2

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
TSG
  • 1,634
  • 6
  • 29
  • 51
  • Virtual machines generally have virtual devices. Using a tool intended for physical devices is likely to get invalid results. – BillThor Jan 25 '15 at 09:50
  • 1
    I'm not sure I agree with your reasoning. Virtualization software virtualizes all aspects of the hardware - even the vdisk emulates cylinders, heads, sectors, etc. So asking for a serial number isn't unreasonable. – TSG Jan 25 '15 at 13:46
  • The emulation of cylinders, heads, sectors, etc. is essential to being able to use the device as modeled by software. The serial number and many of the other items reported by hdparm are related to the physical implementation of the device. (Serial number is not even required at that level.) Many are related to the hardware controller software not the device itself. – BillThor Jan 25 '15 at 22:40
  • For VMWare VMs try applying these steps to set disk.EnableUUID=TRUE for each VM on which you need to have a real Serial Number: https://sort.symantec.com/public/documents/sfha/6.1/vmwareesx/productguides/html/sfhas_virtualization/ch09s05s01.htm – Vlad Stoianovici Dec 11 '18 at 10:30

1 Answers1

2

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'

Lee Miller
  • 36
  • 2
  • In this case the virtual drive is created by VMWare. I can't find anything about setting a serial number of a vdisk in vmware, and it appears it's not edittable (http://serverfault.com/questions/304565/edit-hard-disk-serial-number-with-vmware). Still, shouldn't the command return an empty string (length 0) instead of random chars? – TSG Feb 12 '15 at 02:25