Identify what USB port is a device plugged into

unfa

I'm working on custom Bash scripts for mass duplication of USB flash memory and mass testing (using f3).

I wonder if it's possible to identify what USB port is a pendrive plugged into.

I have USB hubs with numbered ports. If the have some static addresses that I could identify and know if something is plugged into them or not, and what is that (essentially: which /dev/sd* file corresponds to that USB port) I could make it much easier for the users to know what is going on and allow them to remove bad drives early in the process, without waiting till the whole batch is processed and then try to sort out the bad drives from the good ones (this is how I do it now).

I tried searching around but nothing I found seemed to mesh together with what I want to achieve so I decided to ask directly for help in this context.

Rigth now I identify drives by /dev/sd* node names, and the users have no idea what is that. If I could map these to USB ports in a hub, I could present the information based on the USB ports and users could know that port 5 has a bad drive plugged in and they can remove that without interfering with the rest of the process taking place.

I could then even stop doing this in batches and make all ports work simultaneously in loop, the user could plug the drives in and out all the time, keeping track on what is what by the HUB port numbers, it could greatly seed up the workflow.

So the basic question: how can I identify USB ports and USB flash memory plugged into these ports?

dirkt

You can use udevadm to get the device path of some device. This is done by examining the symlinks in /sys/, so you could also do this manually (but it's easier to use udevadm).

For example, an USB stick plugged into an external USB hub on my system produces

$ udevadm info -q path -n /dev/sdh
/devices/pci0000:00/0000:00:1d.0/usb3/3-1/3-1.1/3-1.1.3/3-1.1.3.2/3-1.1.3.2:1.0/host7/target7:0:0/7:0:0:0/block/sdh

As one can see by comparing with the USB tree,

$ lsusb -t
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
        |__ Port 1: Dev 26, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 3: Dev 29, If 0, Class=Hub, Driver=hub/4p, 480M
                |__ Port 2: Dev 31, If 0, Class=Mass Storage, Driver=usb-storage, 480M
                |__ Port 4: Dev 30, If 0, Class=Mass Storage, Driver=usb-storage, 480M
...

the part 3-1.1.3.2 of the path says that on bus 3, it goes through port 1 (on southbridge), again port 1 (on motherboard), port 3 (still on motherboard), and then on port 2 of the external USB hub. Port 4 of this hub is used for an SD card reader.

So depending on how your USB hub is connected, you need to do something similar, and extract the last port you are interested in.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get udev to identify a USB device regardless of the USB port it is plugged in?

From Dev

Will a USB 2.0 device charge faster plugged into a USB 3.0 port?

From Dev

Ubuntu/Debian How to identify USB port of device

From Dev

How to know when Android device is plugged into USB port?

From Dev

How can I remotely determine if a USB3.0 device is plugged into a USB3.0 port?

From Dev

How can I be sure that I've plugged a device into a USB 3 port?

From Dev

Windows 10 usb 3.1 port stops working when device is plugged in another

From Dev

Identify an Unusual USB Port

From Dev

How computer identify if it is a usb or serial AND what port number to use

From Dev

Linux Debian - Recognize USB a specific port is plugged in?

From Dev

Detect if a USB device is plugged in Javascript from browser

From Dev

How to be notified when a USB device was plugged in?

From Dev

What means Port number usb-device command?

From Dev

How can I uniquely identify which device is on USB `hub 6-0:1.0: port 2`?

From Dev

Distinguish multiple USB sound cards by USB port they're plugged in

From Dev

How to find out to which COM port the device is plugged in?

From Dev

Will a mobile phone charge faster if plugged into a USB 3.0 port

From Dev

Android Maps gives blank (black screen) with device plugged in via usb

From Java

Prevent usbhid from autoloading when USB HID device is plugged in

From Dev

Computer won't shut down properly with USB device plugged in

From Dev

Which code is running when device is off and USB is plugged in?

From Dev

How to auto-sync with a plugged-in USB mass storage device?

From Dev

How to load a module (not a driver) when a USB device is plugged in

From Dev

Autorun a script after I plugged or unplugged a USB device

From Dev

Wi-fi turns off when USB device is plugged in

From Dev

Change tkinter menu when a USB device is plugged in or taken out

From Linux

Associate physical usb port to device

From Dev

USB device (keyboard or mouse) shows in `lsusb` but does not work if it is the second USB device to be plugged in

From Dev

How to identify USB 3 port on my laptop

Related Related

  1. 1

    How to get udev to identify a USB device regardless of the USB port it is plugged in?

  2. 2

    Will a USB 2.0 device charge faster plugged into a USB 3.0 port?

  3. 3

    Ubuntu/Debian How to identify USB port of device

  4. 4

    How to know when Android device is plugged into USB port?

  5. 5

    How can I remotely determine if a USB3.0 device is plugged into a USB3.0 port?

  6. 6

    How can I be sure that I've plugged a device into a USB 3 port?

  7. 7

    Windows 10 usb 3.1 port stops working when device is plugged in another

  8. 8

    Identify an Unusual USB Port

  9. 9

    How computer identify if it is a usb or serial AND what port number to use

  10. 10

    Linux Debian - Recognize USB a specific port is plugged in?

  11. 11

    Detect if a USB device is plugged in Javascript from browser

  12. 12

    How to be notified when a USB device was plugged in?

  13. 13

    What means Port number usb-device command?

  14. 14

    How can I uniquely identify which device is on USB `hub 6-0:1.0: port 2`?

  15. 15

    Distinguish multiple USB sound cards by USB port they're plugged in

  16. 16

    How to find out to which COM port the device is plugged in?

  17. 17

    Will a mobile phone charge faster if plugged into a USB 3.0 port

  18. 18

    Android Maps gives blank (black screen) with device plugged in via usb

  19. 19

    Prevent usbhid from autoloading when USB HID device is plugged in

  20. 20

    Computer won't shut down properly with USB device plugged in

  21. 21

    Which code is running when device is off and USB is plugged in?

  22. 22

    How to auto-sync with a plugged-in USB mass storage device?

  23. 23

    How to load a module (not a driver) when a USB device is plugged in

  24. 24

    Autorun a script after I plugged or unplugged a USB device

  25. 25

    Wi-fi turns off when USB device is plugged in

  26. 26

    Change tkinter menu when a USB device is plugged in or taken out

  27. 27

    Associate physical usb port to device

  28. 28

    USB device (keyboard or mouse) shows in `lsusb` but does not work if it is the second USB device to be plugged in

  29. 29

    How to identify USB 3 port on my laptop

HotTag

Archive