LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   How do I find the /dev/sd device currently assigned to a physical flash drive port? (http://www.linuxquestions.org/questions/linux-hardware-18/how-do-i-find-the-dev-sd-device-currently-assigned-to-a-physical-flash-drive-port-892172/)

secondjohn 07-17-2011 09:58 AM

How do I find the /dev/sd device currently assigned to a physical flash drive port?
 
I have (at least 4) native USB ports that contain flash drives. I know that the /dev/sd[abcd] devices are created in the order they were inserted, but say you have all four plugged in at boot time, or further, they can be plugged and unplugged in real time. At times, /dev/sdf, /dev/sdg, etc. are created as well. I'm ignoring external hubs for now.

I need to know which drive is plugged into the "top port on the front panel", etc, by physical location. From dmesg I can check right after booting and get the physical assignment of a PCI device, say, PCI 0000:00:10.3, as being assigned to the EHCI usb bus. From /proc/bus/usb/devices, and the "T:" field, I have learned that the physical connectors I'm interested are known as USB Bus 1, Port=00, Port=01, Port=04, and Port=05.

From lsusb I can see all sorts of information from the USB point of view, but with no /dev/sd references.

From /proc/scsi/scsi, I can see what scsi devices have been created, with a count consistent with the number of flash drives plugged in, but no USB data.

So, I can get lots of information from the USB storage point of view, and lots of information from the SCSI point of view, but nowhere can I find how to correlate them. In other words, if I want to mount the drive plugged into a given physical slot, how can I find the /dev/sd device I need to mount? udev isn't really interesting here, because I'm just looking for the information that udev would use to answer the same question.

I've done some heaving exploring in the /sys and /proc filesystems and have not yet found where the USB and SCSI worlds intersect.

The closest I have found is (where "Port" is the physical port number from above):

P=$(expr $Port + 1)
ls -d /sys/devices/pci0000:00/0000:00:10.3/usb1/1-${P}/*/\
host*/target*/*/block/*

(whew)

This seems to have some mapping to the physical port and references a "/dev/sd[a-z]" value, but I don't know how reliable it might be, nor do I know if my having to increment that physical port by 1 is meaningful. Anyone have a simpler approach?

So, my goal becomes
mount /dev/<sd that was created for the top slot> /mnt/top
mount /dev/<sd that was created for the bottom slot> /mnt/bottom etc.

Anyone been here?

Thanks,

secondjohn

jefro 07-18-2011 03:49 PM

Mount with no options just mount command is the command to view that I'd think.

Use uuid instead maybe.

secondjohn 07-18-2011 09:33 PM

mount will tell me what devices are mounted, but not where physically each is mounted. (i.e., which one is mounted in the left side of the computer and which is in the right).

Thanks, though.

ajaymahagaokar 01-17-2012 11:33 AM

Not sure if it is still relevant ...
 
Check out the following example:

admin@ER1108006398:~$ cat /proc/partitions
major minor #blocks name

8 0 488386584 sda
8 1 19530226 sda1
8 2 9765625 sda2
8 3 459089692 sda3
8 16 2007040 sdb
8 17 2001053 sdb1
8 32 15605504 sdc
8 33 15605244 sdc1
8 48 1423360 sdd
8 49 1423352 sdd1
admin@ER1108006398:~$ ls /proc/scsi/usb-storage/
16 17 2
admin@ER1108006398:~$ cat /proc/scsi/usb-storage/16
Host scsi16: usb-storage
Vendor: Apple Inc.
Product: iPod
Serial Number: 000A27002033BCE9
Protocol: Transparent SCSI
Transport: Bulk
Quirks:
admin@ER1108006398:~$ cat /proc/scsi/usb-storage/17
Host scsi17: usb-storage
Vendor: Amazon
Product: Amazon Kindle
Serial Number: B00E150114323KLX
Protocol: Transparent SCSI
Transport: Bulk
Quirks:
admin@ER1108006398:~$ cat /proc/scsi/usb-storage/2
Host scsi2: usb-storage
Vendor: Transcend
Product: TS2GUFM-H
Serial Number: TS20100712000008
Protocol: Transparent SCSI
Transport: Bulk
Quirks:
admin@ER1108006398:~$

Hammett 01-18-2012 09:35 AM

I think this could give some light to your problem:

http://ubuntuforums.org/showthread.php?t=168221

It basically tells you to assign every USB with their own SN to a specific /dev/sd device. Later you can define mount point in /etc/fstab


All times are GMT -5. The time now is 11:45 PM.