< Power management

Power management/Suspend and hibernate

Currently there are three methods of suspending available:

Suspend to RAM (aka suspend, aka sleep)
The S3 sleeping state as defined by ACPI. Works by cutting off power to most parts of the machine aside from the RAM, which is required to restore the machine's state. Because of the large power savings, it is advisable for laptops to automatically enter this mode when the computer is running on batteries and the lid is closed (or the user is inactive for some time).
Suspend to disk (aka hibernate)
The S4 sleeping state as defined by ACPI. Saves the machine's state into swap space and completely powers off the machine. When the machine is powered on, the state is restored. Until then, there is zero power consumption.
Suspend to both
A hybrid of the aforementioned methods, sometimes called hybrid suspend. Saves the machine's state into swap space, but does not power off the machine. Instead, it invokes usual suspend to RAM. Therefore, if the battery is not depleted, the system can resume from RAM. If the battery is depleted, the system can be resumed from disk, which is much slower than resuming from RAM, but the machine's state has not been lost.

There are multiple low level interfaces (backends) providing basic functionality, and some high level interfaces providing tweaks to handle problematic hardware drivers/kernel modules (e.g. video card re-initialization).

Low level interfaces

Though these interfaces can be used directly, it is advisable to use the high level interfaces to suspend/hibernate. Using low level interfaces directly is significantly faster than using any high level interface, since running all the pre- and post-suspend hooks takes time, but hooks can properly set hardware clock, restore wireless etc.

Kernel (swsusp)

The most straightforward approach is to directly inform the in-kernel software suspend code (swsusp) to enter a suspended state; the exact method and state depends on the level of hardware support. On modern kernels, writing appropriate strings to /sys/power/state is the primary mechanism to trigger this suspend.

See kernel documentation for details.

Userspace (uswsusp)

The uswsusp ('Userspace Software Suspend') is a wrapper around the kernel's suspend-to-RAM mechanism, which performs some graphics adapter manipulations from userspace before suspending and after resuming.

See main article Uswsusp.

High level interfaces

The end goal of these packages is to provide binaries/scripts that can be invoked to perform suspend/hibernate. Actually hooking them up to power buttons or menu clicks or laptop lid events is usually left to other tools. To automatically suspend/hibernate on certain power events, such as laptop lid close or battery depletion percentage, you may want to look into running Acpid.

systemd

systemd provides native commands for suspend, hibernate and a hybrid suspend, see Power management#Power management with systemd for details. This is the default interface used in Arch Linux.

See Power management#Sleep hooks for additional information on configuring suspend/hibernate hooks. Also see systemctl(1), systemd-sleep(8), and systemd.special(7).

Hibernation

In order to use hibernation, you need to create a swap partition or file. You will need to point the kernel to your swap using the kernel parameter, which is configured via the boot loader. You will also need to configure the initramfs. This tells the kernel to attempt resuming from the specified swap in early userspace. These three steps are described in detail below.

About swap partition/file size

Even if your swap partition is smaller than RAM, you still have a big chance of hibernating successfully. See "image_size" in the kernel documentation for information on the sysfs(5) pseudo-file.

You may either decrease the value of to make the suspend image as small as possible (for small swap partitions), or increase it to possibly speed up the hibernation process. For systems with a large amount of RAM, smaller values may drastically increase the speed of resuming a hibernating system. systemd#systemd-tmpfiles - temporary files can be used to make this change persistent:

The suspend image cannot span multiple swap partitions and/or swap files. It must fully fit in one swap partition or one swap file.

Configure the initramfs

  • When an initramfs with the hook is used, which is the default, the hook is required in . Whether by label or by UUID, the swap partition is referred to with a udev device node, so the hook must go after the hook. This example was made starting from the default hook configuration:
HOOKS=(base udev autodetect keyboard modconf block filesystems '''resume''' fsck)
Remember to regenerate the initramfs for these changes to take effect.
  • When an initramfs with the hook is used, a resume mechanism is already provided, and no further hooks need to be added.

Required kernel parameters

The kernel parameter must be used. Any of the persistent block device naming methods can be used as swap_device. For example:

  • -- if swap is on a LVM logical volume (UUID and Label should also work)

The kernel parameters will only take effect after rebooting. To be able to hibernate right away, obtain the volume's major and minor device numbers from lsblk and echo them in format to . If using a swap file, additionally echo the resume offset to .

For example, if the swap device is :

# echo 8:3 > /sys/power/resume

Or when hibernating to a swap file, if the swap file is on volume and has the offset 38912:

# echo 8:2 > /sys/power/resume
# echo 38912 > /sys/power/resume_offset

Hibernation into swap file

Using a swap file requires also setting the resume=UUID=swap_device_uuid and additionally a kernel parameters. See the kernel documentation.

swap_device is the volume where the swap file resides and it follows the same format as for the root parameter. The value of can be obtained by running , the output is in a table format and the required value is located in the first row of the column. For example:

In the example the value of is the first 38912 with the two periods.

Tip: You might want to decrease the swappiness for your swap file if the only purpose is to be able to hibernate and not expand RAM.

Hibernation into swap file on Btrfs

The resume_offset number can be computed using the tool btrfs_map_physical.c. Do not try to use the filefrag tool, on Btrfs the "physical" offset you get from filefrag is not the real physical offset on disk; there is a virtual disk address space in order to support multiple devices.

Download or copy the tool btrfs_map_physical.c into a file named , then compile it,

$ gcc -O2 -o btrfs_map_physical btrfs_map_physical.c

and run it. An example output is shown below.

Note the the first physical offset returned by this tool. In this example, we use 4009762816. Also note the pagesize that can be found with .

To compute the value, divide the physical offset by the pagesize. In this example, it is .

Hibernation into a thinly-provisioned LVM volume

Hibernation into a thinly-provisioned LVM volume is possible, but you have to make sure that the volume is fully allocated. Otherwise resuming from it will fail, see .

You can fully allocate the LVM volume by simply filling it with zeros. E.g.:

# dd if=/dev/zero of=/dev/vg0/swap bs=1M status=progress

To verify the volume is fully allocated, you can use:

A fully allocated volume will show up as having 100% data usage.

Intel Rapid Start Technology (IRST)

Intel Rapid Start Technology is a firmware solution to hibernation that allows hibernating from sleep after a predefined interval or battery state. This should be faster and more reliable than regular hibernation as it is done by firmware instead of at the operating system level. Generally it must enabled in the firmware and the firmware also provides support for setting the duration after suspend/battery event triggering hibernation, however some devices despite supporting IRST in the firmware, only allow it to be configured via Intel's Windows drivers. In such cases the intel-rst kernel module described below should be able to configure the events under Linux.

With Intel Rapid Start Technology (IRST) enabled, resuming from a deep sleep takes "a few seconds longer than resuming from S3 but is far faster than resuming from hibernation".

Many Intel-based systems have firmware support for IRST but require a special partition on an SSD (rather than an HDD). OEM deployments of Windows may already have a preexisting IRST partition which can be retained during the Arch Linux installation process (rather than wiping and re-partitioning the whole SSD). It should show up as an unformatted partition equal in size to the system's RAM.

Warning: The Intel Rapid Start partition is not encrypted; "Intel recommends disabling Intel Rapid Start Technology if you are using software-based disk encryption".

However, if you intend to wipe and re-partition the whole drive (or have already done so), then the IRST partition must be recreated if you also plan on using the technology. This can be done by creating an empty partition equal in size to the system's RAM and by setting its partition type to GUID for a GPT partition or ID for an MBR partition. You may also need to enable support for IRST in your system's firmware settings.

The duration of the IRST hibernation process (i.e., copying the "entire contents of RAM to a special partition") is dependent on the system's RAM size and SSD speed and can thus take 20–60 seconds. Some systems may indicate the process's completion with an LED indicator, e.g., when it stops blinking.

Configuring IRST hibernation events in Linux requires or if set to module, the intel-rst module loaded. Once loaded via modprobe intel_rst, it should create files wakeup_events and wakeup_time under for e.g. that can be used for further configuration. This module is tersely documented, see the source drivers/platform/x86/intel/rst.c for more details.

See also the general Q&A and user guides for Intel Rapid Start Technology.

Troubleshooting

ACPI_OS_NAME

You might want to tweak your DSDT table to make it work. See DSDT.

Suspend/hibernate does not work, or does not work consistently

There have been many reports about the screen going black without easily viewable errors or the ability to do anything when going into and coming back from suspend and/or hibernate. These problems have been seen on both laptops and desktops. This is not an official solution, but switching to an older kernel, especially the LTS-kernel, will probably fix this.

Also problem may arise when using hardware watchdog timer (disabled by default, see in ). Bugged watchdog timer may reset the computer before the system finished creating the hibernation image.

Sometimes the screen goes black due to device initialization from within the initramfs. Removing any modules you might have in Mkinitcpio#MODULES and rebuilding the initramfs, can possibly solve this issue, specially graphics drivers for early KMS. Initializing such devices before resuming can cause inconsistencies that prevents the system resuming from hibernation. This does not affect resuming from RAM. Also, check the blog article best practices to debug suspend issues.

Moving from the radeon video driver to the newer AMDGPU driver could also help to make the hibernation and awakening process successful.

For Intel graphics drivers, enabling early KMS may help to solve the blank screen issue. Refer to Kernel mode setting#Early KMS start for details.

After upgrading to kernel 4.15.3, resume may fail with a static (non-blinking) cursor on a black screen. Blacklisting the module might help.

Laptops with Intel CPU that load module for touchpad, may face kernel panic on resume (blinking caps lock) . The module needs to be added to initramfs as:

/etc/mkinitcpio.conf
MODULES=(... intel_lpss_pci ...)

Then regenerate the initramfs.

Wake-on-LAN

If Wake-on-LAN is active, the network interface card will consume power even if the computer is hibernated.

Instantaneous wakeups from suspend

See Wakeup triggers#Instantaneous wakeups from suspend.

System does not power off when hibernating

When you hibernate your system, the system should power off (after saving the state on the disk). Sometimes, you might see the power LED is still glowing. If that happens, it might be instructive to set the to in :

With the above configuration, if everything else is set up correctly, on invocation of a the machine will shutdown saving state to disk as it does so.

Operating system not found (or wrong OS booting) when booting after hibernation

This can happen when the boot disk is an external disk, and seems to be caused by a BIOS/firmware limitation. The BIOS/firmware tries to boot from an internal disk, while hibernation was done from an OS on an external (or other) disk.

Set as shown in #System does not power off when hibernating to solve the problem permanently. If you have already locked yourself out, you can try rebooting your system 4 times (wait for the error to appear each time), which on some BIOS'es forces a normal boot procedure.

gollark: Fiiiiine. `bin(a).replace("0b","")` should probably just be `bin(a)[2:]`. `eval` in the same line should probbaly be `int`.
gollark: I actually have some ideas for making anima's mildly shorter but that might not be the best idea?
gollark: Oh dear.
gollark: It's a bad spec.
gollark: I'm making a brotlipython esolangs page.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.