70

It is possible for a USB storage device to become logically disconnected: the device is still plugged in, but is invisible from the operating system (e.g. it's not listed under /proc/bus/usb). Maybe this can happen to other kinds of USB or other removable devices as well. This can happen for example:

  • after Nautilus has unmounted a USB storage device;
  • after VirtualBox has claimed a USB storage device (the device disappears from the Linux host when it is attached in the guest, and does not automatically reappear if it is detached from the guest).

What is going on in the driver or in the hardware, and most importantly, (how) can the device be logically reconnected (without physically plugging it out and back in)?

Note that this question is not about mounting. In the “logically disconnected” state, the kernel believes there is nothing on the USB bus (and so of course there is no entry under /dev).

1

10 Answers 10

21

It is sometimes possible to do a power cycle on branch of the USB bus where the device is plugged :

# echo suspend > /sys/bus/usb/devices/1-1/power/level
# echo auto > /sys/bus/usb/devices/1-1/power/level

The 1-1 should be adjusted to your configuration. You can see to which part of the USB tree your device is plugged by running lsusb -t before ejecting it.

You can find detailed information on the linux-usb mailing-list, this thread for example.

5
  • 7
    "suspend" doesn't work on kernels after 2.6.36.
    – alexisdm
    Commented Jan 31, 2014 at 13:14
  • 1
    Assuming dmesg reports the correct device ID ("usb 9-4: USB disconnect [...]"), this does not work on latest Arch Linux. There is no path /sys/bus/usb/devices/9-4 afterwards.
    – l0b0
    Commented Mar 21, 2014 at 7:07
  • 1
    1. dmesg: WARNING! power/level is deprecated; use power/control instead 2. superuser.com/questions/371068/…
    – socketpair
    Commented Dec 21, 2015 at 18:06
  • Also suspend is no longer supported on recent kernel versions.... Commented Jun 22, 2018 at 14:39
  • permission denied even with sudo
    – endolith
    Commented Feb 1, 2022 at 17:23
12
udevadm info -a -n /dev/sdb

Now check for Kernel. E.g. if it is connected to Port 2 of Front UIP then it would be 1-1.2 and if it is connected to Port 1 of Front UIP then it would be 1-1.1.

For Port 2 : To disconnect USB :

echo '1-1.2' | tee /sys/bus/usb/drivers/usb/unbind

To connect USB :

echo '1-1.2' | tee /sys/bus/usb/drivers/usb/bind
1
  • Works on a 3.10 kernel for me where the suspend/auto didn't.
    – Paul
    Commented Aug 26, 2022 at 20:47
6

Reset the device, or the hub it is connected to, and the device should reappear. Here is a small program to do that:

http://marc.info/?l=linux-usb-users&m=116827193506484

It works for most USB drives I've tried, but there are exceptions, like my Kingston DT 101 II 4GB, which fails INQUIRY and READ CAPACITY commands after reset, and remains unusable until power-cycled.

You can power-cycle the device without unplugging if it gets power from the port, and your USB hub supports per-port power control. Here is a small program to control the power:

http://marc.info/?l=linux-usb-devel&m=113724451205634

Unfortunately, almost no USB hubs support this feature, and it's very difficult to find one that supports it. Manufacturers do not advertise it. Many hubs also lie about it, for example if you do "lsusb -v" you can see "Per-port power switching" advertised in "wHubCharacteristic", but in reality it does not work. The chipset may support it, but it was easier/cheaper for the manufacturer to connect port power pins directly to the power supply instead of going through the chipset.

6

The following will disconnect the USB device.

sudo eject /dev/sde

The following will reconnect the USB device.

sudo eject -t /dev/sde

The above works on my Linux Mint.

0
5

I found this answer to work great on my Gentoo system. Please also remember to re-enable your device if it's an important piece of your system (e.g. mouse or keyboard).

sudo sh -c 'AUTHFILE="/sys/bus/usb/devices/5-2/authorized" ; echo 0 > "$AUTHFILE" ; sleep 1 ; echo 1 > "$AUTHFILE"'

To see what you're disabling/re-enabling:

cat /sys/bus/usb/devices/5-2/product
2
  • This seemed to do the trick on my modern Fedora 25 system. Some of the other methods are no longer possible.
    – xenithorb
    Commented Dec 23, 2016 at 8:28
  • no product file in those paths with kernel 6.1.63 -- answer outdated? Commented Jan 25 at 11:29
4

I have tried most of the above suggestions, but they didn't work for me. I found how to reset a USB device from the command line: https://askubuntu.com/a/290519

echo $i >/sys/bus/pci/drivers/ehci_hcd/bind

where $i you can use appropriate device ID from /sys/bus/pci/drivers/ehci_hcd.

0
4

This script disconnects and reconnects all USB devices.

#!/bin/bash

for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  [ -e "$i" ] || continue
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done
3
  • 1
    Welcome to the site, and thank you for your contribution. In order to be helpful to as wide an audiance as possible, would you mind editing your post to include some explanation on how your solution achieves its goal?
    – AdminBee
    Commented Sep 25, 2020 at 8:46
  • 3
    @AdminBee Added. Technically it does answer the question, but it reconnects all USB devices, which could be a problem. Commented Sep 25, 2020 at 8:51
  • No problem. To do for just one device get the address or name from "sudo lsusb" and run /usr/bin/usbreset for it. In my case /usr/bin/usbreset 'USB3.1 Hub'
    – oat
    Commented Sep 25, 2020 at 16:03
1

My USB touchscreen disconnects and sometimes does not reconnect.

I found that using this command

usbreset 001/002

resets the USB bus and makes it reconnect. It can be useful if you are sure that you do not disturb critical devices ( mounted storage ) on the same bus.

Further reference: usbreset man-page

-2

Many of these things don't work for me, either due to absence of data or my failure to comprehend. I simply suspended my machine and then resumed. My USB mounted mouse was restored.

1
  • You are making a comment on a 10 year old question, but your comment is basically "I suspended and resumed and it worked"? That is NOT a solution.
    – number9
    Commented Jun 17, 2021 at 13:10
-5

I'm uncertain that I'm properly understanding your question, but on my system if a usb device is plugged in but not mounted I can 'see it' by

$> fdisk -l

That tells me what device it's associated with (i.e. /dev/sdd1 or something), then I manually mount it.

1
  • 5
    Again: no, the question is not about a filesystem becoming inaccessible (i.e. unmounted), it's about a device becoming inaccesible (the kernel doesn't see a device, so of course there is no entry under /dev). Commented Feb 16, 2011 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .