{"id":47335,"date":"2024-10-08T16:07:42","date_gmt":"2024-10-08T16:07:42","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47335"},"modified":"2024-10-08T16:07:42","modified_gmt":"2024-10-08T16:07:42","slug":"completely-disable-suspend-hibernate","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/10\/completely-disable-suspend-hibernate\/","title":{"rendered":"How to Completely Disable Suspend\/Hibernate in Ubuntu 24.04 | 22.04"},"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 completely disable suspend and\/or hibernate function, so your Linux computer will never go to sleep.<\/p>\n<p>Linux can automatically go to sleep when system is idle or laptop lid is closed, though user can configure to disable that behavior via either graphical options or <code>logind.conf<\/code> configuration file.<\/p>\n<p>But, if you never want to sleep your computer, e.g., for server, then you can completely disable this function. So even the suspend option in power-off menu or the corresponding Linux command won&#8217;t work!<\/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<h3>Configure Systemd to Completely Disable System Sleep<\/h3>\n<p>For modern Linux distributions (e.g., Ubuntu, Debian, Fedora, Arch, and openSUSE) suspend, hibernate, and other sleep functions are managed by systemd.<\/p>\n<p>Systemd includes following 4 services that perform the actions when user or system try going to sleep:<\/p>\n<ul>\n<li><code>systemd-suspend.service<\/code><\/li>\n<li><code>systemd-suspend-then-hibernate.service<\/code><\/li>\n<li><code>systemd-hibernate.service<\/code><\/li>\n<li><code>systemd-hybrid-sleep.service<\/code><\/li>\n<\/ul>\n<p>Disable (mask) the services above won&#8217;t stop the actions, instead it breaks the sleep process. In my case, after masking suspend service in Ubuntu, it still can suspend my laptop, though it wakes up automatically few seconds later.<\/p>\n<p>The correct way is to configure the <code>systemd-sleep.conf<\/code> and write rules to tell systemd to disable the functions.<\/p>\n<p><b>1.<\/b> First, open terminal (Ctrl+Alt+T) or connect to your Linux server, then run command to edit the systemd sleep configuration file:<\/p>\n<pre>sudo nano \/etc\/systemd\/sleep.conf<\/pre>\n<p>Here I use <code>nano<\/code> command line text editor that works in both desktop and server. You may replace it with <code>gedit<\/code> for Ubuntu 22.04 &amp; earlier, <code>gnome-text-editor<\/code> for 24.04 &amp; other Linux with recent GNOME, <code>mousepad<\/code> for XFCE, or other text editor depends on your desktop.<\/p>\n<p><b>2.<\/b> When file opens, scroll down and set following rules under <b>[Sleep]<\/b> section:<\/p>\n<pre>AllowSuspend=no\r\nAllowHibernation=no\r\nAllowSuspendThenHibernate=no\r\nAllowHybridSleep=no<\/pre>\n<p>Remove &#8220;#&#8221; at the beginning of the lines above if they exist and set value to <b>no<\/b>, or just add them manually. When done, press <b>Ctrl+S<\/b> to save changes and <b>Ctrl+X<\/b> to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47336\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no-700x436.webp\" alt=\"\" width=\"610\" height=\"380\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no-700x436.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no-300x187.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no-768x478.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/systemd-sleep-no.webp 818w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>3.<\/b> After saving the file, the &#8216;Suspend&#8217; option disappeared immediately from the top-right power-off menu in my Ubuntu 24.04.<\/p>\n<p>And, <code>systemctl suspend<\/code> command refused to function and said &#8216;Call to Suspend failed: Sleep verb &#8216;suspend&#8217; is disabled by config&#8217;.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47337\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work-700x362.webp\" alt=\"\" width=\"610\" height=\"315\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work-700x362.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work-300x155.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work-768x397.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/10\/suspend-not-work.webp 967w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>NOTE: Systemd also read configurations from <code>.conf<\/code> files under <code>\/etc\/systemd\/sleep.conf.d<\/code> directory.<\/b> Meaning, you may run the command below instead to create a custom conf file:<\/p>\n<pre>sudo nano \/etc\/systemd\/sleep.conf.d\/disable-sleep.conf<\/pre>\n<p>Then, add the lines below into the file to either do the same job or even override the previous rules in step 2.<\/p>\n<pre>[Sleep]\r\nAllowSuspend=no\r\nAllowHibernation=no\r\nAllowHybridSleep=no\r\nAllowSuspendThenHibernate=no<\/pre>\n<h3>Re-enable Suspend\/Hibernate<\/h3>\n<p>To re-enable the functions, either re-configure the <code>\/etc\/systemd\/sleep.conf<\/code> file and comment out (add <b>#<\/b> at beginning) the 4 lines.<\/p>\n<p>Or, just delete the file you added, for example &#8216;disable-sleep.conf&#8217;, under <code>\/etc\/systemd\/sleep.conf.d<\/code> directory.<\/p>\n<pre>sudo rm \/etc\/systemd\/sleep.conf.d\/disable-sleep.conf<\/pre>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to completely disable suspend and\/or hibernate function, so your Linux computer will never go to sleep. Linux can automatically go to sleep when system is idle or laptop lid is closed, though user can configure to disable that behavior via either graphical options or logind.conf configuration file. But, if you never [&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,2005],"class_list":["post-47335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-hibernate","tag-suspend","tag-systemd"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47335","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=47335"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47335\/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=47335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}