Compile FC3 for Software suspend to disk
Site Navigation:
 
 

Compile FC3 for Software suspend to disk 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!

1. Prepare the kernel sources for a compile

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

2. Download and apply patches

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.

3. Configure swsusp

After compiling the kernel with swsusp following steps must be completed:

  • setting up the bootloader
  • installing the hibernate script
  • configuring hibernate
  • setting up the boot-script
  • testing the suspend/resume process
  • setting up for daily usage

3.1. Setting up the bootloader

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.

It is recommended to keep a boot-option for your kernel without resume in case of problems. For that copy the boot-config above and just add noresume2 to it.

3.2. Installing the hibernate script

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/.

3.3. Configuring 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.

3.4. Setting up the boot script 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.

  • log-in as root
  • go to /boot and create a directory myinitrd
  • cd myinitrd and extract the initrd-image: gzip -dc < /boot/initrd-<version>.img | cpio -i
  • edit init by adding echo > /proc/software_suspend/do_resume near the top of the script (after mounting /proc but before mounting any drives)
  • compress the image: find . | cpio -o -c |gzip -9 > /boot/initrd-<version>.img

3.5. Testing the suspend/resume process

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.

4. Troubleshooting

Following tips helped me out after a failed suspend/resume:

  • You can temporarily add noresume2 to the boot-command in Grub's boot-menu by pressing a for editing the boot-command
  • After an unsuccessfull suspend my swap-disk went full (the free space can be displayed with free). At that point reformatting the swap-partition (/sbin/mskswap /dev/hda6) and reinitializing it (swapon /dev/hda6) helped
  • I got a scrambled X when resuming using an ATI Readon Mobility 7500. The problem was solved by commenting out 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)
  • Network was not available after resume: Adding DownInterfaces eth0 and UpInterfaces auto in /etc/hibernate/hibernate.conf got that solved
You can find more about troubleshooting and setting up swsusp in the FAQ and HOWTO here.

5. Setting up for daily usage

5.1. Grating rights for suspending

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

5.2. Suspending on ACPI-event lid-close

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

5.3. Configurations that work fine for me

I have successfully installed and configured following configurations on a Fujitsu Siemens Lifebook E-Series running Fedora Core 3 (with a vanilla kernel):

  • Kernel 2.6.9 with software-suspend-2.1.5-for-2.6.9.tar.bz2 (stable)
  • Kernel 2.6.10 with software-suspend-2.1.5.15-for-2.6.10.tar.bz2 (development)

The Kernel was applied only this patch and the configuration is standard except NTFS read and write support.

5.5. Configurations that don't work for me

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).

6. Pre-compiled kernels with swsusp support

I put together a few links to pre-compiled kernels for those who have problems compiling their own: