Home FAQ [Linux Tips] Disable Suspend And Hibernation
How To Disable Suspend And Hibernation In Linux

[Linux Tips] Disable Suspend And Hibernation

By sk
5302 Views

I've learned many simple and quick Linux tips and tricks over the past few years and decided to share one at a time via our blog. Today we are going to learn how to disable suspend and hibernation in Linux. Before we get into the topic, let us see the brief introduction to suspend and hibernate modes in Computer.

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 will not 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.

How To 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

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 file /etc/systemd/logind.conf:

$ 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

Suggested read:


Hope this helps.

Featured Image by OpenClipart-Vectors from Pixabay.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

4 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

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. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More