Suspend and hibernate
This article describes how to suspend or hibernate a Gentoo system.
Make sure support for suspend and hibernation has been activated (CONFIG_SUSPEND) and (CONFIG_HIBERNATION):
Power management and ACPI options --->
[*] Suspend to RAM and standby
[*] Hibernation (aka 'suspend to disk')
One of the following packages can be used to control the in-kernel default suspend/hibernate implementation, namely, swsusp.
- desktop environments already require it if systemd is not used instead. Make sure it is configured properly.
provides the following commands that can be launched as root or from a user account. Many
- loginctl suspend
- loginctl hibernate
- loginctl hybrid-sleep
- loginctl suspend-then-hibernate
Available suspend modes
To see available suspend modes use
freeze mem disk
for swsusp, default implementation.
Those two file will list at least ACPI S2/4 power down methods on modern hardware. New hardware would also support S5 method which is a rough S4 method. ACPI S2 correspond to suspend to ram (ram method in swsusp terms and 3 in ToI terms); S4 hibernation to disk (disk in swsusp terms and 4 in ToI terms; S5 hibernation to disk (5 in ToI terms).
Swsusp users can choose between platfom, meaning ACPI, or shutdown methods which can be echo-ed to /sys/power/disk sysfs file.
Suspend to Idle
On modern hardware, traditional S3 suspend is being replaced by a set of fine-grained runtime power management capabilities for the S0 sleep state. This is referred to as S0ix by Intel and Modern Standby by Microsoft. To check available standby modes use
For S0ix to work, s2idle must be active.
Suspend to RAM
Preferred commands to suspend are:
or, if using:
See settings at /etc/elogind/logind.conf, in [Sleep] section SuspendMode must be deep if you want to disable fan noise on sleep.
For suspend (to RAM) forusers:
to hibernate (to disk).
A more "raw" method to directly communicate with the kernel is:
echo mem > /sys/power/state
This is not a configuration option! Instead it shows all available states and echo-ing one of them into it immediately executes this state.
Suspend to disk
If you are using genkernel initramfs, you may experience which makes it impossible to resume after suspend-to-disk. There is a number of ways to avoid it, from editing initramfs (e.g. as described here) to dropping genkernel completely.
Remember, swap file must contain all memory used by running processes and memory-based filesystems, like tmpfs or zram, prior to hibernating. However, unless specifically set, the hibernation image is compressed. Setting hibernation image size to half of the amount of installed RAM is a safe value in most cases. One of the cases where this does not fully apply is when the system has a high usage of zswap which means that memory may already be compressed.
For suspend to disk to operate a swap partition or swap file must exist.
The swap file should be active beforehand and should be echoed on the appropriate file before any attempt to suspend/hibernate.
echo /dev/sda1 > /sys/power/resume
A more "raw" method is to:
echo disk > /sys/power/state
Do not forget to probe:
before issuing an actual command and append the result to kernel command line argument prepended with
This will suffice to resume from a block device or swap file for ToI.
However, it's more complicated for a swap file with swsusp.
Suspend to disk and reboot afterwards
Let's say you just want to save your current session and boot into another OS, it is not necessary to do a regular hibernation including shutdown. It is sufficient to just create the hibernate image (within swap or a swap file) and reboot afterwards:
echo reboot > /sys/power/disk
echo disk > /sys/power/state
If this didn't work, please check the available options on your system (and debugging hibernation and suspend on kernel.org). When reboot is available, after echo-ing it you will see something like this (the active/chosen option is within brackets):
platform shutdown [reboot] suspend test_resume
Further information can be found within the documentation on kernel.org for /sys/power/disk resp. /sys/power/state sysfs file.
When rebooting the hibernated system again, the chosen option in /sys/power/disk is still the same (
reboot). Change it again if you want to shutdown your system next time using hibernate this way.
Neither KDE/Plasma or loginctl respect the value (
reboot) in /sys/power/disk when hibernating the system and still poweroff. At least on my system.
Suspend to disk with sys-auth/elogind
First, make sure a swap partition has been set, grub.cfg rebuilt and the initramfs (if any) updated as shown above.
Reboot the system:
Next, try running:
Suspend to disk with swap file
First find UUID of device where your swap file resides. For example /dev/sda1.
When swap file resides in a LVM volume, GRUB must be compiled with LVM support -
device-mapper USE flag. Otherwise, the system will not wake up and will be cold started.
Find offset of swap file on given partition using the swap-offset utility from :
Btrfs filesystem requires to compute the offset of the swap file a different way, see Arch Linux wiki, Hibernation into a swap file on Btrfs.
After that edit GRUB config and add required parameters to the boot string:
Rebuild GRUB config:
grub-mkconfig -o /boot/grub/grub.cfg
Reboot the system and check used kernel parameters:
It should now be possible to hibernate the system.
Classic kernel buffer comes handy:
Can not resume after suspend
Try disabling the security chip setting in BIOS/UEFI and try again. Outdated microcode can result in dysfunction of resumption from suspension, thus make sure it is updated (eg. Intel microcode with i915 drivers).
For i915 drivers if the microcode update is ineffective, try disabling CONFIG_RETPOLINE at the cost of Spectre v2 vulnerability.
Dracut configured without resume module
If using initramfs, be sure the resume module is included in the image. For example, the configuration file could contain:for the creation of the
add_dracutmodules+=" resume "
WiFi stays hard blocked
Although possibly unsafe, tricking the BIOS into believing it being "Microsoft Windows" might solve it.
Enabling this feature can cause compatibility issues for I2C/ACPI HID devices (touchpads, etc)
This can be done by adding
acpi_osi=! acpi_osi=Windows or
acpi_osi=! acpi_osi='Windows 2009'(kernel source) to the boot command line options.
For /etc/default/grub., the options can be appended to GRUB_CMDLINE_LINUX in
Migration from pm-utils to elogind
Copy any suspend/resume and hibernate/thaw hook scripts from the directory /etc/pm/sleep.d/ to /lib64/elogind/system-sleep/, and modify them to cater for the new $1 ('pre' or 'post') and $2 ('suspend', 'hibernate', or 'hybrid-sleep'). See also: Elogind#Suspend.2FHibernate_Resume.2FThaw_hook_scripts
High Battery Drain in S2idle
On many systems, it is necessary to override certain power management defaults to achieve S0ix properly. To test and troubleshoot such problems, Intel's S0ixSelftestTool is recommended.
- Power management/Guide — covers the configuration of a Gentoo system to manage power-hungry resources in a flexible-yet-automated manner.
- Custom Initramfs/Hibernation — describes how to enable hibernation with a custom initramfs.
- Suspend and hibernate on wiki.archlinux.org
- Linux kernel documentation - swsusp.txt, or the usual location of /usr/src/linux/Documentation/power/swsusp.txt
- Gentoo Forums: Suspend and Hibernate with UEFI
- How to achieve S0ix states in Linux details on how to enable and troubleshoot S0ix in Linux