Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to reset the connection of a USB device, without physically disconnecting/connecting from the PC?

Specifically, my device is a digital camera. I'm using gphoto2, but lately I get "device read errors", so I'd like to try to do a software-reset of the connection.

From what I can tell, there are no kernel modules being loaded for the camera. The only one that looks related is usbhid.

share|improve this question
Which version of Ubuntu are you using? – User Aug 1 '10 at 20:15

5 Answers

up vote 12 down vote accepted

Try this http://marc.info/?l=linux-usb&m=121459435621262&w=2

$ cc usbreset.c -o usbreset
$ lsusb
Bus 002 Device 003: ID 0fe9:9010 DVICO

$ chmod +x usbreset
$ sudo ./usbreset /dev/bus/usb/002/003

share|improve this answer
I got errors like this: ./usbreset: command not found Dan 11.04 Natty – user24895 Sep 13 '11 at 4:33
Source unavailable ... :( – Sukminder May 16 at 6:17

I haven't found myself in your specific circumstances before, so I'm not sure if it'll do enough, but the simplest way I've found to reset a USB device is this command: (No external apps necessary)

sudo sh -c "echo 0 > /sys/bus/usb/devices/1-4.6/authorized"

That's the actual one I use to reset my Kinect since libfreenect seems to have no API for putting it back to sleep. It's on my Gentoo box, but the kernel should be new enough to use the same path structure for sysfs.

Yours obviously wouldn't be 1-4.6 but you can either pull that device path from your kernel log (dmesg) or you can use something like lsusb to get the vendor and product IDs and then use a quick command like this to list how the paths relate to different vendor/product ID pairs:

for X in /sys/bus/usb/devices/*; do 
    echo "$X"
    cat "$X/idVendor" 2>/dev/null 
    cat "$X/idProduct" 2>/dev/null
    echo
done
share|improve this answer
sh: 1: cannot create /sys/bus/usb/devices/1-3.1:1.0/authorized: Directory nonexistent – Nicolas Marchildon May 31 '12 at 3:22
It looks like they've changed the layout of the usbfs filesystem. I'll try to figure out what the new way of doing things is on Ubuntu once I'm not so sleepy. – ssokolow Jun 2 '12 at 15:46
Thank you worked great! Maybe you should also mention to perform a echo 1 > /sys/bus/usb/devices/whatever/authorized inside a script to re-enable the device as soon as it has been disabled. I did it on both my mouse and usb keyboard and I ended up with a completely deaf system :) – Avio Apr 28 at 8:43
Last time I used it, something in the system would reset it to 1 a second or two later without me having to do it manually. – ssokolow Apr 29 at 20:33

This will reset all of USB attached ports that belogs to ehci_hcd moudule:

for i in $(ls /sys/bus/pci/drivers/ehci_hcd/|grep :)<br>
 do echo $i >/sys/bus/pci/drivers/ehci_hcd/unbind <br>
echo $i >/sys/bus/pci/drivers/ehci_hcd/bind<br>
done

I believe this will solve your problem. If you do not want to reset all of the USB endpoints, you can use appropriate device ID from /sys/bus/pci/drivers/ehci_hcd

share|improve this answer

Perhaps this works for a camera, too:

Following revived a starved USB 3.0 HDD on a 3.4.42 (kernel.org) Linux on my side. dmesg told, that it was timing out commands after 360s (sorry, I cannot copy the syslog here, not connected networks) and the drive hung completely. Processes accessing the device were blocked in the kernel, unkillable. NFS hung, ZFS hung, dd hung.

After doing this, everything worked again. dmesg told just a single line about the USB device found.

I really have no idea what following does in detail. But it worked.

The following example output is from Debian Squeeze with 2.6.32-5-686 kernel, so I think it works for 2.6 and above:

$ ls -al /dev/sdb
brw-rw---T 1 root floppy 8, 16 Jun  3 20:24 /dev/sdb

$ ls -al /sys/dev/block/8:16/device/rescan
--w------- 1 root root 4096 Jun  6 01:46 /sys/dev/block/8:16/device/rescan

$ echo 1 > /sys/dev/block/8:16/device/rescan

If this does not work, perhaps somebody else can figure out how to send a real reset to a device.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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