0

I'm trying to detect the USB version (USB 2.0/USB 3.0) from just the drive label.

I know the USB version can be fetched from "bcdUSB" parameter in the output of "lsusb -v" or the "Operating speed" parameter in the output of "lsusb -t" (480M/5000M).

And I know the drive label can be found from the output of "lsblk", But I can't figure out a way to match those outputs to match USB version with the drive label.

My backup option is to test speed of transfer for a file to detect USB version, but that's not very reliable.

I was hoping for an easy and reliable way. Any guidance is really appreciated.

0

This is a system-specific thing, but presuming Linux (and not, say, BSD, etc.):

If you have the device name (which lsblk gives you), then:

$ udevadm info -a /dev/sdf1
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1a.7/usb1/1-2/1-2:1.0/host16/target16:0:0/16:0:0:0/block/sdf/sdf1':
    KERNEL=="sdf1"
⋮
  looking at parent device '/devices/pci0000:00/0000:00:1a.7/usb1/1-2':
    KERNELS=="1-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
⋮
    ATTRS{speed}=="480"

I suspect 'speed' is what you're looking for. If not, there is also busnum and devnum there, which match the bus:device given by lsusb.

This also gives you a clue of how to do it by hand: you look in /sys. You can find where to start by readlink -f /sys/block/sdf which tells me /sys/devices/pci0000:00/0000:00:1a.7/usb1/1-2/1-2:1.0/host16/target16:0:0/16:0:0:0/block/sdf. You can then strip off trailing directories until you get back up to the USB device. Then speed, busnum, devnum, etc. are just files you can read.

1
  • Thanks a lot, udevadm works, just had to modify it to udevadm info --attribute-walk --name=sda | grep ATTRS{speed} – Rohit Feb 7 '17 at 16:55
1

The label is user set, or can be when the filesystem on the USB drive is formatted or after the fact. Use the lsusb -v ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.