Sample Header Ad - 728x90

How to disconnect and reconnect USB devices on the command line?

2 votes
3 answers
7278 views
I want to find out what gnome-disk is doing, how to do the same on the command line and how to undo whatever gnome-disk does. (It can not undo all it does itself.) I have already experimented a little and found out the following: the USB memory thumb drive ("stick") I played with has at least 3 "state levels" to toggle, 2 of them can be switched with gnome-drive's buttons "eject" (on and off) and "power off" (only off). From highest level to lowest, I discovered: 1. eject * gnome-drive's eject button * drive does not disappear, neither from gnome-drive, nor elsewhere * command line: eject /dev/sdb * can not be undone with gnome-drive * undo with: eject --trayclose /dev/sdb * kernel messages (journalctl -k) * eject * sdb: detected capacity change from 30253056 to 0 * uneject * sd 4:0:0:0: [sdb] 30253056 512-byte logical blocks: (15.5 GB/14.4 GiB) * sdb: detected capacity change from 0 to 30253056 * sdb: [partition details of my drive] 2. (un)bind * did not find equivalent in gnome-drive * command line: echo 3-6 > /sys/bus/usb/drivers/usb/unbind * device disappears in gnome-drive entirely * no kernel messages * lsusb -t still sees the device, but does not show class ("Mass Storage") or driver ("usb-storage") any more * /sys/bus/usb/drivers/usb/3-6 directory gone * undo with echo 3-6 > /sys/bus/usb/drivers/usb/bind * this provokes kernel messages * usb-storage 3-6:1.0: USB Mass Storage device detected * scsi host4: usb-storage 3-6:1.0 * scsi 4:0:0:0: Direct-Access TOSHIBA TransMemory PMAP PQ: 0 ANSI: 6 * sd 4:0:0:0: Attached scsi generic sg2 type 0 * sd 4:0:0:0: [sdb] 30253056 512-byte logical blocks: (15.5 GB/14.4 GiB) * sd 4:0:0:0: [sdb] Write Protect is off * sd 4:0:0:0: [sdb] Mode Sense: 45 00 00 00 * sd 4:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA * sdb: [partition details of my drive...] * sd 4:0:0:0: [sdb] Attached SCSI removable disk 3. power off * gnome-drive's power off button * device disappears on everything, like physically unplugged * indistinguishable from real unplugging * kernel message: * usb 3-6: USB disconnect, device number 10 * **How to power off via the command line?** * **How to power back on without real re-plugging?** --- For completeness: re-plugging the stick assigns a new device number (11), bus and port stay the same (3-6) and these kernel messages are show: usb 3-6: new high-speed USB device number 11 using xhci_hcd usb 3-6: New USB device found, idVendor=0930, idProduct=6545, bcdDevi> usb 3-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 3-6: Product: TransMemory usb 3-6: Manufacturer: TOSHIBA usb 3-6: SerialNumber: C03FD5F7713EE2B1B000821E [plus all kernel messages as quoted under (re-)bind above]
Asked by Robert Siemer (2445 rep)
Nov 27, 2023, 06:38 PM
Last activity: Dec 13, 2023, 10:19 PM