I am trying to get the serial number (or any unique hardware identifier) ββof a USB drive using Python on Linux. I started with the recipe I found in this SO question .
The code in this link is great for hard drives. For example, on my internal SSD, it returns:
$ sudo python clusterTool.py / dev / sda
Hard Disk Model: SAMSUNG SSD PM810 2.5 "7mm 256GB
Serial Number: S0NUNYAB503012
rocking chair!
However, when I run it on a flash card, I get an error message from ioctl that fails without binding to the following python trace:
$ sudo python clusterTool.py / dev / sdb
Traceback (most recent call last):
File "clusterTool.py", line 21, in
buf = fcntl.ioctl (fd, HDIO_GET_IDENTITY, "" * sizeof_hd_driveid)
IOError: [Errno 22] Invalid argument
The file assumes that they are similar to each other:
$ file / dev / sd {a, b}
/ dev / sda: block special
/ dev / sdb: block special
I'm not sure how they differ, but they clearly diverge. What is the difference between these devices, and is there any way to get their identifiers evenly?
source share