Linux – usb device -> block device mapping on Ubuntu

devicelinuxUbuntuusb

Apologies if this is a duplicate, however.

I have 2 usb mass storage devices, and I need to be able to work out which physical device maps to a block device.

They are not both always present, so I can't just rely on a fixed block device path.

I've tried to determine the device path from lsusb, but that just provides the device info.

Bus 001 Device 016: ID 0781:5406 SanDisk Corp. Cruzer Micro 1/2/4GB Flash Drive
Bus 001 Device 015: ID 4971:ce23 SimpleTech

sudo fdisk -l is not able to read any partition as its a truecrypt encrypted volume.

Is there some way to detect which physical device is mapped to a block device ?

I'm not able to mount the filesystem until I know which is which.

have I approached this problem in the wrong way ?

Any suggestions ?

Best Answer

Are the physical devices both the same size? Are they the exact same brand as well?

If they are different sizes, fdisk -l should show you the size of the entire disk in the header along with the block device name, which should help you.

You can also check the output of dmesg. When a USB device is connected, dmesg will display the process it undergoes to bring it online, as well as showing you the block device it assigned. Here's a sample output:

Aug 14 16:35:02 xen kernel: [2526561.710931] usb 5-5: new high speed USB device using ehci_hcd and address 4
Aug 14 16:35:02 xen kernel: [2526561.859909] usb 5-5: configuration #1 chosen from 1 choice
Aug 14 16:35:02 xen kernel: [2526562.138808] usbcore: registered new interface driver libusual
Aug 14 16:35:02 xen kernel: [2526562.162072] Initializing USB Mass Storage driver...
Aug 14 16:35:02 xen kernel: [2526562.163248] scsi4 : SCSI emulation for USB Mass Storage devices
Aug 14 16:35:02 xen kernel: [2526562.163452] usbcore: registered new interface driver usb-storage
Aug 14 16:35:02 xen kernel: [2526562.163455] USB Mass Storage support registered.
Aug 14 16:35:07 xen kernel: [2526567.161157] scsi 4:0:0:0: Direct-Access     WDC WD50 00AAKS-00A7B0         PQ: 0 ANSI: 2 CCS
Aug 14 16:35:07 xen kernel: [2526567.171712] sd 4:0:0:0: [sdb] 976773168 512-byte hardware sectors (500108 MB)
Aug 14 16:35:07 xen kernel: [2526567.172736] sd 4:0:0:0: [sdb] Write Protect is off
Aug 14 16:35:07 xen kernel: [2526567.173733] sd 4:0:0:0: [sdb] 976773168 512-byte hardware sectors (500108 MB)
Aug 14 16:35:07 xen kernel: [2526567.174606] sd 4:0:0:0: [sdb] Write Protect is off
Aug 14 16:35:13 xen kernel: [2526567.174616]  sdb: sdb1
Aug 14 16:35:13 xen kernel: [2526572.854493] sd 4:0:0:0: [sdb] Attached SCSI disk
Aug 14 16:35:13 xen kernel: [2526572.854544] sd 4:0:0:0: Attached scsi generic sg2 type 0

As you can see, the kernel assigned /dev/sdb to the USB device. Hope this helps!

Related Topic