Ubuntu: Disable mouse wake from suspend


One of the most annoying “features” of Ubuntu is that it will wake from suspend on mouse move, even if waking up your system was the last thing you wanted; in fact, it will wake from suspend, a second after you put it to sleep, if your touch is less than feather-like in releasing the mouse after clicking on the “Suspend” button.

(By the way, Canonical: why did you feel the need to “hide” the Suspend button, and only enable it on Alt-press?)

Unfortunately, the most popular solutions on the matter will also cause the keyboard to be disabled (if you happen to have a USB keyboard) and that is actually something we want.

The “popular” solution (don’t do this) is to modify the /proc/acpi/wakeup system file, by disabling the offending device:

└─( cat /proc/acpi/wakeup | grep enabled

will give you a list of enabled devices, and then it’s a bit of guesswork as to which one is the USB hub that your mouse connects to — on my system there are two: EUSB and USBE, turns out that the hub to which both the keyboard and the mouse are connect is the EUSB, so this would disable both:

└─( sudo sh -c "echo EUSB >/proc/acpi/wakeup"

The above works, but it is crude and, as mentioned, disables the keyboard wake, which is actually useful.

A more granular alternative can be derived from this post which is actually about enabling the wake-on-mouse; but the principle is the same.

First, we start by enumerating the USB devices connected to the system:

└─( lsusb | sort

from here, it’s pretty obvious which one is the mouse:

Bus 002 Device 006: ID 046d:c52b Logitech, Inc. Unifying Receiver

then we proceed with finding where the devices are mapped to:

└─( grep . /sys/bus/usb/devices/*/power/wakeup | grep enabled


Finally, to figure out which is which, we use:

    └─( dmesg | grep Logitech | grep -o -P "usb.+?\s"
    usb 2-1.2.7:

at which point it’s pretty obvious which one needs to be disabled:

└─( sudo sh -c "echo 'disabled' > /sys/bus/usb/devices/2-1.2.7/power/wakeup"

(note: every time you need to echo as superuser, sh -c is necessary, or the system will not allow redirecting to a priviliged file).

Then it’s just a matter of suspending the system and verifying that, while the mouse does not wake it, the keyboard will.

Update: this does not survive a system reboot, so either you need to re-run the last command, or add it to your .bashrc or .zshrc.

This is something that has been annoying me on Ubuntu since when I installed 16.04, and probably there forever, I cannot understand why Canonical wouldn’t add this in the System Settings.


10 responses to “Ubuntu: Disable mouse wake from suspend”

  1. I found the command that will keep my mouse from waking my laptop from suspend: sudo sh -c “echo ‘disabled’ > /sys/bus/usb/devices/1-3/power/wakeup”

    And you’re right that it doesn’t survive a reboot. However, are you sure I’m supposed to put that in my .bashrc file? When I do, it still doesn’t keep my mouse from waking the computer, until I open a terminal. Then, every time I open a terminal, it asks for my sudo password (if I keep the sudo command in) and THEN activates the command, or it tells my i don’t have permission to run that command (if I don’t keep the sudo command in). Neither of those situations is acceptable. Is there a system-wide place I should be putting that command, so that I don’t have to open a terminal and type my password before my mouse is prevented from waking the system?

    1. Hey Mike, thanks for reading my blog!

      That is “expected behavior” as `.bashrc` is only executed upon running an interactive TTY session (and not a graphic UI) – there is a way to add scripts to be run at login (if memory serves, you need to use Alt+F2 or something like that) but I found it rather unreliable.
      To get you going, I recommend googling “ubuntu login run scripts”

      And, anyway, Terminal (actually, Terminator 🙂 ) is the first thing I run upon logging in Ubuntu: without a shell, it’s not much use to me.

      As for asking your password when using `sudo` this is, again, “expected behavior” and protects the integrity of the system; you can bypass it by adding your user to the `sudoers` group (remember to use `visudo` to edit the /etc/sudoers file); this may help guiding you in the right direction: https://codetrips.com/2012/01/18/adding-a-new-sudoer-in-ubuntu/

      Hope this helps!

  2. I’ve just updated from 18.04 to 20.04 and mouse wake from suspend no longer works, so someone must have been listening to you! On 16.04 wake worked for a while then stopped working, on 18.04 wake worked fine, now on 20.04 I’m back to pressing the power button to wake!! I have tried a couple of online solutions, none have worked and I’m scared I’ll do damage. The ability to control wake should be in SETTINGS or a TWEAK utility. In someways I wish I had not updated to 20.04.

    1. I can only wish… I am on Ubuntu 20.04:
      $ lsb_release -a
      No LSB modules are available.
      Distributor ID: Ubuntu
      Description: Ubuntu 20.04.2 LTS
      Release: 20.04
      Codename: focal
      and if I execute this (it takes a bit of fiddling to figure out the right device, see the Python script for more details):
      $ grep . /sys/bus/usb/devices/*/power/wakeup | grep enabled
      (this is the keyboard) and mouse wakeup doesn’t work; then:
      $ sudo sh -c “echo ‘enabled’ > /sys/bus/usb/devices/2-1.7.7/power/wakeup”
      then Suspend, and mouse wakeup works just fine: just twiggle the mouse (don’t even need to click, on my systems, YMMV).

      To disable again (I can’t imagine why you need it, TBH):
      $ sudo sh -c “echo ‘disabled’ > /sys/bus/usb/devices/2-1.7.7/power/wakeup”
      Hope this helps and thanks for reading!

  3. Any way to do this with a wireless mouse connected via a USB 2.4Ghz adapter?
    None of the devices has `wakeup:enabled’ on my box and yet the mouse does wake up the system from suspend

    1. This actually works regardless of whether the mouse is wired/wireless (mine is just like yours, for that matter, and it shows up just fine).
      I am not sure why it doesn’t show up in the list of devices, I’m afraid.

    2. Trevor O Bartram Avatar
      Trevor O Bartram

      My experience is the opposite. With 16.04 & 18.04 Ubuntu did wake from sleep with mouse movement. With 20.04 it no longer wakes with mouse, I have to tap the power button on my desktop PC to wake it. I’m slowly getting used to this. When waking in this way, the DVD drives do cycle momentarily as well, hopefully this doesn’t cause unnecessary wear on the drives.
      Control of waking should really be included in Ubuntu settings but for some reason it never has been.

      1. I assume then that it doesn’t wake with keyboard press either? I’m guessing it somehow disabled USB wakeup entirely, so you should be able to enable it using exactly the process described here, just in reverse (write `enabled` into the relevant devices).
        I wouldn’t worry too much about the DVD drives (you really have still those? amazing! 🙂 ) they are supposed to spin up and down million of times, if you were to wear them down by turning on/off your computer, you’d have other problems too…

        And I completely agree with you: Ubuntu Desktop should totally provide in settings the ability to enable/disable wake-from-suspend for all the various external devices (at the very minimum, mouse/keyboard): it can’t be *that* difficult.

  4. There is simpler solution making udev rule to make the setting permanent here:

    1. Thanks for pointing this out.
      I am unable to test it out right now, but soon as I can validate it, I will update the post.
      Thanks again, and thanks for reading my blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: