{"id":47099,"date":"2024-08-24T15:03:05","date_gmt":"2024-08-24T15:03:05","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47099"},"modified":"2024-10-30T15:18:21","modified_gmt":"2024-10-30T15:18:21","slug":"wake-up-ubuntu-pc","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/08\/wake-up-ubuntu-pc\/","title":{"rendered":"Disable Keyboard, Mouse, or Lid from Waking up Your Ubuntu PC"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-39085\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/hibernate-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>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&#8217;t want.<\/p>\n<div id=\"attachment_34463\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-34463\" class=\"size-large wp-image-34463\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo-600x332.jpg\" alt=\"\" width=\"600\" height=\"332\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo-600x332.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo-300x166.jpg 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo-768x424.jpg 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo-1536x849.jpg 1536w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/laptop-photo.jpg 1600w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-34463\" class=\"wp-caption-text\">image from pixabay.com<\/p><\/div>\n<p><!--more--><\/p>\n<p><b>This tutorial is tested on ThinkPad t480s with Ubuntu 24.04. It should also work on other Linux and other devices, but the &#8220;Lid Open&#8221; action may vary!<\/b><\/p>\n<h3>Option 1: Prevent USB Devices (e.g., Keyboard &amp; Mouse) Waking up Ubuntu<\/h3>\n<p>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.<\/p>\n<p><b>1. Find out your USB device ID<\/b><\/p>\n<p>First, press <code>Ctrl+Alt+T<\/code> on keyboard to open up a terminal window. When it opens, run the command below to list all USB devices:<\/p>\n<pre>lsusb<\/pre>\n<p>My keyboard is connected through a wireless USB receiver. According to the terminal output, &#8220;YICHIP Wireless Device&#8221; is the only one matches my device.<\/p>\n<p>And, the ID is <code>3151:3020<\/code>. They are hexadecimal numbers. And, the <b>first 4 numbers &#8220;3151&#8221; is the vendor ID, while the second 4 &#8220;3020&#8221; is the product ID.<\/b><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/list-usbid.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47458\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/list-usbid-700x366.webp\" alt=\"\" width=\"610\" height=\"319\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/list-usbid-700x366.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/list-usbid-300x157.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/list-usbid.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>2. Add an udev rule for that device<\/b><\/p>\n<p>Next, run the command below in terminal to create a custom udev config file:<\/p>\n<pre>sudo gnome-text-editor \/etc\/udev\/rules.d\/40-disable-wakeup-triggers.rules<\/pre>\n<p><i>Here replace <code>gnome-text-editor<\/code> according to your desktop environment, <code>gedit<\/code> for old GNOME (22.04 and earlier), <code>musepad<\/code> for XFCE, or use <code>nano<\/code> instead that works in most desktops.<\/i><\/p>\n<p>When file opens, write the line below (replace <code>3151<\/code> and <code>3020<\/code> to yours):<\/p>\n<pre>ACTION==\"add|change\", SUBSYSTEM==\"usb\", DRIVERS==\"usb\", ATTRS{idVendor}==\"3151\", ATTRS{idProduct}==\"3020\", ATTR{power\/wakeup}=\"disabled\"<\/pre>\n<p>Here<\/p>\n<ul>\n<li><code>ACTION==\"add|change\"<\/code> tells to do the action on add (usually startup) or change (re-plug-in).<\/li>\n<li><code>ATTR{power\/wakeup}=\"disabled\"<\/code> (<b>here&#8217;s only one &#8220;=&#8221;<\/b>) tell to write &#8220;disabled&#8221; to the <code>power\/wakeup<\/code> so to disable the trigger.<\/li>\n<li>While others (e.g., SUBSYSTEM, DRIVER, idVendor) tell which device to apply the rule.<\/li>\n<\/ul>\n<p><b>NOTE: there are 2 kinds of equal sign &#8220;=&#8221; and &#8220;==&#8221;.<\/b><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47105\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger-700x335.webp\" alt=\"\" width=\"610\" height=\"292\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger-700x335.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger-300x143.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger-768x367.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/disable-keyboard-trigger.webp 1046w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>3. Apply Change<\/b><\/p>\n<p>After saving the config file (for nano, press Ctrl+S to save then Ctrl+X to exit), run the command below to apply change:<\/p>\n<pre>sudo udevadm trigger<\/pre>\n<p>When done, try to suspend your computer and verify if pressing on keyboard will wake it up.<\/p>\n<h3>Option 2: Disable Lid Open Wake up your computer<\/h3>\n<p><b>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.<\/b><\/p>\n<p>Most laptops today support for waking up on lid open action. To enable\/disable this feature, first you need to try the option in <b>BIOS<\/b> settings.<\/p>\n<p>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.<\/p>\n<p><b>1.<\/b> First, open terminal (Ctrl+Alt+T) and run the command below to find out the <code>\/sys\/bus<\/code> sub-folder for the Lid:<\/p>\n<pre>sudo dmesg |grep Lid<\/pre>\n<p>In my case, it&#8217;s <code>\/devices\/LNXSYSTM:00\/LNXSYBUS:00\/PNP0C0D:00\/<\/code>.<\/p>\n<p><b>2.<\/b> Then, try to send &#8220;disabled&#8221; to <code>power\/wakeup<\/code> file for that device folder (replace the bold text accordingly).<\/p>\n<pre>echo disabled | sudo tee \/sys\/<b>devices\/LNXSYSTM:00\/LNXSYBUS:00\/PNP0C0D:00<\/b>\/power\/wakeup<\/pre>\n<p>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 <a href=\"https:\/\/ubuntuhandbook.org\/index.php\/2020\/05\/lid-close-behavior-ubuntu-20-04\/\" target=\"_blank\" rel=\"noopener\">lid switch action to ignore<\/a>.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47106\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup-700x540.webp\" alt=\"\" width=\"610\" height=\"471\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup-700x540.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup-300x231.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup-768x592.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/temp-lid-wakeup.webp 770w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>3.<\/b> If the last step works, then you can create a udev rule to make it permanent.<\/p>\n<p>First, run command to find out the key parameters to identify the device (replace <b>bold<\/b> text according to last command).<\/p>\n<pre>udevadm info -q all -a \/sys\/<b>devices\/LNXSYSTM:00\/LNXSYBUS:00\/PNP0C0D:00\/<\/b><\/pre>\n<p>In my case (see the screenshot), <code>KERNEL==\"PNP0C0D:00\"<\/code>, <code>SUBSYSTEM==\"acpi\"<\/code>, and <code>DRIVER==\"button\"<\/code> is what I need for udev rules.<\/p>\n<p>Next, run command to create (and edit) a udev rule (replace <code>gnome-text-editor<\/code> accordingly):<\/p>\n<pre>sudo gnome-text-editor \/etc\/udev\/rules.d\/40-disable-wakeup-triggers.rules<\/pre>\n<p>While file opens, add line below and save:<\/p>\n<pre>ACTION==\"add\", <b>KERNEL==\"PNP0C0D:00\", SUBSYSTEM==\"acpi\", DRIVER==\"button\",<\/b> ATTR{power\/wakeup}=\"disabled\"<\/pre>\n<p>Also run <code>sudo udevadm trigger<\/code> command or restart computer to apply the change.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47107\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger-700x314.webp\" alt=\"\" width=\"610\" height=\"274\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger-700x314.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger-300x134.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger-768x344.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/udev-lid-trigger.webp 1229w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 3: For other devices<\/h3>\n<p>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.<\/p>\n<p><b>1. Find out who can wake up your computer<\/b><\/p>\n<p>First, press <code>Ctrl+Alt+T<\/code> to open up a terminal window, then run command to list enabled wakeup triggers:<\/p>\n<pre>cat \/proc\/acpi\/wakeup |grep enabled<\/pre>\n<p><i>Skip <code>|grep enabled<\/code> in the command will show all the triggers either enabled or disabled.<\/i><\/p>\n<p>In the output, you&#8217;ll see vendor-specific code names, e.g., XHC (USB 3.0), SLPB (sleep button), LID (laptop lid), their <code>sysfs<\/code> IDs, as well as in which sleep level (s3 &#8211; suspend, s4 &#8211; hibernate) they can wake up from.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cat-wakup-triggers.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47100\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cat-wakup-triggers-700x418.webp\" alt=\"\" width=\"610\" height=\"364\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cat-wakup-triggers-700x418.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cat-wakup-triggers-300x179.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/cat-wakup-triggers.webp 738w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>For PCI devices, you may run one more command to tell more about what they are:<\/p>\n<pre>lspci |grep -e \"xx:xx.x\" -e \"xx:xx.x\" -e \"xx:xx.x\" -e \"xx:xx.x\"<\/pre>\n<p>In the command, replace <code>xx:xx.x<\/code> according to the <code>sysfs<\/code> IDs (e.g., 00:1f.6, 00:14.0, 00:1c.3 in my case) you got in last command. And, add\/remove <code>-e \"xx:xx.x\"<\/code> according to how many PCI devices you want to list.<\/p>\n<p>As the screenshot below shows you, in my case I can wake up my computer from:<\/p>\n<ul>\n<li>GLAN, pci:0000:00:1f.6, the wired network card, from S4 (also includes S3\/S2\/S1) hibernation state.<\/li>\n<li>XHC, pci:0000:00:14.0, USB 3.0 device, from S3 (sleep to RAM) suspend state.<\/li>\n<li>PXSX, pci:0000:04:00.0, Thunderbolt 3 device, from S4 hibernate state.<\/li>\n<li>SLPB (sleep button), LID (laptop lid), and few other PCIe devices.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47101\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers-700x335.webp\" alt=\"\" width=\"610\" height=\"292\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers-700x335.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers-300x144.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers-768x368.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/08\/wakeup-triggers.webp 1026w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>2. Disable wakeup trigger<\/b><\/p>\n<p>To disable one of the wakeup triggers listed above, just run command:<\/p>\n<pre>echo disabled | sudo tee \/sys\/bus\/pci\/devices\/<b>0000:04:00.0<\/b>\/power\/wakeup<\/pre>\n<p>Here replace the ID <code>0000:04:00.0<\/code> (it&#8217;s Thunderbolt 3 device in my case) according to what you got in last command.<\/p>\n<p><b>The last <code>echo<\/code> command works temporarily until reboot or re-plug the devices.<\/b> To make it persistent even after reboot, you may also use udev config file.<\/p>\n<p>a.) First, run command to create (and edit) custom udev rules file (<code>40-disable-wakeup-triggers.rules<\/code> in the case):<\/p>\n<pre>sudo gnome-text-editor \/etc\/udev\/rules.d\/40-disable-wakeup-triggers.rules<\/pre>\n<p><i>Also replace <code>gnome-text-editor<\/code> according to your desktop environment, <code>gedit<\/code> for old GNOME (22.04 and earlier), <code>musepad<\/code> for XFCE, or use <code>nano<\/code> instead that works in most desktops.<\/i><\/p>\n<p>b.) When file opens, add the line below (replace <code>0000:04:0.0<\/code> with yours ID):<\/p>\n<pre>ACTION==\"add\", KERNEL==\"0000:04:0.0\", SUBSYSTEM==\"pci\", ATTR{power\/wakeup}=\"disabled\"<\/pre>\n<p>c.) After saving the file, run <code>sudo udevadm trigger<\/code> command to apply change.<\/p>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":39085,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[653,2203],"class_list":["post-47099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-hibernate","tag-suspend"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47099"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47099\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/39085"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}