lhsw is terrible for detecting disks

Bug #1402280 reported by Rob Thomas
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
High
Blake Rouse

Bug Description

Various bugs report that lshw isn't reporting disks, or disk sizes correctly. This is because lshw, while venerable, is somewhat out of date with modern hardware.

I suggest avoiding that totally, and replacing 100% of the disk detection code with this one liner:

 parted -lms | awk 'found{ if(!/dev\/mapper/){print};found=0} /^BYT;$/{found=1}'

This will reliably and repeatably output a single line per available disk, with a valid size:

root@t0:~/maas# parted -lms | awk 'found{ if(!/dev\/mapper/){print};found=0} /^BYT;$/{found=1}'
/dev/cciss/c0d0:147GB:cpqarray:512:512:msdos:Compaq Smart Array:;
root@t0:~/maas#

root@bay6:/var/log# parted -lms | awk 'found{ if(!/dev\/mapper/){print};found=0} /^BYT;$/{found=1}'
/dev/cciss/c0d0:147GB:cpqarray:512:512:msdos:Compaq Smart Array;
/dev/cciss/c0d1:147GB:cpqarray:512:512:gpt:Compaq Smart Array;
root@bay6:/var/log#

root@gw:~# parted -lms | awk 'found{ if(!/dev\/mapper/){print};found=0} /^BYT;$/{found=1}'
/dev/sda:42.9GB:scsi:512:512:msdos:VMware Virtual disk;
root@gw:~#

It also explicitly excludes LVM (the /dev/mapper negation) volumes.

This provides output in an easy to parse format, and will never be out of date, unlike lshw.

Related branches

Revision history for this message
Blake Rouse (blake-rouse) wrote :

I have to agree with you that lshw is not the best source. As I am currently trying to detect that disks are SSD, and lshw does not provide that information.

I am looking into replacing lshw with another method of detecting disks, for the new storage work for MAAS. I will take into account your suggestion here.

Thanks,
Blake

Changed in maas:
status: New → Triaged
importance: Undecided → High
Revision history for this message
Rob Thomas (xrobau) wrote :

Well, that's slightly harder to do in an awk one liner.

Still doable, but not readable.

cat /sys/block/cciss\!c0d0/queue/rotational
1

root@t0:~# cat /sys/block/cciss\!c0d0/queue/rotational
1
root@t0:~# echo /dev/sda | sed 's/\//!/g; s/!dev!//'
sda
root@t0:~# echo /dev/cciss/c0d0 | sed 's/\//!/g; s/!dev!//'
cciss!c0d0
root@t0:~#

If it's 1 it's spinning, if it's zero it's not.

Revision history for this message
Rob Thomas (xrobau) wrote :

As that was a bit of an interesting puzzle:

#!/bin/bash

# Basic HDD detection script.
# Written by Rob Thomas, <email address hidden>
# Code available under the licence of your choice.

ALLDISKS=$(parted -lms | awk 'found{ if(!/dev\/mapper/){print};found=0} /^BYT;$/{found=1}')

while read -r l; do
        RAWDISK=`echo "$l" | cut -d: -f1 | sed -r 's/\//!/g; s/!dev!//'`
        SSD="?"
        if [ -e "/sys/block/$RAWDISK/queue/rotational" ]; then
                SSD=`cat /sys/block/$RAWDISK/queue/rotational`
        fi
        echo $l$SSD
done <<< "$ALLDISKS"

That will append ? (if there's an error), 0 or 1 to the end of the string

Christian Reis (kiko)
Changed in maas:
milestone: none → next
tags: added: cloud-installer
Changed in maas:
assignee: nobody → Blake Rouse (blake-rouse)
status: Triaged → Fix Committed
Changed in maas:
status: Fix Committed → Fix Released
Changed in maas:
milestone: next → none
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.