Ubuntu – Why does udevadm not provide me a disk serial number when hdparm can

hard drivehdparmUbuntuudevusb


root@home:~# hdparm -I /dev/sdb | grep Serial
    Serial Number:      WCJ025C8
    Transport:          Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0


root@home:~# udevadm info -a -p $(udevadm info -q path -n /dev/sdb) | grep -i serial

I see this 0123456789ABCDEF a lot with udev, but it's bogus, whereas hdparm's output exactly matches the physical number on the drive.

As a result, I can't create udev rules that'll match my 4 USB drives by serial number.

I'm running ubuntu 16.04 LTE.

Suggestions greatly appreciated.

Best Answer

In the end I went with this, which is a bit of a hack:

KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM="/root/get_disk_serial.sh %k", SYMLINK+="disk/by-serial/%c"

and then a quick script like this:


/sbin/hdparm -I /dev/$1 | grep 'Serial Number' | awk '{print $3}'

It ain't pretty, but it works...

Related Topic