9

Every now and then there might come a need to reset a USB device, is there a way to perform the reset in software without unplugging the device itself and then pluggin it back in?

More specifically I have a webcam which gets confused when playing too much with the settings in guvcapture and then needs a reset to get back on track.

4 Answers 4

9

You could try Benjamin Close's resetusb program to reset all devices — there are no binaries available, but compiling it is rather easy. Save the source code as resetusb.c, then run:

gcc -lusb resetusb.c -o resetusb

You can now run the tool as resetusb. Alternatively, @unhammer points to Alan Stern's single-device version (plus some hints on how to use it).

Some people have also had luck just removing and modprobe-ing the relevant modules:

modprobe -vr ehci_hcd
modprobe -v ehci_hcd

(you could of course script this)

Some distributions may also have their own tools to restart the USB subsystem; Mandrake apparently has /etc/init.d/usb.

4
  • askubuntu.com/questions/645/… has a similar program for resetting a single usb device
    – unhammer
    Dec 31, 2013 at 14:34
  • $ sudo modprobe -vr ehci_hcd results in modprobe: FATAL: Module ehci_hcd is builtin. on kubuntu trusty.
    – naught101
    Jun 28, 2014 at 3:42
  • On my laptop with debian 8, ehci_hcd gives errors. However, rmmod ehci_pci && sleep 2 && modprobe ehci_pci works perfectly.
    – Bharat G
    Oct 12, 2015 at 14:16
  • The modprobe trick did the job on CentOS 4 :-( , saved my day !
    – Open SEO
    Jun 9, 2016 at 13:09
9

Let's say I want to reset /dev/sdc.

# udevadm info -q all /dev/sdc | grep DEVPATH
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.4/2-1.4:1.0/host2/target2:0:0/2:0:0:0/block/sdc

I take the 2-1.4 above (yours might just be 2-1 - my device is plugged into a hub) and do:

# echo 2-1.4 > /sys/bus/usb/drivers/usb/unbind
# echo 2-1.4 > /sys/bus/usb/drivers/usb/bind
1
  • 1
    I've made a one-liner(-ish) for that: DEV="sdc"; USB=$(udevadm info -q all /dev/$DEV | grep DEVPATH | grep -o '/usb[1-9]*/[1-9,-]*' | cut -d'/' -f3); echo $USB > /sys/bus/usb/drivers/usb/unbind; echo $USB > /sys/bus/usb/drivers/usb/bind Make DEV the drive you want to reset, and run - it'll extract the USB port number and unbind/bind it (untested).
    – unfa
    Sep 11, 2019 at 10:56
2

usbutils includes usbreset.

Run it without any arguments to see usage and a list of devices. It requires superuser access to actually reset devices.

Usage:
usbreset PPPP:VVVV - reset by product and vendor id
usbreset BBB/DDD   - reset by bus and device number
usbreset "Product" - reset by product name

This allows resetting individual devices which is an improvement over some answers that reset the entire bus. It might not resolve intermediary hub/bus issues, but it's a lot less disruptive to only reset the desired device.

1

You can restart the hardware abstraction layer: sudo /etc/init.d/hal restart

2
  • 2
    i think HAL is replaced by something else in the newest version of ubuntu.. so its depend of distrib..
    – bAN
    Aug 17, 2010 at 20:29
  • 1
    I seriously doubt it would have worked anyway. HAL wasn't a low-level abstraction layer like the Windows component of the same name.
    – sourcejedi
    Dec 10, 2012 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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