I would like to bind/unbind my usb device - a wireless adapter.

echo -n "1-1:1.0" > /sys/bus/usb/drivers/ub/unbind

So to able to do that, I need the bus ID. lsusb prints out the following:

Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter

And 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/3p, 480M
        |__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
        |__ Port 2: Dev 4, If 0, Class=vend., Driver=rt73usb, 480

So where can I find this bus ID? Thanks!
Update: here is the detailed info about the wireless devide: (lsusb -v | grep -E '\<(Bus|iProduct|bDeviceClass|bDeviceProtocol)' 2>/dev/null)

Bus 001 Device 004: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter
  bDeviceClass            0 (Defined at Interface level)
  bDeviceProtocol         0 
  iProduct                2
  • maybe this will help you: lsusb -v | grep -E '\<(Bus|iProduct|bDeviceClass|bDeviceProtocol)' 2>/dev/null – LilloX Nov 12 '15 at 11:27
  • @LilloX updated the question, can you please help to find that id? – laplasz Nov 12 '15 at 11:34
  • 1
    In you situation: Bus=1, Port=2 so: echo -n "1-2" > /sys/bus/usb/drivers/usb/unbind You don't need the device number – LilloX Nov 12 '15 at 12:58

You can read off the sequence from the device tree you get with lsusb -t. The number before the hyphen is the bus, the numbers after the hyphen are the port sequence. Your device is on bus 01, on port 1 of the root hub for this bus is another hub, and on port 3 of this hub is your device: So you get 1-1.3.

If you know the vendor id from lsusb (like 148f for Ralink), you can also grep for it with

grep 148f /sys/bus/usb/devices/*/idVendor

and you'll get something like

/sys/bus/usb/devices/1-1.3/idVendor:148f

as answer. If there are several devices from the same vendor, you can narrow it down with idProduct.

finally I found the right bus ID of the usb device. There is a file listing all the IDs - /sys/bus/usb/devices/ and the content is the following:

root@raspberrypi:/home/pi# ls /sys/bus/usb/devices
1-0:1.0  1-1  1-1.1  1-1:1.0  1-1.1:1.0  1-1.3  1-1.3:1.0  usb1

and the corresponding lsusb:

root@raspberrypi:/home/pi# 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/3p, 480M
        |__ Port 1: Dev 3, If 0, Class=vend., Driver=smsc95xx, 480M
        |__ Port 3: Dev 17, If 0, Class=vend., Driver=rt73usb, 480M

root@raspberrypi:/home/pi# lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 017: ID 148f:2573 Ralink Technology, Corp. RT2501/RT2573 Wireless Adapter

so I tried 1-1.3 as an ID and it worked. But 1-3 did not.

root@raspberrypi:/home/pi# echo -n "1-3" > /sys/bus/usb/drivers/usb/unbind
bash: echo: write error: No such device

Here is an example where I was trying to do the same thing on Ubuntu 16.04 for USB-Ethernet device:

anurag@anurag-ThinkPad-E470:~$ lsusb
Bus 002 Device 003: ID 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet
Bus 002 Device 002: ID 0424:5744 Standard Microsystems Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 007: ID 138a:0011 Validity Sensors, Inc. VFS5011 Fingerprint Reader

We want to unbind the first device. You can see the driver instance created in sysfs and within the driver, an instance of the USB bus address of the Ethernet Dongle:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers$ ls
ax88179_178a  btusb  hub  r8188eu  usb  usbfs  usbhid  uvcvideo
anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.2:1.0  bind  module  new_id  remove_id  uevent  unbind

If you plug in another dongle of same type, you can now see two devices:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.1:1.0  2-2.2:1.0  bind  module  new_id  remove_id  uevent  unbind

At this point you can see two net devices:

anurag@anurag-ThinkPad-E470:~$ ip link show
....
6: enx000ec6cd8d75: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:75 brd ff:ff:ff:ff:ff:ff
7: enx000ec6cd8d90: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:90 brd ff:ff:ff:ff:ff:ff

You can unbind like so:

anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ sudo sh -c "echo 2-2.2:1.0 > unbind"
[sudo] password for anurag:
anurag@anurag-ThinkPad-E470:/sys/bus/usb/drivers/ax88179_178a$ ls
2-2.1:1.0  bind  module  new_id  remove_id  uevent  unbind

And the device will no longer show up in the interface list:

anurag@anurag-ThinkPad-E470:~$ ip link show
....
6: enx000ec6cd8d75: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0e:c6:cd:8d:75 brd ff:ff:ff:ff:ff:ff

Note that just issuing sudo echo 2-2.2:1.0 > unbind doesn’t work because that only elevates permission for the echo command and not for the redirection. Hence we use temporarily elevated shell. The unbind is writable only by root user.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.