lshdd

I typically buy a couple new drives for my file server once or twice a year, and as such I have a quite heterogeneous collection of drives in it. Keeping track of what drives are where can be a bit of a detective game.

In order to plan out purchases, replacements, and RAID shuffling work, I want to know what I have, how it’s wired up, how big it is, etc. I’d love to be able to visualize them somehow:

For now though, a command line tool will have to suffice! Specific info I’d like to know includes the existing drive manufacturer and model, serial number, size, usage, what array it’s part of, and where it’s mounted. All this information is available either through sysfs or various system tools, but not summarized in one place.

lshdd is a wrapper script that collects the data from the system and presents it in a tidy table, like this:

Bus            Target  Device    Array  Model                     ID                 SN#                    Size Used MB/sec
0000:00:01.0  4:0:0:0  /dev/sde  md0    WDC WD20EARX-00PASB0      50014ee104aaa42c   WD-WMAZA9300056     2000 GB 70%  115.0
0000:00:01.0  7:0:0:0  /dev/sdf         Hitachi HDS721010CLA332   5000cca373d19a27   JP2940HD17RD3C      1000 GB      132.8
0000:00:1c.0  9:0:0:0  /dev/sdg  md0    ST2000DL003-9VT166        5000c50036aa7060   5YD36Y9G            2000 GB 70%  136.3
0000:00:1c.0 11:0:0:0  /dev/sdh         ST31000340AS              5000c50002675551   3QJ02E22            1000 GB      104.3
0000:00:1f.2  0:0:0:0  /dev/sda         INTEL SSDSC2CT240A4       5001517387e9cffb   CVKI246300R6240DGN   240 GB 5%   387.4
0000:00:1f.2  1:0:0:0  /dev/sdb         INTEL SSDSA2M160G2GC      50015179591fa938   CVPO00930308160AGN   160 GB      236.3
0000:00:1f.5  2:0:0:0  /dev/sdc  md1    WDC WD4000FYYZ-01UL1B0    50014ee2b24798b3   WD-WCC130149937     4000 GB 88%  156.9
0000:00:1f.5  3:0:0:0  /dev/sdd  md1    WDC WD4000FYYZ-01UL1B0    50014ee2078d8c6a   WD-WCC130130855     4000 GB 88%  171.1
0000:00:1f.2  0:0:1:0  /dev/sr0         OPTIARC DVD-ROM DDU1681S                                                      0.0
0000:00:1f.2  1:0:1:0  /dev/sr1         OPTIARC DVD-ROM DDU1681S                                                      0.0

The rightmost columns unfortunately require use of tools that must be run as root, so they’re not displayed if not root. To get the read speeds, lshdd runs a benchmark against each drive, which means that when you run as root the output is slow. However, I find these measurements quite handy at helping me select which drives to replace so I’ve opted to include them for now. Perhaps in a future iteration I’ll make a command line option control whether they’re captured.

The one piece of data I don’t yet have is where the drive is physically located. But at least with the model and serial number I can just shut down the machine and look in each slot for the drive.

lshdd can be had at my github account: https://github.com/bryceharrington/lshdd

6 Responses to lshdd

  1. Next time you shut the machine down, put a label on the edge of each disk showing the serial number. That way you’ll know which disk is which before shutting down. I have had issues with disks and just yanked them out hot without rebooting, because I know exactly which disk went phut.

    Also, if you don’t have a label maker, get one. Then like me you can go round labelling *everything*. I label power cables, plugs, laptop PSUs, drawers… everything :)

    • bryce says:

      Label makers are awesome. I found the el cheapo Brother labelmaker was fine for flat surfaces but crap for wires, so upgraded to a Brady just recently.

      Unfortunately due to ventilation holes I don’t have very good spots for putting a long SN label, plus usually whenever I actually care to know the serial numbers it’s because I’m about to swap stuff around. :-)

      I’m thinking that if I can map out what bus ids go to what physical slot, that’ll be a longer term solution.

  2. I had a similar wish, and have developed a similar compromise solution (text instead of graphics): https://github.com/ProgrammersOfVilnius/pov-admin-tools#disk-inventory

    It’s interesting to see how our mental models differ, e.g. RAID of partitions vs whole devices.

    • bryce says:

      I’d done that in the past. Split up a drive into several partitions and then RAID them to other drives. I found it kind of a hassle to manage, so nowadays just make one big partition on each drive, and only RAID drives of equal sizes.

      As an aside, when I got the 4G drives, I learned that fdisk couldn’t handle those sizes, so have been using parted for doing the partitioning now.

  3. German Pulido says:

    Hi!

    I checked your script, and it’s very useful, but two suggestions:

    1. The default interpreter shouldn’t be python3. I tested with standard python on RHEL 6.4 (python 2.6.6) and your script seems to work fine. 2. Your script does not list USB disks. Is this intentional? or maybe a bug in the 2.6.6 python I used?

    Thanks!

    • bryce says:

      You’re right, ordinary python should be fine.

      As to USB disks, I’m not sure why they’re not being detected (I noticed that myself!) but it’s certainly not intentional. Someday I’ll figure it out (although patches would be welcomed!)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>