Thursday, October 10, 2024

How to Setting Suspend and Hibernate on Linux Server



While features like suspend and hibernate offer energy savings, some users prefer their systems to stay awake. This might be for servers, running long tasks, or simply a preference for uninterrupted operation. This guide will walk you through how to completely disable suspend and hibernate on your Linux machine, using systemd, the modern system manager.

Why Disable Sleep Modes?

Here are some reasons why you might want to permanently disable suspend and hibernate:

  • Server operations: Servers need constant uptime. Sleep modes can interrupt crucial processes.

  • Long-running tasks: Suspend or hibernate can interrupt tasks like downloads, compilations, or complex calculations.

  • User preference: Some users simply prefer their system to remain active, eliminating the potential for unwanted sleep interruptions.

Disabling Sleep Modes with systemd

Systemd is the core system and service manager in many modern Linux distributions, like Ubuntu, Debian, Fedora, Arch, and openSUSE. It controls various system functions, including sleep modes.

1. Edit the Systemd Sleep Configuration

First, open a terminal (Ctrl+Alt+T) or connect to your server. Then, use a text editor to edit the sleep.conf file:

      sudo nano /etc/systemd/sleep.conf
    

(You can substitute nano with your preferred text editor, such as gedit for Ubuntu 22.04 and earlier, gnome-text-editor for Ubuntu 24.04 and other GNOME-based systems, mousepad for XFCE, or any other editor available on your system.)

2. Modify the Sleep Rules

Within the sleep.conf file, locate the [Sleep] section. Add or modify the following lines:

AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no
    

Remove any "#" characters at the beginning of the lines if they are commented out. Make sure the values are set to no.

3. Save and Close

Press Ctrl+S to save the changes and Ctrl+X to exit the editor.

4. Verification

The changes should take effect immediately. You can try the following:

  • Power menu: The "Suspend" option should disappear from the power-off menu.

  • Command line: The systemctl suspend command should fail with a message indicating that suspend is disabled.

Disabling Sleep Modes with Custom Configuration Files

Systemd also reads configuration files from the /etc/systemd/sleep.conf.d directory. You can create a custom file there, for example, disable-sleep.conf:

      sudo nano /etc/systemd/sleep.conf.d/disable-sleep.conf
    

Add the following lines to this file:

[Sleep]
AllowSuspend=no
AllowHibernation=no
AllowHybridSleep=no
AllowSuspendThenHibernate=no
    

This custom file will override any settings from the sleep.conf file.

Re-enabling Suspend and Hibernate

To re-enable suspend and hibernate, you have two options:

  • Edit sleep.conf: Comment out the four lines in the /etc/systemd/sleep.conf file by adding a "#" at the beginning of each line.

  • Delete the custom file: Remove the file you created in the /etc/systemd/sleep.conf.d directory. For example, to remove disable-sleep.conf, use the following command:

      sudo rm /etc/systemd/sleep.conf.d/disable-sleep.conf
    

Remember: Be mindful of the implications of disabling sleep modes. If you run into issues with a server or long-running tasks, you might want to reconsider this setting.

0 comments:

Post a Comment