In this article, we take you through how to disable suspend and hibernation modes on a Linux system. But before we do that, let’s briefly have an overview of these two modes.
When you suspend your Linux system, you basically activate or put it into sleep mode. The screen goes off, even though the computer remains very much powered on. Also, all of your documents and applications remain open.
Suspending your system helps save power when you are not using your system. Getting back to using your system requires a simple mouse-click or a tap on any keyboard button. Sometimes, you may be required to press the power button.
There are 3 suspend modes in Linux:
- Suspend to RAM (Normal Suspend): This is the mode that most laptops automatically enter incase of inactivity over a certain duration or upon closing the lid when the PC is running on the battery. In this mode, power is reserved for the RAM and is cut from most components.
- Suspend to Disk (Hibernate): In this mode, the machine state is saved into swap space & the system is completely powered off. However, upon turning it on, everything is restored and you pick up from where you left.
- Suspend to both (Hybrid suspend): Here, the machine state is saved into swap, but the system does not go off. Instead, the PC is suspended to RAM. The battery is not used and you can safely resume the system from the disk and get ahead with your work. This method is much slower than suspending to RAM.
Disable Suspend and Hibernation in Linux
To prevent your Linux system from suspending or going into hibernation, you need to disable the following systemd targets:
$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
You get the output shown below:
hybrid-sleep.target Created symlink /etc/systemd/system/sleep.target → /dev/null. Created symlink /etc/systemd/system/suspend.target → /dev/null. Created symlink /etc/systemd/system/hibernate.target → /dev/null. Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
Then reboot the system and log in again.
Verify if the changes have been effected using the command:
$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
From the output, we can see that all four states have been disabled.
Enable Suspend and Hibernation in Linux
To re-enable the suspend and hibernation modes, run the command:
$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Here’s the output that you will get.
Removed /etc/systemd/system/sleep.target. Removed /etc/systemd/system/suspend.target. Removed /etc/systemd/system/hibernate.target. Removed /etc/systemd/system/hybrid-sleep.target.
To verify this, run the command;
$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
To prevent the system from going into suspend state upon closing the lid, edit the /etc/systemd/logind.conf file.
$ sudo vim /etc/systemd/logind.conf
Append the following lines to the file.
[Login] HandleLidSwitch=ignore HandleLidSwitchDocked=ignore
Save and exit the file. Be sure to reboot in order for the changes to take effect.
This wraps our article on how to disable Suspend and hibernation modes on your Linux system. It’s our hope that you found this guide beneficial. Your feedback is most welcome.
Hey, I love following you, James. Great articles, great know-how, and also a surprisingly good community for a Linux crowd!
Thanks.
Good work, James.
Disabling all suspend and hibernate options on my Mint just became less daunting thanks to this helpful tutorial.
I changed my distro from LM 21.3 to LMDE 6. The Debian Edition doesn´t have hibernation and suspend mode by default. So I was searching the same and found this amazing article.
Now all modes are available and the info to edit the /etc/systemd/logind.conf file to handle the lid of my laptop is amazing.
Great work.
You can also edit /etc/systemd/sleep.conf or do it the drop-in way and put this in /etc/systemd/sleep.conf.d directory.
You have to create the file first.
Next add the following lines to sleep.conf file as shown.
Thanks a lot this worked on Linux Ubuntu 22.04.
I’m using Ubuntu 18.04.
I tried as you said, it’s gone, but after a few minutes the pause symbol is showing again on top, whenever I get this symbol my keyboard is not working, and when I try to click with the mouse in the browser it is downloading html file.
I’ll be very thankful for any solutions to get rid of this.
Hello Good Android Team,
I tried to enable suspend and hibernation mode in Linux, but every time I copy and paste the above, command I run into this error message “Command not found” am really worried.
Any help would really be of help.
will this work with arch-based distros?
Only if it uses systemd as its init.
Does this command also disable sleep and hibernate for a USB HDD? If not, how would you go about doing that?
Hi,
Thank you so much for the great topic.
Thanks, Jalal, You are welcome. Keep it Tecmint.
Hi James, thanks for the info but how can I remove being suspended in my own hiber account cause the hiberofficials suspended me i did not even do something wrong please help me James thanks.
Hi James,
Great tutorial, thanks! The other day I installed a music server on an old notebook running Ubuntu Server 20.04.1. Whenever I closed the lid it went to sleep (or hibernation?). The command
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
, and editing the file edit the /etc/systemd/logind.conf file, solves the issue indeed.However, with a side effect: the process /lib/systemd/systemd-logind starts eating up most of the CPU power, going up to 80% and remaining there. When I open the lid it slowly decreases; I close the lid, and up goes the CPU load again:
Checking /var/log/auth.log shows it starts being filled up with this when I close the lid, and until opening again:
With some more searching I found this page:
https://serverfault.com/questions/1045949/how-to-disable-suspend-on-ubuntu-20-04-systemd-via-cli
In my case unfortunately updating /etc/systemd/logind.conf & reboot does not help. Continuing my googling …
Thanks & best regards
Mark
One more line in /etc/systemd/logind.conf does the trick:
Now all is fine, no extra CPU load, and all normal in auth.log.
BR Mark
The title should be “How to disable suspend and hibernate in SYSTEMD”. To claim that this is universal across all of Linux is just plain wrong. The steps outlined in the article do not work on many distros. Ubuntu is NOT the be-all and end-all of Linux.
Hi Dragonmouth,
I totally agree with you that Systemd, while frequently used with Linux, is not the same thing as Linux. It’s too bad the misleading headline pulled you in and annoyed you. It would be better if the title was: “How to disable suspend and hibernate using Systemd on Linux”.
On the other hand, I have to admit that the tips worked for me as I haven’t used a non-systemd box in a long time. I miss those times. Even all these years since it took over, the systemd still feels like a foreign invader, forcing me to speak its stilted dialect and learn new, tortuous ways of doing things I used to be able to do simply.
I still haven’t figured out how to do some things: like if a particular process is hanging at boot time, being able to hit ^C to just cancel it and go on booting was super handy. Is there even a systemd equivalent? I don’t think so.
There was a time when it wasn’t completely ludicrous for someone to say, “This is a UNIX system. I know this!” Now, UNIX is just vestigial trappings, a quisling prince kept as a figurehead for appearances, but powerless. Systemd is the true power.
But don’t blame the “everything is Ubuntu” mentality. Systemd is a much wider scourge having taken over Debian and its derivatives. Ultimately, Systemd was created by RedHat, so I blame them, even if it is
Linus Torvald’s distribution of choice.
“Linux is Ubuntu and Ubuntu is Linux” viewpoint predates systemd by a few years. However, because of being almost universally pushed, *buntus have done their part in the spread of the systemd pandemic.
Systemd is an init that aspires to be a distro. Luckily there still are some very good distros that have not been infected.
By the way, if you don’t use systemd, it looks like you can just write to certain files in /sys/power/. I don’t know how to make that setting stick, though.