4

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?

1
  • I have an interim solution that involves scraping the output of this It is hack-hack-ugly and depends on shell scripts etc. Looking for a real answer still. Commented Sep 10, 2013 at 20:36

1 Answer 1

0

This might help http://www.roman10.net/linux-get-udev-device-information-in-pythonpyudev/ using pyudev and python setup tools with syspath.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.