Home Linux Tips & Tricks How To Disable Suspend And Hibernation In Linux

How To Disable Suspend And Hibernation In Linux

By sk
Published: Last Updated on 46.2K views

Today we are going to learn how to disable suspend and hibernation in Linux. Before we get into the topic, let us see a brief introduction to suspend and hibernate modes in Computer.

What are Suspend and Hibernate Modes?

Whenever you suspend your system, the computer will enter into sleep mode. Meaning - all of the opened applications, files and documents remain open, but the monitor and other parts of the system will be switched off to save the power. When you suspend the computer, it is not going to be completely powered off. The computer is still switched on and it will still be using a small amount of power.

The hibernation is one of the type of suspend. There are currently three suspend methods available:

  1. Suspend to RAM or Normal Suspend - In this mode, the screen and most parts of the system will be turned off (but not completely) except the RAM. All Laptops will enter this suspend mode when the user is inactive for a particular time or when the system is running on batteries or the lid is closed. When you press a Key or click the mouse button, the computer will wake up to the normal mode.
  2. Suspend to DISK or Hibernate-  In this mode, the current computer's state will be saved into swap space and the system will be turned off completely. When you turn on the system again, the state is restored. This is usually known as hibernation.
  3. Suspend to BOTH or Hybrid Suspend- In this mode, the current computer's state is saved into swap space and the usual suspend to RAM mode is invoked. So, the computer is not turned off completely. If the battery is depleted, the computer can be resumed from disk. If the battery is not depleted, the computer can be resumed from RAM. This is sometimes called as hybrid suspend.

Hope you get the basic idea about suspend and hibernate modes. Now, let us get back to the topic and see how to disable suspend and hibernate modes.

Disable Suspend and Hibernation in Linux

If you want to prevent your Linux machine from suspending and hibernating, disable the following targets at the systemd level:

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

Sample Output:

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.
Disable Suspend And Hibernation In Linux
Disable Suspend And Hibernation In Linux

Save all works (just in case) and then run the following command to apply the changes:

$ sudo systemctl restart systemd-logind.service

Alternatively, reboot the system for this to take effect.

Check if the changes have been really applied:

$ systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target

Sample Output:

● sleep.target
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

● suspend.target
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

● hibernate.target
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

● hybrid-sleep.target
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

As you see in the above output, the suspend and hibernate system targets have been masked and inactive.

To re-enable suspend and hibernate on your system, simply run:

$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

Sample output:

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.

If you just want to prevent suspending when the lid is closed, edit /etc/systemd/logind.conf file:

$ sudo nano /etc/systemd/logind.conf

Add/modify the following lines:

[Login] 
HandleLidSwitch=ignore 
HandleLidSwitchDocked=ignore

Save and close the file. Don't forget to restart systemd-logind.service or reboot your system to take effect the changes.

For more details, check man pages.

$ man logind.conf

Hope this helps.

You May Also Like

8 comments

Jalal April 20, 2020 - 9:07 am

Hi,
Very useful article
Thanks a lot

Reply
Thales July 28, 2020 - 2:38 am

Excellent tip!

Thank you.

Reply
Cleber Shimizu August 28, 2020 - 7:14 pm

After the command
$ sudo systemctl restart systemd-logind.service
the system did not boot anymore. Tried to reinstall, but did not have the option without losing data. Please help!

Reply
sk August 28, 2020 - 8:21 pm

What did you do actually? This how-to will not cause any data loss. This is just a basic tip. I guess you did something else.

Reply
Koko September 8, 2022 - 11:15 pm

Systemctl works fine for RHEL7, but how To Disable Suspend And Hibernation on RHEL 6 from command line?

Reply
sk September 9, 2022 - 1:24 pm

I don’t have RHEL 6 at the moment, so I can’t check it. Check it yourself and tell us how did it go.

Reply
Koko September 9, 2022 - 2:24 pm

RHEL6 doesn’t support systemd, so the systemctl command is not available there:

# systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
-bash: systemctl: command not found

Reply
Jim M December 4, 2022 - 10:39 pm

Worked great!!

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More