Linux poweroff usb device

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

Читайте также:  Linux create test file

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?

Добрый день, есть устройство (Атол) — pos терминал, на борту ubuntu 16.04. Есть сканер ШК — Haneywell 1250g. Суть проблемы: сканер при выключении, включении системы не включается сам, если его передернуть из USB то все хорошо.

Читайте также:  Arch linux intel graphics drivers

Каждый раз, при включении, передергивать его — не хорошо, хочеться автоматизировать сей процесс..

Причем в системе он не определяется (пока не передернешь его). Есть ли возможность отключить питание на USB порты?

Видел это, ошибка при выполнении команды:

echo suspend > /sys/bus/usb/devices/usb1/power/level bash: echo: ошибка записи: Недопустимый аргумент 

Значит, хаб не поддерживает управление питанием. Что вряд ли, скорее всего ты дёргаешь не то устройство.

Что то я не понимаю..

lsusb -t /: Bus 02.Port 1: Dev 1, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Driver=hub/6p, 480M |__ Port 4: Dev 4, If 0, Interface Device, Driver=usbhid, 12M |__ Port 4: Dev 4, If 1, Interface Device, Driver=usbhid, 12M /: Bus 01.Port 1: Dev 1, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Driver=hub/6p, 480M 

пытался к второй шине подключить..тот же результат..

lspci | grep USB 00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 05) 00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 05) 

где глянуть поддерживает ли hub управление питанием? хотя точно поддерживает, это ноутбук..через laptop-mode-tools USB то отключаются.

Есть ли возможность отключить питание на USB порты?

Питание нет. Сам долго думал что такое возможно, оказался не прав. Подобная тема уже была здесь.

Наоборот, редкие хабы поддерживают управление питанием.

Источник

Turning off power to usb port. Or turn off power to entire usb subsystem

I have a usb lamp which I specifically bought in order to turn it off programmatically at a certain time, thus I need to remove the power to its usb port. I believe I have a usb-hub at usb6. The lamp is connected to one of the ports in this hub:

#myhost$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 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 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub . . Bus 008 Device 006: ID 050d:0234 Belkin Components F5U234 USB 2.0 4-Port Hub 
echo disabled > /sys/bus/usb/devices/usb1/power/wakeup echo suspend > /sys/bus/usb/devices/usb1/power/level # turn off 

but I get write error: Invalid argument when trying to write to /sys/bus/usb/devices/usb1/power/level :

$sudo bash -c 'echo disabled > /sys/bus/usb/devices/usb6/power/wakeup' $echo suspend|sudo tee /sys/bus/usb/devices/usb6/power/level suspend tee: /sys/bus/usb/devices/usb6/power/level: Invalid argument $sudo bash -c 'echo suspend> /sys/bus/usb/devices/usb6/power/level'bash: line 0: echo: write error: Invalid argument 
sudo bash -c 'echo 0 > /sys/bus/usb/devices/usb6/power/autosuspend_delay_ms; echo auto > /sys/bus/usb/devices/usb6/power/control' 

which does turn off power to the usb-hub device. I was also trying to follow this: But the output of lsusb -t just hangs:

$lsusb -t 4-1:0.0: No such file or directory 4-1:0.1: No such file or directory ^C 
echo '2-1.1' > /sys/bus/usb/drivers/usb/unbind 

Is there an alternative way of getting this information? Alternatively, is there a way to shut off power to the entire usb subsystem? Something like modprobe -r usb_etc ? My kernel is:

Читайте также:  Linux ubuntu права суперпользователя

Источник

Is there a way to power down a USB device using software?

Is there a way that I can power off a (specific) USB device completely using software from a Linux machine? I want to use this to power off (so that the LED is off) a (single) USB stick. Do you know any method to achieve this? E.g. using /sys/bus/usb or the like?

No, that doesn’t help. There is also the possibility that there are no usable partitions (which could be mounted) on the stick.

For a flash drive, the one way to remove the disk is echo 1 > /sys/block/sd/device/delete . (eject might be doing that. ) It MIGHT result in the device being (soft) «powered off». (If it works for disks, it won’t work for non-disk devices..)

2 Answers 2

If your machine runs old kernel, you could issue echo suspend > /sys/bus/usb/devices/X-X/power/level to force suspension of device.

However, since 2.6.32 this is no longer possible:

We can categorize power management events in two broad classes: external and internal. External events are those triggered by some agent outside the USB stack: system suspend/resume (triggered by userspace), manual dynamic resume (also triggered by userspace), and remote wakeup (triggered by the device). Internal events are those triggered within the USB stack: autosuspend and autoresume. Note that all dynamic suspend events are internal; external agents are not allowed to issue dynamic suspends.

power/control This file contains one of two words: "on" or "auto". You can write those words to the file to change the device's setting. "on" means that the device should be resumed and autosuspend is not allowed. (Of course, system suspends are still allowed.) "auto" is the normal state in which the kernel is allowed to autosuspend and autoresume the device. (In kernels up to 2.6.32, you could also specify "suspend", meaning that the device should remain suspended and autoresume was not allowed. This setting is no longer supported. 

I guess the best thing you can do is to unbind device from driver, so there would be no activity on it, and then configure the device to autosuspend as soon as possible ( echo auto > /sys/bus/usb/devices/X-X/power/control && echo 0 > /sys/bus/usb/devices/X-X/power/autosuspend_delay_ms ).

However, as far as I understand USB specs, even if you suspend the device, some power on port will remain, so it might be impossible to disable led if it is powered by ‘dumb’ scheme (i.e. directly connected to +5V and GND pins).

Источник

Оцените статью
Adblock
detector