https://wiki.archlinux.org/api.php?action=feedcontributions&user=Yaky83&feedformat=atomArchWiki - User contributions [en]2024-03-28T13:01:58ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Power_management/Suspend_and_hibernate&diff=291738Power management/Suspend and hibernate2014-01-05T21:32:53Z<p>Yaky83: Modified "resume=UUID=4209c845..." to "resume=PARTUUID=4209c845...", according to https://www.kernel.org/doc/Documentation/kernel-parameters.txt (resume=).</p>
<hr />
<div>[[Category:Power management]]<br />
[[ja:Suspend and Hibernate]]<br />
{{Related articles start}}<br />
{{Related|Uswsusp}}<br />
{{Related|TuxOnIce}}<br />
{{Related|systemd}}<br />
{{Related|pm-utils}}<br />
{{Related|Suspending to RAM with hibernate-script}}<br />
{{Related|Suspending to Disk with hibernate-script}}<br />
{{Related articles end}}<br />
Currently there are available three methods of suspending: '''suspend to RAM''' (usually called just '''suspend'''), '''suspend to disk''' (usually known as '''hibernate'''), and '''hybrid suspend''' (sometimes aptly called '''suspend to both'''):<br />
<br />
* '''Suspend to RAM''' method cuts 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).<br />
<br />
* '''Suspend to disk''' method saves the machine's state into [[Swap|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.<br />
<br />
* '''Suspend to both''' method 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.<br />
<br />
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).<br />
<br />
== Low level interfaces ==<br />
<br />
Though these interfaces can be used directly, it is advisable to use some of [[#High level interfaces|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.<br />
<br />
=== kernel (swsusp) ===<br />
<br />
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 {{ic|/sys/power/state}} is the primary mechanism to trigger this suspend.<br />
<br />
See [https://www.kernel.org/doc/Documentation/power/states.txt kernel documentation] for details.<br />
<br />
=== uswsusp ===<br />
<br />
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.<br />
<br />
See main article [[Uswsusp]].<br />
<br />
=== tuxonice ===<br />
<br />
TuxOnIce is a fork of the kernel implementation of suspend/hibernate that provides kernel patches to improve the default implementation. It requires a custom kernel to achieve this purpose.<br />
<br />
See main article [[TuxOnIce]].<br />
<br />
== High level interfaces ==<br />
<br />
{{Note|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]].}}<br />
<br />
=== systemd ===<br />
<br />
[[systemd]] provides native commands for suspend, hibernate and a hybrid suspend, see [[Power Management#Power management with systemd]] for details.<br />
<br />
See [[Power Management#Sleep hooks]] for additional information on configuring suspend/hibernate hooks. Also see {{ic|man systemctl}}, {{ic|man systemd-sleep}}, and {{ic|man systemd.special}}.<br />
<br />
=== pm-utils ===<br />
<br />
pm-utils is a set of shell scripts that encapsulate the backend's suspend/hibernate functionality. It comes with a set of pre- and post-suspend tweaks and various hooks to customize the process.<br />
<br />
See main article [[pm-utils]].<br />
<br />
== Suspend to RAM ==<br />
<br />
Suspend to RAM should work out of the box.<br />
<br />
== Hibernation ==<br />
<br />
In order to use hibernation, you need to create swap partition or swap file. See [[Swap]] for details.<br />
<br />
=== About swap partition/file size ===<br />
<br />
Even if your swap partition is smaller than RAM, you still have a big chance of hibernating successfully. According to [https://www.kernel.org/doc/Documentation/power/interface.txt kernel documentation]:<br />
<br />
: ''{{ic|/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.''<br />
<br />
You may either decrease the value of {{ic|/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.<br />
<br />
=== Required kernel parameters ===<br />
<br />
The kernel parameter {{ic|1=resume=<swap_partition>}} has to be used. As {{ic|<swap_partition>}} you can use either kernel name of the swap partition, i.e. {{ic|/dev/sda1}}, or the [[UUID]] of the swap partition. See [[Kernel parameters]] for more examples for various bootloaders.<br />
<br />
For example, with GRUB2 you can use {{ic|GRUB_CMDLINE_LINUX}} variable:<br />
<br />
{{hc|/etc/default/grub|2=GRUB_CMDLINE_LINUX="resume=/dev/sda1"}}<br />
<br />
And if you use UUID instead:<br />
<br />
{{hc|/etc/default/grub|2=GRUB_CMDLINE_LINUX="resume=PARTUUID=4209c845-f495-4c43-8a03-5363dd433153"}}<br />
<br />
Don't forget to run {{ic|grub-mkconfig -o /boot/grub/grub.cfg}} afterwards.<br />
<br />
{{Tip|As an alternative, for GRUB2 you may try this solution from [http://wiki.debian.org/Grub#Configuring_grub_v2 debian wiki], which automatically adds your first swap partition to {{ic|1=resume=}} parameter to all found linux entries.}}<br />
<br />
==== Hibernation into swap file ====<br />
<br />
Using a swap file instead of a swap partition requires an additional kernel parameter {{ic|1=resume_offset=<Swap File Offset>}}.<br />
<br />
The value of {{ic|<Swap File Offset>}} can be obtained by running {{ic|filefrag -v <Swap File>}}, the output is in a table format and the required value is located in the first row of the {{ic|physical_offset}} column. For example:<br />
{{hc|# filefrag -v /swapfile|<nowiki><br />
Filesystem type is: ef53<br />
File size of /swapfile is 4294967296 (1048576 blocks of 4096 bytes)<br />
ext: logical_offset: physical_offset: length: expected: flags:<br />
0: 0.. 0: 38912.. 38912: 1: <br />
1: 1.. 22527: 38913.. 61439: 22527: unwritten<br />
2: 22528.. 53247: 899072.. 929791: 30720: 61440: unwritten<br />
...<br />
</nowiki>}}<br />
<br />
In the example the value of {{ic|<Swap File Offset>}} is {{ic|38912}}.<br />
<br />
{{Tip|The value of {{ic|<Swap File Offset>}} can also be obtained by running {{ic|swap-offset <Swap File>}}. The ''swap-offset'' binary is provided by package {{AUR|uswsusp-git}}.}}<br />
<br />
{{Note|<br />
* Please note that in the kernel parameter {{ic|resume}} you have to provide the device of the partition that contains the swapfile, not swapfile itself! The parameter {{ic|resume_offset}} informs the system where the swapfile starts on the resume device.<br />
* If using [[uswsusp]], then these two parameters have to be provided in {{ic|/etc/suspend.conf}} via the keys {{ic|resume device}} and {{ic|resume offset}}.<br />
}}<br />
<br />
=== Recreate initial ramdisk ===<br />
<br />
If you use an initramfs (default Arch systems do), you must add the {{ic|resume}} hook into the HOOKS in the configuration of [[mkinitcpio]]:<br />
<br />
{{hc|/etc/mkinitcpio.conf|2=<br />
# resume must be placed after block and lvm2, but before filesystems<br />
HOOKS="... block lvm2 '''resume''' filesystems ..."<br />
}}<br />
<br />
Finally, you must rebuild the initrd image for these changes to take effect:<br />
<br />
# mkinitcpio -p linux<br />
<br />
{{Note|If you use a custom kernel, then you might have to change the value of the {{ic|-p}} option.}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== ACPI_OS_NAME ===<br />
<br />
You might want to tweak your '''DSDT table''' to make it work. See [[DSDT]] article<br />
<br />
=== VAIO Users ===<br />
<br />
Add acpi_sleep=nonvs kernel flag to your loader, and you are done!<br />
<br />
=== Suspend/hibernate doesn't work ===<br />
<br />
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.</div>Yaky83