Suspend and hibernate
Installation[edit | edit source]
Kernel[edit | edit source]
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')
Software[edit | edit source]
One of the following packages can be used to control the in-kernel default suspend/hibernate implementation, namely, swsusp.
- sys-auth/elogind providing loginctl suspend, loginctl hibernate and loginctl hybrid-sleep, where loginctl can be launched as root or from a user account. Many desktop environments already require it if systemd is not used instead. Make sure it is configured properly.
- sys-power/suspend providing s2ram, s2disk and s2both
- sys-power/hibernate-script
Available suspend modes[edit | edit source]
To see available suspend modes use
root #
cat /sys/power/state
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 RAM[edit | edit source]
Preferred commands to suspend are:
root #
s2ram
or, if using elogind
root #
loginctl suspend
For suspend (to ram) for hibernate-script users:
root #
hibernate-ram
or
root #
hibernate
to hibernate (to disk.)
A more raw method is to
root #
echo mem > /sys/power/state
Suspend to disk[edit | edit source]
If you are using genkernel initramfs, you may experience bug #156445 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.
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.
root #
echo /dev/sda1 > /sys/power/resume
A more raw method is to:
root #
echo disk > /sys/power/state
Do not forget to probe:
root #
cat /sys/power/tuxonice/swap/headerlocations
before issuing an actual command and append the result to kernel command line argument prepended with `resume='. This will suffice to resume from a block device or swap file for ToI. However, it's more complicated for a swapfile with swsusp.
Suspend to disk with sys-auth/elogind[edit | edit source]
First, make sure a swap partition has been set, grub.cfg rebuilt and the initramfs (if any) updated as shown above.
Reboot the system:
root #
loginctl reboot
Next, try
root #
loginctl hibernate
Suspend to disk with swapfile[edit | edit source]
You can use suspend to disk with a swapfile. When you have a functional swapfile you need to configure kernel parameters (via GRUB, etc.).
First find UUID of device where your swapfile resides. For example: /dev/sda1.
If swapfile resides in a LVM volume, GRUB must be compiled with LVM support. Otherwise, the system will not wake up and will be cold started.
root #
blkid /dev/sda1
Find offset of swapfile on given partition using swap-offset
utility from sys-power/suspend:
root #
swap-offset /path/to/swapfile
After that edit GRUB config and add required parameters to boot string:
/etc/defaults/grub
GRUB defaultsGRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=<UUID_of_partition> resume_offset=<offset_of_swapfile>"
Rebuild GRUB config:
root #
grub-mkconfig -o /boot/grub/grub.cfg
Reboot the system and check used kernel parameters:
user $
cat /proc/cmdline
It should now be possible to hibernate the system.
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.
Troubleshooting[edit | edit source]
Classic kernel buffer comes handy:
user $
dmesg
Can not resume after suspend[edit | edit source]
In case resuming from suspend does not work, disable the security chip setting in BIOS/UEFI and try again.
Wifi stays hard blocked[edit | edit source]
Although possibly unsafe, tricking the bios into believing it being "Windows" might solve it.
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 sys-boot/grub, it can be appended to GRUB_CMDLINE_LINUX in /etc/default/grub.
Migration from pm-utils to elogind[edit | edit source]
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#Hook_scripts_to_be_run_when_suspending.2Fhibernating_and.2For_when_resuming.2Fthawing
See also[edit | edit source]
- 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.
External resources[edit | edit source]
- Suspend and hibernate on wiki.archlinux.org
- TuxOnIce
- tuxonice-sources has been last-rited, see bug #627924.
- Linux kernel documentation - swsusp.txt, or the usual location of /usr/src/linux/Documentation/power/swsusp.txt
- Gentoo Forums: Suspend and Hibernate with UEFI
References[edit | edit source]