This tutorial shows how to enable/disable Keyboard, Mouse, Lid Open, and/or other devices events from waking up your Ubuntu PC or laptop from sleep.
By default, open laptop lid, press any key on keyboard, or press sleep button can wake up your computer from suspend or hibernation state. If you want, you can configure Ubuntu to ignore certain wakeup triggers that you don’t want.
This tutorial is tested on ThinkPad t480s with Ubuntu 24.04. It should also work on other Linux and other devices, but the “Lid Open” action may vary!
Option 1: Prevent USB Devices (e.g., Keyboard & Mouse) Waking up Ubuntu
In my case, I have external keyboard and mouse connected to the laptop through USB ports. And, I want to stop the keyboard key press waking up Ubuntu from sleep.
1. Find out your USB device ID
First, press Ctrl+Alt+T
on keyboard to open up a terminal window. When it opens, run the command below to list all USB devices:
lsusb
My keyboard is connected through a wireless USB receiver. According to the terminal output, “YICHIP Wireless Device” is the only one matches my device.
And, the ID is 3151:3020
. They are hexadecimal numbers. And, the first 4 numbers “3151” is the vendor ID, while the second 4 “3020” is the product ID.
2. Add an udev rule for that device
Next, run the command below in terminal to create a custom udev config file:
sudo gnome-text-editor /etc/udev/rules.d/40-disable-wakeup-triggers.rules
Here replace gnome-text-editor
according to your desktop environment, gedit
for old GNOME (22.04 and earlier), musepad
for XFCE, or use nano
instead that works in most desktops.
When file opens, write the line below (replace 3151
and 3020
to yours):
ACTION=="add|change", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="3151", ATTRS{idProduct}=="3020", ATTR{power/wakeup}="disabled"
Here
ACTION=="add|change"
tells to do the action on add (usually startup) or change (re-plug-in).ATTR{power/wakeup}="disabled"
(here’s only one “=”) tell to write “disabled” to thepower/wakeup
so to disable the trigger.- While others (e.g., SUBSYSTEM, DRIVER, idVendor) tell which device to apply the rule.
NOTE: there are 2 kinds of equal sign “=” and “==”.
3. Apply Change
After saving the config file (for nano, press Ctrl+S to save then Ctrl+X to exit), run the command below to apply change:
sudo udevadm trigger
When done, try to suspend your computer and verify if pressing on keyboard will wake it up.
Option 2: Disable Lid Open Wake up your computer
NOTE: This step MAY or MAY NOT work on your laptop!! There seems no unified way to disable the lid open waking up feature. If you know, please tell me by leaving comment below.
Most laptops today support for waking up on lid open action. To enable/disable this feature, first you need to try the option in BIOS settings.
If your BIOS settings page does NOT include that option, you may try the steps below one by one, which however may NOT work in some laptops.
1. First, open terminal (Ctrl+Alt+T) and run the command below to find out the /sys/bus
sub-folder for the Lid:
sudo dmesg |grep Lid
In my case, it’s /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/
.
2. Then, try to send “disabled” to power/wakeup
file for that device folder (replace the bold text accordingly).
echo disabled | sudo tee /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/power/wakeup
When done, suspend your computer then close the lid. Finally, try opening lid a few moments later and see if it wakes up on the action. If it does NOT work, try setting lid switch action to ignore.
3. If the last step works, then you can create a udev rule to make it permanent.
First, run command to find out the key parameters to identify the device (replace bold text according to last command).
udevadm info -q all -a /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/
In my case (see the screenshot), KERNEL=="PNP0C0D:00"
, SUBSYSTEM=="acpi"
, and DRIVER=="button"
is what I need for udev rules.
Next, run command to create (and edit) a udev rule (replace gnome-text-editor
accordingly):
sudo gnome-text-editor /etc/udev/rules.d/40-disable-wakeup-triggers.rules
While file opens, add line below and save:
ACTION=="add", KERNEL=="PNP0C0D:00", SUBSYSTEM=="acpi", DRIVER=="button", ATTR{power/wakeup}="disabled"
Also run sudo udevadm trigger
command or restart computer to apply the change.
Option 3: For other devices
Besides lid open action and USB devices, there are still some other hardware can wake system up. They include sleep (or power) button, network card (wake on lan), and Thunderbolt 3 device.
1. Find out who can wake up your computer
First, press Ctrl+Alt+T
to open up a terminal window, then run command to list enabled wakeup triggers:
cat /proc/acpi/wakeup |grep enabled
Skip |grep enabled
in the command will show all the triggers either enabled or disabled.
In the output, you’ll see vendor-specific code names, e.g., XHC (USB 3.0), SLPB (sleep button), LID (laptop lid), their sysfs
IDs, as well as in which sleep level (s3 – suspend, s4 – hibernate) they can wake up from.
For PCI devices, you may run one more command to tell more about what they are:
lspci |grep -e "xx:xx.x" -e "xx:xx.x" -e "xx:xx.x" -e "xx:xx.x"
In the command, replace xx:xx.x
according to the sysfs
IDs (e.g., 00:1f.6, 00:14.0, 00:1c.3 in my case) you got in last command. And, add/remove -e "xx:xx.x"
according to how many PCI devices you want to list.
As the screenshot below shows you, in my case I can wake up my computer from:
- GLAN, pci:0000:00:1f.6, the wired network card, from S4 (also includes S3/S2/S1) hibernation state.
- XHC, pci:0000:00:14.0, USB 3.0 device, from S3 (sleep to RAM) suspend state.
- PXSX, pci:0000:04:00.0, Thunderbolt 3 device, from S4 hibernate state.
- SLPB (sleep button), LID (laptop lid), and few other PCIe devices.
2. Disable wakeup trigger
To disable one of the wakeup triggers listed above, just run command:
echo disabled | sudo tee /sys/bus/pci/devices/0000:04:00.0/power/wakeup
Here replace the ID 0000:04:00.0
(it’s Thunderbolt 3 device in my case) according to what you got in last command.
The last echo
command works temporarily until reboot or re-plug the devices. To make it persistent even after reboot, you may also use udev config file.
a.) First, run command to create (and edit) custom udev rules file (40-disable-wakeup-triggers.rules
in the case):
sudo gnome-text-editor /etc/udev/rules.d/40-disable-wakeup-triggers.rules
Also replace gnome-text-editor
according to your desktop environment, gedit
for old GNOME (22.04 and earlier), musepad
for XFCE, or use nano
instead that works in most desktops.
b.) When file opens, add the line below (replace 0000:04:0.0
with yours ID):
ACTION=="add", KERNEL=="0000:04:0.0", SUBSYSTEM=="pci", ATTR{power/wakeup}="disabled"
c.) After saving the file, run sudo udevadm trigger
command to apply change.
This is an almost useful article thank you,
Except that it sepcifically says ‘keyboard’ then doesn’t say how to disable the keyboard, nor how to identify it from list of devices. This specifically would be very useful thanks
Updated! Hope it will be more easy to follow.
Thanks for your feedback.