- Power on/off USB ports
- 4 Answers 4
- USB storage devices
- Auto-mounting with udisks
- Manual mounting
- Getting a kernel that supports usb_storage
- Identifying device
- Mounting USB memory
- Allow writing by regular users
- As normal user with fstab
- Mount tools
- Troubleshooting
- No USB storage devices are detected
- Device not shutting down after unmounting all partitions
- Device is detected but does not register as mountable
Power on/off USB ports
Is it possible to on/off a specific USB port using the terminal in Ubuntu? lsusb displays the following result:
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 2232:1020 Bus 002 Device 009: ID 0bc2:a013 Seagate RSS LLC Bus 002 Device 003: ID 0a5c:219c Broadcom Corp.
Seagate is my external hard disk drive. Can I power it off in the terminal? I tried Controlling a USB power supply (on/off) with Linux. But I am confused about what should be replaced in place of usbX .
4 Answers 4
All of the previous answers talk about a USB suspend mechanism, i.e. a «logical power-off», they will never physically cut the VBUS +5V from the USB port.
Only a few hubs can actually cut VBUS as described here.
The hubpower tool can do it (if the hub supports it).
After running into the same problem, I found that the commands should be entered differently so that «sudo» would apply rights appropriately.
echo 0 | sudo tee /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms
will apply root rights to the «tee» command which will write the 0 into the specified file, replacing anything that is currently there. To append, use the tee command with option -a.
for info see the man page of tee
The tee command will have the side effect of also printing to the screen. If you want, dd of=/sys/bus/. will write only to the file, and nowhere else.
Actually usbX is nothing but the USB ports numbers where X denotes the number like 1 or 2 and so on. For example, usb1 and usb2 for ports 1 and 2. In general, a laptop may have three or four USB ports with USB 2.0 and USB 3.0 ports.
In Ubuntu, usb1 , usb2 . usbX are the links to /sys/devices/pci000:00/* . To understand it well, run this command:
So to enable/disable USB ports usbX will be replaced with usb1 when you want to enable/disable USB Port Number 1 (or refer Stack Exchange):
Edit: Thanks to Stefan Denchev to tell the correct way to echo some text to a file using sudo. (Check his comment also.) You should not get the permission denied message now.
sudo sh -c "echo '0' > /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms" sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb1/power/control"
After seeing your lsusb result, it looks like your Seagate device is connected to Port No. 2 , so you need to disable usb2 . Then the commands would be:
sudo sh -c "echo '0' > /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms" sudo sh -c "echo 'auto' > /sys/bus/usb/devices/usb2/power/control"
Thanks. If I try echo «0» > «/sys/bus/usb/devices/usb2/power/autosuspend_delay_ms» the output is bash: /sys/bus/usb/devices/usb2/power/autosuspend_delay_ms: Permission denied
Actually I didn’t try to enable/disable any ports in Linux.. My motto was to make you clear about usbX problem. If you are much clear about the commands that you grabbed from StackOverflow then only you should give it a try. Any way now I am also interested to know which is actual command to enable/disable ports. I’ll reply you soon, when it works for me. Tell then you unplug your device and try again. or try the first answer given at stackoverflow .
udisksctl has power-off flag, which I suggest you use in conjunction with unmount
power-off Arranges for the drive to be safely removed and powered off. On the OS side this includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage. The exact steps for powering off the drive depends on the drive itself and the interconnect used. For drives connected through USB, the effect is that the USB device will be deconfigured followed by disabling the upstream hub port it is connected to
Here’s me unmounting my USB jumpdrive and then powering it off
testdir:$ lsusb Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 009: ID 154b:007a PNY Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub testdir:$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 111.8G 0 disk └─sda1 8:1 0 111.8G 0 part / sdb 8:16 1 30G 0 disk └─sdb1 8:17 1 30G 0 part /media/xieerqi/6A32C4555E1C5B4D sr0 11:0 1 1024M 0 rom testdir:$ udisksctl unmount -b /dev/sdb1 && udisksctl power-off -b /dev/sdb1 Unmounted /dev/sdb1. testdir:$ lsusb Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub testdir:$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 111.8G 0 disk └─sda1 8:1 0 111.8G 0 part / sr0 11:0 1 1024M 0 rom testdir:$
USB storage devices
This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage device.
If you have an up-to-date system with the standard Arch kernel and a modern desktop environment, your device should just show up on your desktop, with no need to open a console.
Auto-mounting with udisks
This is the easiest and most frequently used method. It is used by many desktop environments, but can be used separately too.
See Udisks for detailed information, including list of mount helpers.
Manual mounting
Note: Before you decide that Arch Linux does not mount your USB device, be sure to check all available ports. Some ports might not share the same controller, preventing you from mounting the device.
Getting a kernel that supports usb_storage
If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest udev, you may just plug your device in and the system will automatically load all necessary kernel modules.
Identifying device
The first thing one needs to access a storage device is its identifier assigned by kernel. See File systems#Identify existing file systems for details.
Newly plugged-in devices are usually shown in the journal.
Mounting USB memory
If mount does not recognize the file system of the device you can try to use the -t argument, see mount(8) for details. If mounting does not work, you can try to recreate the file system or even repartition the disk.
Allow writing by regular users
If you want non-root users to be able to write to the USB stick, you can issue the following command:
# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick
If it does not work, make sure that the file system is mountable and writable as root, see the previous section for details.
As normal user with fstab
See FAT#Writing to FAT32 as normal user if you want normal user to do the mount/unmount action.
Mount tools
Multiple mount tools facilitate mounting as a regular user.
Troubleshooting
No USB storage devices are detected
If you have connected your USB storage device and it is not listed by lsblk but appears in the journal without being assigned a block device, see General troubleshooting#Cannot use some peripherals after kernel upgrade.
Also ensure that your BIOS has both XHCI Handoff and EHCI Handoff enabled, but this is usually not an issue with most modern devices.
Device not shutting down after unmounting all partitions
This article or section needs expansion.
Reason: Please advise how to automatically shut down devices after unmounting (Discuss in Talk:USB storage devices)
Failure to power off a device might result in:
- a hard disk drive not parking its head, making a faint scratching sound while spinning out and degrading the device [2], or
- a solid-state drive (especially older) not flushing its cache buffers or updating its mapping tables, and losing data [3].
When you unmount the partitions, the device is still powered on. You should ask the system to turn it off first in order to safely remove it: [4]
# echo 1 > /sys/block/disk_name/device/delete
If you use udisks, you can use these commands: [5]
$ udisksctl unmount -b /dev/sdXY $ udisksctl power-off -b /dev/sdX
Device is detected but does not register as mountable
udev is shipped with a default set of rules, found in /usr/lib/udev/rules.d/ , including one for ignoring some specific devices for various reasons. Some hardware devices, such as digital cameras, portable recorders, etc., may format usb storage in a way that results in the ignore rules to be triggered. You can check if one of these rules was applied with the following command and then find the corresponding conditions in the defaults:
$ udevadm info --attribute-walk --name=device_name | grep UDISKS_IGNORE
If this is the case and your device has this property set to «1», you can override it with a custom rule, following the udev page.