How to use systemd hybrid-sleep instead of suspend when closing the lid under gnome in linux?

9,086

Solution 1

If you edit the file /etc/systemd/logind.conf, you will see that there are spcifications for handling several events, among which is, for instance:

#HandleLidSwitch=suspend

(in my case). if you remove the #, you will activate the action. You can then change it by choosing one of the available actions, ignore, poweroff, reboot, halt, suspend, hibernate, hybrid-sleep, lock, kexec.

There are also many other equivalent keys, handling all usual events. You will then have to restart the systemd-logind daemon for the new configuration to take place.

The Arch Linux Wiki page also states:

In the current version of systemd, the Handle* options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where systemd suspends your system, then when it wakes up the other power manager suspends it again.

Warning: Currently, the power managers in the newest versions of KDE and GNOME are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the Handle options to ignore if you want your ACPI events to be handled by Xfce, acpid or other programs.

Just allow me to add one (unsolicited, admittedly) bit of advice. I do not know whether you are running Arch Linux, Fedora or Red Hat (the three major distros currently using systemd), but when in doubt, the Arch Wiki is an excellent source of info: well explained, current, correct, exhaustive. Since you are using systemd in any case, you should use it whenever you can, it is truly precious.

Solution 2

The answer by Marius didn't work for me (maybe I ran into the situation in their quote block), but the following did.

Currently, you can enable "Suspend when laptop lid is closed" in Gnome Tweaks > General (Gnome v3.32.2 at time of writing). This means that your laptop will suspend when you close the lid. So if you want to do something else, e.g., hibernate or hybrid-sleep, you can let suspend behave like one of those.

You can do this by editing /etc/systemd/sleep.conf and copying the entries from HybridSleepMode and HybridSleepState to SuspendSleepMode and SuspendSleepState as follows

[Sleep]
#AllowSuspend=yes
#AllowHibernation=yes
#AllowSuspendThenHibernate=yes
#AllowHybridSleep=yes
#SuspendMode=
#SuspendState=mem standby freeze
# Configure suspend as hybrid-sleep
SuspendMode=suspend platform shutdown
SuspendState=disk
#HibernateMode=platform shutdown
#HibernateState=disk
#HybridSleepMode=suspend platform shutdown
#HybridSleepState=disk
#HibernateDelaySec=180min

You can test if it works by running systemctl suspend and checking that it goes into hybrid-sleep instead of suspending.

Note that this implies that you can not use suspend anymore. Would you still like to use suspend, you could swap it with hybrid-sleep and make hybrid-sleep behave like suspend.

Share:
9,086

Related videos on Youtube

Arch User
Author by

Arch User

Updated on September 18, 2022

Comments

  • Arch User
    Arch User almost 2 years

    How can I make GNOME 3 use Systemd hybrid-sleep instead of suspend when closing the lid or using suspend from the menu?

  • orschiro
    orschiro almost 6 years
    Has anything changed since 2014? Is Hybrid Sleep now supported by GNOME on lid closing?