Step-by-Step to Suspend2 enabled Kernel using initramfs on Ubuntu 5.10/6.06/6.10 or Debian Sid
Authors: Robert Brunhuber (suspend2@rbrunhuber.de), Karl Hegbloom (karlheg@laclinux.com)
Some updates for Ubuntu Edgy by Paolo 'Blaisorblade' Giarrusso (blaisorblade (at) yahoo (dot) it)
To avoid compiling your own kernels, follow the instructions on http://dagobah.ucc.asn.au/dapper-kernels/ - Thanks to BernardBlackham. It provides integration with the USplash, too. -- Rohan Dhruva.
You should not 'sudo su - root' in order to perform the following (to protect your system against potential mistakes in Makefiles) but you will need sudo permissions. Again, you do not need to be root for any operations not prefixed below with the sudo command. Read 'man fakeroot' to find out what it does in the make-kpkg command line given below.
To have write access to /usr/src, you need to be in the src group: 'sudo adduser mylogin src'. Log out (of Gnome) and back in again to reinitialize the supplementary group list active in your login session.
Get Suspend2 Kernel patches (eg: suspend2-2.2.7-for-2.6.17.tar.bz2) and extract the tar (replace SUSPEND2VERSION from now on with the actual version string from the tar file name):
cd /usr/src tar xvjf suspend2-SUSPEND2VERSION.tar.bz2
Get Suspend2 hibernate script, suspend2ui_text, and tools required for kernel building. (Hint: Make sure that you have the Universe apt respository enabled first.):
sudo apt-get install hibernate build-essential fakeroot kernel-package libncurses5-dev
If you are using a very recent copy of Suspend2, you may need a newer version of hibernate than the one in Ubuntu Universe. Get that from http://www.suspend2.net/downloads/. The newer hibernate should be backward compatible with older versions of Suspend2.
The userui (see: UserUIHowto) is in the Ubuntu repository for edgy at least, as suspend2-userui. It includes both the text and the usplash interfaces. Note that they get installed in /usr/sbin instead of /usr/local/sbin, so correct paths below.
It was not in the Ubuntu repository in older releases, so in case you cannot find it, grab it from the Suspend2 website download area. Install the suspend2ui_text into /usr/local/sbin:
sudo cp suspend2ui_text /usr/local/sbin sudo chown root:root /usr/local/sbin/suspend2ui_text
If you want to get a ubuntu-like userui, grab the recent userui version (>= 0.6.4):
sudo apt-get install libpng12-dev libmng-dev tar xvfz suspend2-userui-VERSION.tar.gz cd suspend2-userui-VERSION/ sudo make install
Edit your hibernate.conf:ProcSetting userui_program /usr/local/sbin/suspend2ui_usplash
Get matching kernel source from kernel.org and save it to /usr/src/
Extract kernel source and change directory into it. (Replace KVER from now on with the actual kernel version string from the directory name.)
cd /usr/src tar xjvf linux-KVER cd linux-KVER
- Patch the kernel with suspend2 patches:
../suspend2-SUSPEND2VERSION/apply
- Copy config from current kernel
cp /boot/config-`uname -r` .config
Build a linux-image package using make-kpkg:
fakeroot make-kpkg clean fakeroot make-kpkg --stem linux --append-to-version -suspend2-1 --config menuconfig \ --initrd kernel_image [modules_image] [kernel_headers]
Note: The instructions in sqare brackets are optional! If you don't need them or don't no what they mean just leave them out! This would result in the following instruction (which should be okay for everyday use):
fakeroot make-kpkg clean fakeroot make-kpkg --stem linux --append-to-version -suspend2-1 --config menuconfig \ --initrd kernel_image
If you need to rebuild and are running the above new version, increment the suspend2-1 to create an image that can be installed side-by-side with your current version.
Now you must add custom scripts to the initramfs, through Ubuntu initramfs tools. Custom scripts must be placed, depending on your Ubuntu version, under /etc/initramfs-tools/ (verified on Edgy) or /etc/mkinitramfs (older versions). Correct paths below accordingly - the script content is correct in any case, they cater to various possible setups. Create two shell scripts for the initramfs, editing with 'sudo gedit SCRIPT'.
/etc/mkinitramfs/hooks/suspend2 with the contents:
#!/bin/sh PREREQ="" prereqs() { echo "$PREREQ" } case $1 in # get pre-requisites prereqs) prereqs exit 0 ;; esac . /usr/share/initramfs-tools/hook-functions if [ -x /usr/local/sbin/suspend2ui_text ]; then mkdir --parents ${DESTDIR}/usr/local/sbin 2>/dev/null || true copy_exec /usr/local/sbin/suspend2ui_text usr/local/sbin elif [ -x /usr/sbin/suspend2ui_text ]; then mkdir --parents ${DESTDIR}/usr/sbin 2>/dev/null || true copy_exec /usr/sbin/suspend2ui_text usr/sbin elif [ -x /usr/local/sbin/suspend2ui_usplash ]; then mkdir --parents ${DESTDIR}/usr/local/sbin 2>/dev/null || true copy_exec /usr/local/sbin/suspend2ui_usplash usr/local/sbin elif [ -x /usr/sbin/suspend2ui_usplash ]; then mkdir --parents ${DESTDIR}/usr/sbin 2>/dev/null || true copy_exec /usr/sbin/suspend2ui_usplash usr/sbin fi/etc/mkinitramfs/scripts/local-premount/suspend2 with the contents:
#!/bin/sh PREREQ="" prereqs() { echo "$PREREQ" } case $1 in # get pre-requisites prereqs) prereqs exit 0 ;; esac if [ -d /proc/suspend2 ]; then echo > /proc/suspend2/do_resume elif [ -d /sys/power/suspend2 ]; then echo > /sys/power/suspend2/do_resume elif [ -d /proc/software_suspend ]; then echo > /proc/software_suspend/do_resume fi- Make sure these files have execute permissions or it will not work:
sudo chmod +x /etc/mkinitramfs/hooks/suspend2 sudo chmod +x /etc/mkinitramfs/scripts/local-premount/suspend2
- Find out your swap partition:
cat /proc/swaps
Edit /boot/grub/menu.list, and add ' resume2=swap:/dev/YOURSWAP' to the line that begins with '# nonaltoptions=' or with '# defoptions =' (there will be one of them), where YOURSWAP is the value we found in the last step. Also add ' noresume2' to the line that begins with '# altoptions=', so that recovery mode boots won't attempt to resume. Eg (LVM):
# nonaltoptions=splash resume2=swap:/dev/mapper/Ubuntu-swap_1
Install the linux-image package that was just created. The initramfs will be automatically created by the package post-install script, and the /boot/grub/menu.lst will automatically be updated:
sudo dpkg -i ../linux-image-KVER-suspend2-1_10.00.Custom_i386.deb
If you need to recreate the initramfs, perhaps to update the scripts on it in case there was a mistake in one of them, you can do it like this: sudo mkinitramfs -o /boot/initrd.img-KVER-suspend2-1 KVER-suspend2-1
You can regenerate the /boot/grub/menu.lst by running: sudo update-grub
Edit /etc/default/acpi-support, and add the lines from the script fragment below that begin with HIBERNATE, plus ensure that at least the variable ACPI_HIBERNATE=true is set. If your machine suspends to RAM using hibernate -F /etc/hibernate/ram.conf, then also enable the ACPI_SLEEP=true line. These are what puts the suspend and hibernate options on the Gnome Logout dialog. The new variables are for the modifications we'll make in the next step.
# ... # Uncomment the next line to enable ACPI suspend to RAM #ACPI_SLEEP=true HIBERNATE_SCRIPT=true HIBERNATE_ARGS= HIBERNATE_SCRIPT_RAM=false HIBERNATE_RAM_ARGS="-F /etc/hibernate/ram.conf" # Comment the next line to disable suspend to disk ACPI_HIBERNATE=true # ...
Edit /etc/acpi/hibernate.sh, and right below the line that reads in the "power_funcs", add:
if [ x$HIBERNATE_SCRIPT = xtrue ] && [ -x /usr/sbin/hibernate ]; then /usr/sbin/hibernate $HIBERNATE_ARGS ; exit $?; fi
Edit /etc/acpi/sleep.sh, and right below the line that calls "DeviceConfig", add:
if [ x$HIBERNATE_SCRIPT_RAM = xtrue ] && [ -x /usr/sbin/hibernate ]; then /usr/sbin/hibernate $HIBERNATE_RAM_ARGS ; exit $?; fi
Adapt /etc/hibernate/hibernate.conf and /etc/hibernate/ram.conf to your needs.
If you are using NetworkManager, you can have it go into sleep mode before hibernation, then have it wake up on resume. Here's how.
Place this script in /usr/local/sbin/network-manager-ctrl:
#!/bin/sh case "$1" in sleep|wake) # Thanks to Tim Niemueller for: dbus-send --system \ --dest=org.freedesktop.NetworkManager \ /org/freedesktop/NetworkManager \ org.freedesktop.NetworkManager.${1}; ;; wireless-enabled) # $2 = true or false dbus-send --system \ --dest=org.freedesktop.NetworkManager \ --type=method_call \ /org/freedesktop/NetworkManager \ org.freedesktop.NetworkManager.setWirelessEnabled \ "boolean:$2"; ;; esac; exit 0;
In /etc/hibernate/hibernate.conf and /etc/hibernate/ram.conf, add:
OnSuspend 20 /usr/local/sbin/network-manager-ctrl sleep OnResume 20 /usr/local/sbin/network-manager-ctrl wake # OnResume 25 /etc/init.d/openvpn restart
If you have a machine with an Intel 855GM chipset that requires you to run 855patch and/or 855resolution in order to get enough video RAM and full native resolution from your LCD, also add the following lines. (Note: the 855patch program is not in Ubuntu. I compiled it from source, and made a copy of the 855resolution init.d script, then edited it to call 855patch 65535. Both are run from rcS.d, changed from the Debian package which runs it from rc2.d but too late for the early start of GDM in Ubuntu.)
OnResume 90 /etc/init.d/855patch start OnResume 90 /etc/init.d/855resolution start
Reboot, Hibernate and have fun!
Let me know if you require any assistance, and if you find any errata. karlheg@laclinux.com




