Gentoo/Suspend To Disk Using uswsusp and genkernel

Page last edited 3,789 days ago
From Alon Bar-Lev's Site
Jump to navigation Jump to search

sys-power/suspend aka uswsusp is the mainline suspend/resume solution. It contain both s2ram (suspend to RAM) and s2disk (suspend to disk aka hibernate). The problem is that Genkernel developers ignores the need to use suspend properly see bug 156445.

Preparations

Linux Kernel Configuration:
  General setup  --->
    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
  Power management and ACPI options  --->
    [*] Suspend to RAM and standby
    [*] Hibernation (aka 'suspend to disk')
    [*] ACPI (Advanced Configuration and Power Interface) Support  --->
      -*-   Button

Assuming swap partition is at /dev/sda2:

File: /etc/suspend.conf
snapshot device = /dev/snapshot
resume device = /dev/sda2
compute checksum = y
compress = y
cp /usr/share/genkernel/defaults/linuxrc /usr/share/genkernel/defaults/linuxrc.uswsusp

Modify:

File: /usr/share/genkernel/defaults/linuxrc.uswsusp
 #!/bin/sh
 
 . /etc/initrd.defaults
 . /etc/initrd.scripts
+swsusp_resume() {
+    /sbin/resume
+}
 splash() {
mkdir -p /var/lib/genkernel/overlay/etc /var/lib/genkernel/overlay/sbin
cp /etc/suspend.conf /var/lib/genkernel/overlay/etc
cp /usr/lib/suspend/resume /var/lib/genkernel/overlay/sbin
genkernel --linuxrc=/usr/share/genkernel/defaults/linuxrc.uswsusp --initramfs-overlay=/var/lib/genkernel/overlay your_standard_parameters

Basically it will use standard genkernel process with the patched linuxrc script and inject the resume utility and suspend.conf into the initramfs.

Test

  • Switch to text mode.
  • Run:
s2disk
  • Wait for computer to turn off.
  • Turn on computer.
  • After boot you should resume right after the s2disk.

Integrating splashutils

uswsusp can show nice splash activity during suspend/resume.

File: /etc/portage/package.use/suspend.conf
sys-power/suspend fbsplash

Add:

File: /etc/suspend.conf
splash = y

Recreate the initramfs overlay with the new resume and suspend.conf.

Run genkernel again now as splash enabled, and again.

Tweeks

hibernate-script

Suspending from graphical environment or within complex environment requires tweaking. There are two alternatives: sys-power/hibernate-script and sys-power/pm-utils.

I use the hibernate-script as it is simple and extensible framework.

Modify:

File: /etc/hibernate/common.conf
SaveClock yes             # this will save current system time into RTC when suspending.
FBSplash on               # this will turn on splash during hibernate-script operation.
Unmount /boot /mnt/tmp    # in case resume fails, or filesystem is accessed during boot, better to umount it cleanly before suspend.
FullSpeedCPU yes          # perform suspend as fast as we can, even if we chose to save power on batteries for example.
OnSuspend 55 sync         # execute command during suspend
GentooModulesAutoload yes # hack for Gentoo
SwitchToTextMode no       # save if you are using kernel mode switching

Now you can suspend from anywhere, try:

hibernate

acpid

emerge sys-apps/acpid
rc-update add acpid default

The following will suspend to disk when sleep button is pressed, and suspend to RAM if power button is pressed or lid is closed, add:

File: /etc/acpid/default.sh
         button)
                 case "$action" in
+                        power)
+                                /usr/sbin/hibernate
+
+                        ;;
+                        lid)
+                                grep -q closed /proc/acpi/button/lid/LID/state && \
+                                        /usr/sbin/hibernate-ram
+                        ;;
+                        sleep)
+                                /usr/sbin/hibernate
+                        ;;

Suspend to RAM

Suspend to RAM is more problematic than suspend to disk as it requires hardware support and cooperation. In most recent laptops it works correctly.

Use the hibernate script, you may need to alter:

File: ususpend-ram.conf
USuspendRamForce yes     # if hardware is unrecognized (most probably)
USuspendRamAcpiSleep 3   # if you experiencing problem in waking up, also try 1 or 2
hibernate-ram

If still not being able to wake up, try to play with other tweaks available in file.

Maintainer

Alon Bar-Lev

Authors

Originally written by: Alon Bar-Lev - 2011-11-17


Authors are people who have worked on this document and have made significant changes to its content. If you have edited this article and wish to add yourself to the authors list please read "Who are Authors".