Playing with USB devices,remove them without physical access

In below text I will show how to disable / enable USB device from command line without plugging it out.

Information about USB on Linux system are listed under

/sys/bus/usb/devices

You will find there devices which are present on system.On my laptop I have something like ( depending on your hardware,content of /sys/bus/usb/devices can be different )

lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb1 -> ../../../devices/pci0000:00/0000:00:1a.7/usb1
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb3 -> ../../../devices/pci0000:00/0000:00:1a.0/usb3
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb4 -> ../../../devices/pci0000:00/0000:00:1a.1/usb4
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb5 -> ../../../devices/pci0000:00/0000:00:1a.2/usb5
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb6 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb7 -> ../../../devices/pci0000:00/0000:00:1d.1/usb7
lrwxrwxrwx. 1 root root 0 Jun 11 13:33 usb8 -> ../../../devices/pci0000:00/0000:00:1d.2/usb8

When USB device is connected,in logs we can see something like ( an example ):

Jun 11 17:31:43 e-makina kernel: [14304.023129] usb 1-1: new high speed USB device using ehci_hcd and address 95
Jun 11 17:31:44 e-makina kernel: [14304.760077] usb 1-1: New USB device found, idVendor=090c, idProduct=1000
Jun 11 17:31:44 e-makina kernel: [14304.760090] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3


so this means USB device is under

# /sys/bus/usb/devices/usb1/1-1

In /sys/bus/usb/devices/usb1/1-1 there are many files and there you can find device serial number (serial) ,vendor (vendor), etc. The one of interest for us in sense of removing USB device without physically removing it is file bConfigurationValue.If device is connected it will contain ‘1‘,if device is not connected it will contain ‘0
I recommend here to read “libusb Developers Guide” which can be found here

So to remove device run
# echo 0 > bConfigurationValue
and below to “connect” it
# echo 1 > bConfigurationValue

This can be useful in situations where you need to disconnect device for some reason but do not have physical access to machine.

Good reading
1) # yum instlall -y kernel-doc;cd /usr/share/doc/kernel-doc/Documentation/usb and documentation shipped with kernel-doc package
2) usb.org

Advertisements

#usb-devices