Turn off usb linux

Is it possible to turn off a specific USB port so it doesn’t accept any device?

I have a lot of ports on my computer. I would like to turn off one of them, so when I connect my phone to that port, it only charges. I do want my phone to work with my computer in some occasions though, so I hope other ports are not affected. I would just like to know how possible this is.

3 Answers 3

The output should be like:

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. 

In the output, find the device number of the port to be disabled. For example, the Seagate drive in the example has Device 009 — that is its device number. Then the id will be usb[device number] — such as usb9

Then, disable USB wake-up (do this only once):

Be sure to replace X in usbX with the device number.

echo disabled | sudo tee /sys/bus/usb/devices/usbX/power/wakeup 
echo suspend | sudo tee /sys/bus/usb/devices/usbX/power/level 

Undo this:

echo enabled | sudo tee /sys/bus/usb/devices/usbX/power/wakeup echo on | sudo tee /sys/bus/usb/devices/usbX/power/level 

Источник

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.

Читайте также:  Приложения windows linux ios

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:$ 

Источник

Читайте также:  Astra linux отличие от ubuntu

How to turn USB-connected device on and off in linux?

I am using Kensington Expert Mouse, a trackball, which usually works. However, sometimes, after system goes to sleep, it stops reacting to the movement of the ball. Under Windows, i can go to the device manager and disable-enable the device, which results in it working again, but how can i do the same under Linux? Unplugging the device works but is is annoying. My OS is Linux Mint 18.

1 Answer 1

To find out the exact device run:

To disable and enable the device(f.e. USB on port 2 and device ID 1):

$ echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind 

2)Turn device ID 2-1 back on:

 $ echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind 

Alternatively, if you just want to reset a USB device, the bind/unbind can be tricky as the IDs can change overtime and you might accidently select another device. In this case you could use the vendor and product IDs given by lsusb with usb_modeswitch.

F.e.: to identify a wireless adapter:

$ lsusb Bus 001 Device 042: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] Bus 001 Device 035: ID 0409:005a NEC Corp. HighSpeed Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

You can reset the Wireless adapter from Edimax Technology by:

$ sudo usb_modeswitch -v 0x7392 -p 0x7811 --reset-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:

Читайте также:  What is hdr in linux

Источник

Turning off a single usb device. again

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i’m running Debian. The deal is: I bought an usb powered led lamp, which is very simple and doesn’t even have an on/off switch (it works and is always on). I want to be able to turn it on/off via command line. Here’s what i tried:

 echo on > /sys/bus/usb/devices/usb1/power/level # turn on echo suspend > /sys/bus/usb/devices/usb1/power/level # turn off 
 -su: echo: write error: Invalid argument 
 echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms" 
 echo "usb1" > /sys/bus/usb/drivers/usb/unbind 

works only for more «inteligent» devices, like the keyboard, the mouse, or the usb wifi card. What i mean is that only tyhose devices are turned off, other usbN don’t give an error, but the lamp never goes off. the contents of /sys/bus/usb/devices/ are

 1-0:1.0 1-1:1.0 1-2:1.0 1-2:1.2 2-0:1.0 4-0:1.0 4-1:1.0 6-0:1.0 8-0:1.0 8-2:1.0 usb2 usb4 usb6 usb8 1-1 1-2 1-2:1.1 1-2:1.3 3-0:1.0 4-1 5-0:1.0 7-0:1.0 8-2 usb1 usb3 usb5 usb7 
 echo device_name > /sys/bus/usb/drivers/usb/unbind 

with every single one of them, but only the devices usbN and N-M react, the ones of the form n-m:x.y yield

 tee: /sys/bus/usb/drivers/usb/bind: No such device 

(i tried putting in, for instance, «1-0:1.0», «1-0\:1.0» and «1-0\:1.0», all gave the same result). One last thing, what is shown after executing

Источник

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