swsusp
Author: Sven Knispel
Updated: [udate]
Software suspend to disk (swsusp) is a tool for suspending your systems' state to disk.
swsusp is not part of the official kernel but exists as a patch, so installing swsusp means recompiling the kernel.
Don't panic, this exercise is easier than you think!
The kernel-sources as distributed by Fedora are not appropriate for this exercise as they are different from the official kernel sources. Therefore (ans also for many other reasons) it is recommended to compile the kernel from the official sources.
The process of recompiling an official kernel is described here
Once the kernel sources are ready download the swsusp patch for your kernel (e.g. from Download swsusp for your kernel from http://softwaresuspend.berlios.de/ and decompress it to your tmp:
bzip2 -cd software-suspend-2.1.5.15-for-2.6.10.tar.bz2 | tar xvf - -C ~/tmp
Then go to your kernel source directory and apply the patch:
cd /usr/src/linux-2.6.10/
sudo ~/tmp/software-suspend-2.1.5.15-for-2.6.10/apply
The process should finish with All Happy.
From here first finish kernel compile process.
swsusp
After compiling the kernel with swsusp following steps must be completed:
The bootloader must be informed that there is a resume-partition; this happens by adding resume2 to the boot-configuration (in /boot/grub/grub.conf):
kernel /boot/vmlinuz-2.6.10 ro root=LABEL/1 rhgb quitet resume2=swap:/dev/hdx
initrd /boot/initrd-2.6.10.img
Where hdx is the name of your swap-partition.
noresume2 to it.
Download the hibernate script from http://softwaresuspend.berlios.de/download.html.
Decompress and install the script:
cd ~/tmp/
tar xzf hibernate-script-x.xx.tar.gz
cd /tmp/hibernate-script-x.xx/
./install.sh
The script is located in /usr/local/sbin/hibernate and the configuration in /etc/hibernate/.
Check /etc/hibernate/hibernate.conf for settings. At least the entry SuspendDevice must be set to the same value as the swap-partition in §3.1.
initrd
In order for the boot-process to check if there is a suspended system state to be picked up it is required to modify the init-script to add that instruction to be executed during thie init-process.
Here is how you can do it afterward (after the kernel-compile).
This consists in uncompressing the initrd image and modifyining the init script.
myinitrd
cd myinitrd and extract the initrd-image: gzip -dc < /boot/initrd-<version>.img | cpio -i
init by adding echo > /proc/software_suspend/do_resume near the top of the script (after mounting /proc but before mounting any drives)
For testing swsusp you should start in text-mode.
First test in text-mode (init 3), log-on as root and type:
/usr/local/sbin/hibernate
If this work you are ready to hibernate from X-Windows.
Following tips helped me out after a failed suspend/resume:
noresume2 to the boot-command in Grub's boot-menu by pressing a for editing the boot-command
free). At that point reformatting the swap-partition (/sbin/mskswap /dev/hda6) and reinitializing it (swapon /dev/hda6) helped
load "dri" from the Section "Module" in /etc/X11/xorg.conf (Hint: a recent update reinserted load "dri" in my xorg.conf; commenting it out again solved the problem)
DownInterfaces eth0 and UpInterfaces auto in /etc/hibernate/hibernate.conf got that solved
swsusp in the FAQ and HOWTO here.
One everything is working fine you certainly want to allow anyone to use /usr/local/sbin/hibernate.
I have created a group hibernate, added my local users to it and changed the rights on the script:
chgrp hibernate /usr/local/sbin/hibernate
chmod 750 /usr/local/sbin/hibernate
This assumes that you have ACPI enabled.
ACPI allows to run scripts in response to certain events; in this case we are interested in running /usr/local/sbin/hibernate in response to the event lid.
As the lid event carries no information about whether the lid was opened or closed we must write a little script lid.sh and save it to /etc/acpi/actions and call /usr/local/sbin/hibernate only when the lid is closed:
#!/bin/sh
# lid.sh
die() {
echo "Unable to determine state of lid."
exit 1
}
STATE_FILE=/proc/acpi/button/lid/LID/state
[ -f $STATE_FILE ] || die;
STATE=$(awk '{ print $2 }' < $STATE_FILE)
case "$STATE" in
"closed")
echo "Lid is closed."
/usr/local/sbin/hibernate
;;
"open")
echo "Lid is open."
;;
*)
die
;;
esac
After that we edit /etc/acpi/events/sample.conf and add the action on the event /button/lid:
event=button/lid
action=/etc/acpi/actions/lid.sh
An finally restart ACPI: /sbin/service acpid restart
For troubleshooting you will find the trace from lid.sh in /var/log/acpid
I have successfully installed and configured following configurations on a Fujitsu Siemens Lifebook E-Series running Fedora Core 3 (with a vanilla kernel):
software-suspend-2.1.5-for-2.6.9.tar.bz2 (stable)
software-suspend-2.1.5.15-for-2.6.10.tar.bz2 (development)
I was not able to get software-suspend-2.1.5.12-for-2.6.10 running (kept complaining about some issues with XFree on resume). software-suspend-2.1.5.12-for-2.6.10 solved that (see also Troubleshooting).
I put together a few links to pre-compiled kernels for those who have problems compiling their own: