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
|