I am trying to get the serial number (or any unique hardware based identifier) of a USB flash drive using Python on Linux. I started with the recipe I found in this SO question.
The code in that link work great for fixed hard drives. For example on my internal laptop SSD it returns:
$ sudo python clusterTool.py /dev/sda Hard Disk Model: SAMSUNG SSD PM810 2.5" 7mm 256GB Serial Number: S0NUNYAB503012
Rocking!
However when I run it on a flash-stick I get a error from ioctl that is getting ungracefully coherced 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
File suggests they are the same sort of beast:
$ file /dev/sd{a,b}
/dev/sda: block special
/dev/sdb: block special
I am not sure how they differ, but they clearly diverge somewhere. What is the difference between these devices, and is there any way I uniformly get their identifiers?