Difference between revisions of "Power management/Suspend and hibernate"

From ArchWiki
Jump to: navigation, search
m (About swap partition/file size: make it a subsection)
m ('work in progress' warning)
Line 11: Line 11:
 
{{Article summary wiki|Suspending to Disk with hibernate-script}}
 
{{Article summary wiki|Suspending to Disk with hibernate-script}}
 
{{Article summary end}}
 
{{Article summary end}}
{{Stub|see [[Suspend to RAM]] for better introduction; for details see separate pages (e.g. [[uswsusp]] or [[pm-utils]])}}
+
{{Stub|This page is work in progress, see [[User:Lahwaacz#Power management]]. Only [[#Hibernation]] is relevant.}}
 
Manually suspending the operating system, either to memory (standby) or to disk (hibernate) sometimes provides the most efficient way to optimize battery life, depending on the usage pattern of the laptop. While there is relatively straightforward support in the linux kernel to support these operations, typically some adjustments have to be made before initiating these operations (typically due to problematic drivers, modules or hardware). The following tools provide wrappers around the kernel interfaces to suspend/resume
 
Manually suspending the operating system, either to memory (standby) or to disk (hibernate) sometimes provides the most efficient way to optimize battery life, depending on the usage pattern of the laptop. While there is relatively straightforward support in the linux kernel to support these operations, typically some adjustments have to be made before initiating these operations (typically due to problematic drivers, modules or hardware). The following tools provide wrappers around the kernel interfaces to suspend/resume
  

Revision as of 18:09, 27 July 2013

Summary help replacing me
Describes suspend(sleep-to-ram), hibernate(sleep-to-disk)
Related articles
Suspend to RAM
Systemd
pm-utils
Uswsusp
Tuxonice
Suspending to RAM with hibernate-script
Suspending to Disk with hibernate-script

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: This page is work in progress, see User:Lahwaacz#Power management. Only #Hibernation is relevant. (Discuss in Talk:Power management/Suspend and hibernate#)

Manually suspending the operating system, either to memory (standby) or to disk (hibernate) sometimes provides the most efficient way to optimize battery life, depending on the usage pattern of the laptop. While there is relatively straightforward support in the linux kernel to support these operations, typically some adjustments have to be made before initiating these operations (typically due to problematic drivers, modules or hardware). The following tools provide wrappers around the kernel interfaces to suspend/resume

  • Wrappers: Systemd, pm-utils
  • Backend: kernel, uswsusp, tuxonice

Backend

Kernel

Suspend

Suspension works out-of-box.

Hibernation

In order to use hibernation, you need to create swap partition or swap file. See Swap for details.

About swap partition/file size

Even if your swap partition is smaller than RAM, you still have a big chance of hibernating successfully. According to kernel documentation:

/sys/power/image_size controls the size of the image created by the suspend-to-disk mechanism. It can be written a string representing a non-negative integer that will be used as an upper limit of the image size, in bytes. The suspend-to-disk mechanism will do its best to ensure the image size will not exceed that number. However, if this turns out to be impossible, it will try to suspend anyway using the smallest image possible. In particular, if "0" is written to this file, the suspend image will be as small as possible. Reading from this file will display the current image size limit, which is set to 2/5 of available RAM by default.

You may either decrease the value of /sys/power/image_size to make the suspend image as small as possible (for small swap partitions), or increase it to possibly speed up the hibernation process.

Required kernel parameters

The kernel parameter resume=<swap_partition> has to be used. As <swap_partition> you can use either kernel name of the swap partition, i.e. /dev/sda1, or the UUID of the swap partition. See Kernel parameters for more examples for various bootloaders.

For example, with GRUB2 you can use GRUB_CMDLINE_LINUX variable:

/etc/default/grub
GRUB_CMDLINE_LINUX="resume=/dev/sda1"

And if you use UUID instead:

/etc/default/grub
GRUB_CMDLINE_LINUX="resume=UUID=4209c845-f495-4c43-8a03-5363dd433153"

Don't forget to run grub-mkconfig -o /boot/grub/grub.cfg afterwards.

Tip: As an alternative, for GRUB2 you may try this solution from debian wiki, which automatically adds your first swap partition to resume= parameter to all found linux entries.
Hibernation into swap file

Using a swap file instead of a swap partition requires an additional kernel parameter resume_offset=<Swap File Offset>.

The value of <Swap File Offset> can be obtained from the output of filefrag -v or swap-offset <Resume Device>; the output is in a table format; the required value is located in the physical column from the first row. Eg:

# filefrag -v /swapfile
Filesystem type is: ef53
File size of /swapfile is 4290772992 (1047552 blocks, blocksize 4096)
ext logical  physical  expected  length flags
  0       0     7546880                6144 
  1    6144  7557120  7553023   2048 
  2    8192  7567360  7559167   2048 
...

In the example <Swap File Offset> is 7546880.

Note:
  • Please note that in the kernel parameter resume you have to provide the device of the partition that contains the swapfile, not swapfile itself! The parameter resume_offset informs the system where the swapfile starts on the resume device.
  • If using uswsusp, then these two parameters have to be provided in /etc/suspend.conf via the keys resume device and resume offset.

Recreate initial ramdisk

If you use an initramfs (default Arch systems do), you must add the resume hook into the HOOKS in the configuration of mkinitcpio:

/etc/mkinitcpio.conf
# resume must be placed after block and lvm2, but before filesystems
HOOKS="... block lvm2 resume filesystems ..."

Finally, you must rebuild the initrd image for these changes to take effect:

# mkinitcpio -p linux
Note: If you use a custom kernel, then you might have to change the value of the -p option.

Uswsusp

uswsusp (userspace software suspend) is a set of user space tools used for hibernation (suspend-to-disk) and suspend (suspend-to-RAM or standby) on Linux systems.

Consulte Uswsusp.

TuxOnIce

TuxOnIce , an advanced suspend/hibernate framework which supports suspending to a swap-disk or a regular file with fast LZO-compression.

Consulte TuxOnIce.

Wrappers

systemd

$ systemctl suspend
$ systemctl hibernate
$ systemctl hybrid-sleep

See Systemd#ACPI_power_management.

pm-utils

# pm-suspend
# pm-hibernate
# pm-suspend-hybrid

See pm-utils.