Is there a way to distinguish between USB sticks (flash memory) and USB hard drives via libudev / sysfs in Linux? If not, is there a way to query the hardware directly? Thank you.
Asked
Active
Viewed 1,138 times
3
-
USB flash devices generally don't respond appropriately to `hdparm -I`, so if you get an `SG_IO` error it typically means that it's a pendrive and not a spinning platter (I'm shy an SSD to test that theory on ATM) – Anya Shenanigans Feb 14 '13 at 13:02
-
Have just tried with a SSD plugged in a SATA<->USB device - `hdparam -I` gave almost the same info as when querying a USB flash :( – Zaur Nasibov Feb 14 '13 at 13:25
-
I checked with a few sticks, drives and an SSD and got http://db.tt/F4BQZcDr I also used sg_inq on the devices and got https://www.dropbox.com/s/cwbih24iqjvkfcb/sg_inq.txt - I don't think I got the same response as you from hdparm, though. – Anya Shenanigans Feb 14 '13 at 15:46
-
@Petesh, I get `SG_IO: bad/missing sense data, sb[]...` for both SSD and flash sticks. As I understand, you have the same output in `hdaparam -I`. Neither `sg_inq` output (http://pastebin.com/0H8LCqmG) shows any particular difference. – Zaur Nasibov Feb 14 '13 at 16:00
1 Answers
1
Perhaps you could check the device subclass with a udev rule like this: ATTRS{bDeviceSubClass}=="xx"
. I don't know if you can accurately distinguish sticks from real drives using just the subclass though.

kouk
- 1,453
- 12
- 12
-
Unfortunately that one doesn't work well :( E.g. try plugging in a usb stick and `lsusb --verbose` - gives `bInterfaceSubClass 6 SCSI` for a Kingston Datatraveller 8GB stick. – Zaur Nasibov Feb 13 '13 at 14:58
-
-
As far as I know, you cannot distinguish a stick from a USB hard drive using the subclass. – fpmurphy Feb 13 '13 at 14:59
-
does this answer help? http://unix.stackexchange.com/questions/10755/how-to-determine-if-disk-is-compact-flash-or-standard-hard-drive – kouk Feb 13 '13 at 15:34