I had the same problem with Ubuntu 16.04 (Xenial Xerus) and searched so much for any solution...
The solution is at the end of this answer if you don't care about the context story. Context could look like unuseful blabla (maybe it is), but I think that it could help readers to check if the problem I've solved on my PC is the same as their one.
CONTEXT
I desperately have unsuccessfully tested near every tips I've found on the web, rebooting after each try:
- '/etc/default/grub' kernel boot
usbcore.autosuspend=-1
parameter
- laptop-mode's 'runtime-pm.conf'
CONTROL_RUNTIME_AUTOSUSPEND=0
- fully disabling Laptop Mode Tools from '/etc/laptop-mode/laptop-mode.conf' file, confirming that the problem isn't related to this kernel feature. I've checked different ways that laptop_mode wasn't running anymore to be sure. (Ref:
man laptop-mode.conf
& man laptop_mode
)
- I've read some tricks about '/etc/laptop-mode/conf.d/usb-autosuspend.conf', but this file doesn't exist in my version of Ubuntu 16.04 with laptop-mode-tools v1.68
- powertop application uninstallation. It's often suspected in forums to cause autosuspend issues, and today I know that it was not true in my case as uninstalling it didn't fix anything.
options usbcore autosuspend=1
in '/etc/modprobe.d/usb.conf' has been inefficient too
- '/etc/udev/rules.d/60-power.rules' script provided by Gentoo official Wiki
- device-specific
rules
file for udev
'/etc/udev/rules.d/usb-power.rules' recommended by Serge Y. Stroobandt
After having read all this technical stuff I only understood that the cause was related to my '/sys/module/usbcore/parameters/autosuspend' value stuck at two seconds, no matter what change I do to my configuration. You can check it with cat
command:
$ cat /sys/module/usbcore/parameters/autosuspend
2
And yes, my mouse was disabled exactly after two seconds, so I knew I was on the right way. Of course I had tested the echo -1
command that I've seen here and there, -1
intended to disable autosuspend... but:
sudo echo -1 > sys/module/usbcore/parameters/autosuspend
bash: /sys/module/usbcore/parameters/autosuspend: Permission denied
I didn't understand why permission was denied even in sudo mode. I didn't try as root, because I just didn't think that it could be a problem. Here was the mistake :(
Thanks to Alex Dekker & Bryce comments, I've learnt how to disable autosuspend only for my mouse. But of course my first tries have failed with this bash: Permission denied error
, so I had to wait for understanding of my root/sudo confusion before the echo -1
command suggested by Alex finally work.
I've also found a better way to execute a command as the root user without login as root. The difference between root shell and root commands usage is well explained in the official Ubuntu's RootSudo wiki page. I love to learn to these kind of things, but hey! Why does it have to be always learnt the painful way? LOL
OMG, it was a real headache, and it took lot of time for a noob like me to understand, as I usually say "no brain no gain". Mine visibly needs more training.
So let's stop talking about myself and go fix it! Please continue below...
I highly recommend the second solution for your idle external HDD to don't drain your laptop battery for nothing. But I give you both solutions, because who loves his/her own freedom should love each others freedom too :)
SOLUTION 1
To disable autosuspend on every USB devices/ports
Open Terminal and execute:
sudo sh -c "echo -1 > /sys/module/usbcore/parameters/autosuspend"
This is indeed a temporary solution that allows you to instantly test if this command fixes your mouse or keyboard autosuspend issue.
If your USB device(s) work fine now, just edit your '/etc/rc.local' script so it will run that command whenever the system is booted. This way you'll make the fix kind of permanent. Edit the file, for example with nano:
sudo nano /etc/rc.local
and put the echo -1
command in your '/etc/rc.local' file before the exit 0
line
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
(...)
# By default this script does nothing.
echo -1 > /sys/module/usbcore/parameters/autosuspend
exit 0
Restart your computer
(Please check the Important note at the end.)
.
SOLUTION 2
To disable autosuspend for a specific USB device/port
The power options for a USB device are in /sys/bus/usb/devices/n-n/power
. What n-n
is for a given device requires a few manipulation to find out, but it's not complicated. The example below shows how I've determined that the USB port number of my wireless mouse receiver is 3-1
, so please adapt this to your own situation:
Unplug your USB device, open Terminal and execute the sudo dmesg
command
Connect your USB device back, and then execute sudo dmesg
again in Terminal to check for changes
Here's what the end of my dmesg
command output looks like after having plugged my mouse back in a slot:
[40208.575249] usb 3-1: new full-speed USB device number 8 using xhci_hcd
[40208.705233] usb 3-1: New USB device found, idVendor=062a, idProduct=4102
[40208.705240] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[40208.705245] usb 3-1: Product: 2.4G Wireless Mouse
[40208.705248] usb 3-1: Manufacturer: MOSART Semi.
[40208.707679] input: MOSART Semi. 2.4G Wireless Mouse as /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/0003:062A:4102.0007/input/input24
[40208.763946] hid-generic 0003:062A:4102.0007: input,hiddev0,hidraw0: USB HID v1.10 Mouse [MOSART Semi. 2.4G Wireless Mouse] on usb-0000:00:14.0-1/input0
Now we can see that the port where my USB device has been plugged-in is identified as usb 3-1
.
**Note:** this trick concerns the USB port ID, not a device ID. For example, if I plug my mouse to the next USB port, it becomes identified as `usb 3-2` in the `dmesg` result. But this solution #2 remains very useful if you take the habit to always plug your mice or keyboard to the same port, and it's generally what people use to do unconsciously ;)
Execute the following command in your Terminal, changing my port number 3-1
with the one you've found in your own dmesg
result:
sudo sh -c "echo -1 > /sys/bus/usb/devices/3-1/power/autosuspend_delay_ms"
Note that autosuspend_delay_ms
has replaced the deprecated autosuspend
since kernel version 2.6.38, according to the Linux official documentation.
This is indeed a temporary solution, but you can now easily test if this command fixed your mouse or keyboard autosuspend issue.
If your USB device work fine now, just edit your '/etc/rc.local' script so it will run that command whenever the system is booted. This way you'll make the fix kind of permanent. Edit the file, for example with nano:
sudo nano /etc/rc.local
and put the echo -1
command in your '/etc/rc.local' file before the exit 0
line, once again don't forget to change port number n-n
in the command:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
(...)
# By default this script does nothing.
echo -1 > /sys/bus/usb/devices/3-1/power/autosuspend_delay_ms
exit 0
Restart your computer
.
Important: don't forget that you'll have to execute the sudo sh -c
"temporary" command again manually if you disconnect/reconnect your USB device while your desktop environment is already started, even if you plug it back on the same USB plug. Normal, just because the '/etc/rc.local' file is called only once at system startup.
Anyway, workarounds are possible. Better skilled peoples may have more clever methods, but I've configured port-specific aliases in Ubuntu. It allows me to use the simple usb1
or usb2
commands selectively if I have to unplug/replug my USB device here or there. You too! You could also create commands aliases to play with short words instead of typing the full command. It's easy to set in less than two minutes and also works with Alt + F2 :)
More ideas to make it easier would be also very welcome.
xserver-xorg-input-all
worked for me when I upgraded toUbuntu 17.04