簡體   English   中英

Ubuntu / Debian如何識別設備的USB端口

[英]Ubuntu/Debian How to identify USB port of device

如何識別單個USB設備以解除綁定並綁定它們? 具體而言,鼠標,鍵盤,加密狗等設備不是存儲設備。

例如,在Debian(本例中為Raspbian GNU / Linux v8.0)上,我在/ sys / bus / usb / drivers / usbhid /中列出了一些設備:

ls / sys / bus / usb / drivers / usbhid /顯示USB設備:

1-1.2:1.0  1-1.2:1.1  1-1.2:1.2  1-1.3:1.0  1-1.3:1.1  1-1.4:2.2

lsusb顯示:

Bus 001 Device 006: ID 1410:9020 Novatel Wireless
Bus 001 Device 009: ID 045e:00db Microsoft Corp. Natural Ergonomic Keyboard 4000 V1.0
Bus 001 Device 008: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

lsusb -t顯示:

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 2: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 2: Dev 8, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 2: Dev 8, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 9, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 9, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 4: Dev 6, If 0, Class=Communications, Driver=cdc_ether, 480M
        |__ Port 4: Dev 6, If 1, Class=CDC Data, Driver=cdc_ether, 480M
        |__ Port 4: Dev 6, If 2, Class=Human Interface Device, Driver=usbhid, 480M

我知道Novatel Wireless的猜測是1-1.4:2.2

我可以通過運行echo -n'1-1.4:2.2'> / sys / bus / usb / drivers / usbhid / unbindecho -n'1-1.4:2.2'> / sys / bus / usb / drivers重置它/ USBHID /綁定

如果有一種明顯的方法來識別它並在bash腳本中重置它會很棒。 另外,如果不同端口上有多個相同的硬件,如何識別和重置設備?

這兩條信息都在/dev/sys/class目錄中。

您可以使用ls -l /sys/class/xxx ,其中xxx替換您要查詢的設備類別。

ls -l /sys/class/block

/sys/devices/pci0000:00/0000:00:12.2/usb1/1-3/1-3:1.0/host251/target251:0:0/251:0:0:0/block/sdb/sdb1

問題是你必須知道你正在尋找哪個設備,即有一個名字或公交車號碼。 但是,您可以通過lsusb或用於特定設備類的命令獲取此信息,即ip link (LTE調制解調器通常實現為RNDIS主機,並在ip link顯示為usb0 ), lsblk --output NAME,KNAME,FSTYPE,MOUNTPOINT,RM,UUID ,......

對於任何USB設備, ls - l /sys/class/xxx將輸出USB端口和udev路徑

您的Novatel無線(USB以太網)將在sys/class/ǹet 您還可以使用vendoridproductID識別設備。

如果您需要更多信息,可以使用udevadm

sudo udevadm info --query=all --attribute-walk --path=/devices/pci0000:00/0000:00:12.2/usb1/1-3/1-3:1.0/host251/target251:0:0/251:0:0:0/block/sdb/sdb1

 looking at device '/devices/pci0000:00/0000:00:12.2/usb1/1-3/1-3:1.0/host237/target237:0:0/237:0:0:0/block/sdb/sdb1':
    KERNEL=="sdb1"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{partition}=="1"
    ATTR{start}=="64"
    ATTR{size}=="62517184"
    ATTR{ro}=="0"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="0"
    ATTR{stat}=="     156        7     1304      132        0        0        0        0        0      128      128"
    ATTR{inflight}=="       0        0"

另一種可能性是使用run udevadm monitor然后附加設備。

https://unix.stackexchange.com/questions/116664/map-physical-usb-device-path-to-bus-device-number-returned-by-lsusbhttps://unix.stackexchange.com/questions / 74513 / udev-how-do-you-identify-the-physical-that-a-sys-device-belongs-to

對於鼠標(輸入設備),請嘗試:

sudo udevadm info --query=all --attribute-walk --name=/dev/input/mouse0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM