Linux – hdparm serial number is garbage

hdparmlinuxserial

I'm trying to read the model and serial number from a drive using "hdparm -I /dev/sda" and I find on some systems (eg: VMware virtual machines) the serial number and model often return garbage (see below). And the garbage seems to change over time when I repeat the command. Is there a way to tell hdparm to not output this garbage? (i.e. show nothing if it can't read the data)

/dev/sda:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ATA device, with non-removable media
�������@�����@�����@:       ����
        Serial Number:      ����@�����@����
        Firmware Revision:  ��O��
Standards:
        Likely used: 2
Configuration:
        CHS addressing not supported
        LBA    user addressable sectors:  116676416
        Logical/Physical Sector size:           512 bytes
        device size with M = 1024*1024:       56970 MBytes
        device size with M = 1000*1000:       59738 MBytes (59 GB)
        cache/buffer size  = unknown

Best Answer

hdparm -I /dev/sdX

This command performs an "identify device", which is a specific ATA protocol that requests the identifying information from the device's firmware. In the case of a physical drive, you could, for instance, connect a bus analyzer between the host bus adapter of your computer and the drive itself and see the identify request traverse the SATA interface and the responding data from the drive.

In the case of a virtual machine, libata is talking to hard drive firmware (through a virtual HBA) that is being emulated as a virtual device. The identify device information that is returned from hdparm depends on how the virtual device has implemented the response to that ATA command. The hdparm command doesn't know that it's talking to a virtual device. It only knows how to execute the command through libata and how to parse the data structure that is returned.

In this context, perhaps it makes more sense to see if there is a way to set the "garbage" fields of your virtual device to whatever values you choose.

If you are using VirtualBox, see this: https://www.virtualbox.org/manual/ch09.html#changevpd

Alternatively, if you just want to remove binary characters from the output, you can pipe it through tr:

sudo hdparm -I /dev/sda | tr -cd '\11\12\15\40-\176'

Related Topic