Both suspend-to-ram (S3) and suspend-to-disk (S4) works with a recent kernel (tested with 2.6.10).
For suspend-to-ram, the only problem to overcome was that the monitor remains powered off after the computer resumes from a suspension. This is easilly solved by installing the vbetool and acpid packages, and some scripting. I've personally set things up so that closing the lid of the computer triggers a suspend-to-ram.
The script which accomplishes this is split into two parts, the first is placed at /etc/acpi/events/lidbtn
with the following contents:
Example 1. Specifying to acpid which script to run when the lid is closed
# /etc/acpi/events/lidbtn # This is called when the user closes the lid and calls # /etc/acpi/lidbtn.sh for further processing. # Optionally you can specify the placeholder %e. It will pass # through the whole kernel event message to the program you've # specified. # We need to react on "button lid.*" and "button/lid.*" because # of kernel changes. event=button[ /]lid action=/etc/acpi/lidbtn.sh "%e"
This means that when the lid is closed, acpid executes the /etc/acpi/lidbtn.sh
script which performs the following:
Example 2. /etc/acpi/lidbtn.sh
#!/bin/sh # /etc/acpi/lidbtn.sh # Initiates a suspend-to-ram when the lid has been closed # Initial settings exec > /dev/null 2>&1 umask 0077 PATH="/sbin:/bin:/usr/sbin:/usr/bin" # Suspend echo "Going to sleep at `date`" echo "* chvt 1" /usr/bin/chvt 1 echo "* save vbestate" /usr/sbin/vbetool vbestate save > /etc/acpi/vbestate echo "* writing to /sys" echo -n "mem" > /sys/power/state echo "" # Resume echo "Back from sleep at `date`" echo "* restore vbestate" /bin/cat /etc/acpi/vbestate | /usr/sbin/vbetool vbestate restore echo "* restore clock" /sbin/hwclock --hctosys echo "* chvt 7" /usr/bin/chvt 7 echo "* done" echo "" # Done exit 0
This script changes to a text console, as required by vbetool, saves the current state of the video card to /etc/acpi/vbestate
and then continues to suspend. On resume, which happends when the computer is opened again and the "Fn" key is pressed, the script continues executing where it left off, restores the vbe state, ensures that the system clock is correct (it seems to drift when suspended) and then switches back to the console where X is usually running.
Suspend-to-disk needs a similar setup to that of suspend-to-ram, first you need to make sure that the kernel is compiled with swsusp support (swsusp2 also seems to be working fine, but I haven't spent lots of time with it as swsusp does everything I need). Then install acpid and create the file /etc/acpi/events/sleepbtn
as follows:
Example 3. Specifying to acpid which script to run when the sleep (Fn + F4) button is pressed
# /etc/acpi/events/powerbtn # This is called when the user presses the power button and calls # /etc/acpi/powerbtn.sh for further processing. # Optionally you can specify the placeholder %e. It will pass # through the whole kernel event message to the program you've # specified. # We need to react on "button power.*" and "button/power.*" because # of kernel changes. event=button[ /]sleep action=/etc/acpi/sleepbtn.sh "%e"
This means that when the sleep button Fn+F4 is pressed, acpid executes the /etc/acpi/sleepbtn.sh
script which has the following contents:
Example 4. /etc/acpi/sleepbtn.sh
#!/bin/sh # /etc/acpi/sleepbtn.sh # Initiates a suspend when the sleep button has been pressed # Initial settings exec >> /dev/null 2>&1 umask 0077 PATH="/sbin:/bin:/usr/sbin:/usr/bin" # These are troublesome modules you wish to remove prior to suspending MODULES="" # Suspend echo "Going to sleep at `date`" echo -n "* remove modules:" for i in $MODULES; do echo -n " $i" rmmod $i done echo "" echo "* sending commands" echo -n "shutdown" > /sys/power/disk echo -n "disk" > /sys/power/state # Resume echo "" echo "Back from sleep at `date`" echo -n "* inserting modules:" for i in $MODULES; do echo -n " $i" modprobe $i done echo "" echo "* done" echo "" # Done exit 0
This script unloads any troublesome modules (in my case, a binary-only WLAN driver), and then performs a suspend-to-disk. Before it all works, you must also make sure that you have a swap partition (not file), and that you pass the resume
=partition
command to your kernel (eg. resume
=/dev/hda2
) every time you boot (which you probably want to do by editing the config files for LILO or GRUB). Once this is all complete, and you've rebooted with the correct kernel parameters, pressing Fn+F4 should suspend the computer to disk.
I've added links to the four files which are needed under /etc/acpi
below so that you can download them.
Further, you might want to install the laptop-mode-tools package to have the laptop-mode mode of more recent kernels automatically enabled when you are on battery power (depending on how you configure it in /etc/laptop-mode/laptop-mode.conf
). laptop-mode can keep your harddrive spun down for as much as 10 minutes at a time, saving writes in memory, and then writing it out to disc all in one go, which should conserve power (at the risk of losing more data upon a crash). See the documentation of the package, and the comments in the config file for more details.
Jean Sébastien reported that the vbetool trick doesn't work reliably with DRI and that all problems can be avoided by using acpi_sleep
=s3_bios
as a boot parameter instead.