Enhance Intrepid Ibex with TuxOnIce
Ubuntu 8.10 ("Intrepid Ibex") uses the kernel's default suspend system, swsusp, but lacks support for TuxOnIce (formally known as "suspend2"). TOI has some advantages to the classic suspend system, for example "suspend to file", "LZW compression" (for faster resuming) and the ability to cancel any suspend request by pressing ESC. Have a look at the feature list for a comparison of these systems.
Espacially "suspend to file" is extremly important to me, because it allows to resume from an encrypted root partition. Of course, this also works with swsusp by using an encrypted swap device, but then you can't use a random password (or a password file stored on root) and have to enter at least two passwords when booting or resuming: one for root (/) and one for swap.
To add TOI support to Ubuntu, you have to build your own kernel. It's pretty easy, but if you use restricted kernel modules (drivers for your graphic card, VMWare/VirtualBox, ...) you will have to recompile them. So, here we go. First of all, download the kernel source and install some additional packages required at compile time:
$ sudo apt-get install linux-source fakeroot build-essential \ makedumpfile kernel-package $ sudo apt-get build-dep linux $ sudo apt-get build-dep linux-source-$(uname -r)
When apt has finished, change dir to /usr/src/ and untar the linux-source-package (I assume that it is 2.6.27, as this is the kernel that is shiped with Intrepid). Then step into the new directory and apply the patch (have I said that you should adjust the path to the downloaded file?):
$ cd /usr/src $ sudo tar xvjf linux-source-2.6.27.tar.bz2 $ cd linux-source-2.6.27 $ bunzip2 -c $HOME/current-tuxonice-ubuntu-intrepid.patch.bz2 | sudo patch -p1
Copy the current kernel configuration to the kernel sources. It has some debug flags enabled. Disable them with a short shell command:
$ sudo cp /boot/config-$(uname -r) .config $ sudo sed -i~ -r -e 's/^(CONFIG\w*DEBUG\w*)=.*$/# \1 is not set/g' .config
I also disabled Xen features (otherwise you will get an 'linux-xenu'-package):
$ sudo sed -i~ -r -e 's/^(CONFIG\w*XEN\w*)=.*$/# \1 is not set/g' .config
Run "sudo make oldconfig". It should ask for some options concerning TuxOnIce (TOI_) and some of the disabled debugging options. Press enter to use the default value for all questions but TOI_IGNORE_LATE_INITCALL. This one should be answered with "y" instead of "N". If you did a mistake, you can start 'sudo make menuconfig' to change this by hand or just repeat the steps starting with "cp /boot/config...".
Before you're going to compile your kernel you should correct the EXTRAVERSION. I'm not sure if this is really neccessary, but it won't hurt. The extraversion is the number behind the first dash in the output of "uname -r". The current kernel on my system is '2.6.27-7-generic', so the EXTRAVERSION is "-7". Edit the Makefile and find the line that starts with "EXTRAVERSION =". Change the value of this option to you're extraversion. The following command should do this for you:
$ sudo sed -i~ -r -e "s/^(EXTRAVERSION\s*=\s*).*/\1-$(uname -r | cut -d- -f2)/" Makefile
Now it's time to build the kernel. I'll suggest to append a custom suffix (e.g. '-tuxonice') to the package to distinguish it from Ubuntu's packages and prevent an unmeant upgrade:
$ sudo make-kpkg --rootcmd fakeroot --initrd --append-to-version=-tuxonice kernel-image kernel-headers
On dualcore-systems, you may want to compile using both cores (thx to Mehmet Kose):
$ sudo CONCURRENCY_LEVEL=2 make-kpkg --rootcmd fakeroot --initrd --append-to-version=-tuxonice kernel-image kernel-headers
This may take a while (even a few hours), so have a cup of coffee, read you're blogs or do something useful ;-) If you ran into problems, have a look at the update a few lines below!
When make-kpkg finished successfully, you should find two new .deb-Files in /usr/src. Install both of them:
$ sudo dpkg -i /usr/src/linux-*$(uname -r | cut -d- -f1,2)-tuxonice*.deb
Ok, now you're able to suspend and resume using TuxOnIce, but you still will have to edit /boot/grub/menu.lst and append a 'resume='-argument to you're new kernel, as described here (forget about the first steps, dpkg has done this for you - just start at "Add menu.lst entry"). I also suggest to read the comments in menu.lst carefully and thus discover that you shouldn't append this option to any 'kernel' line but to '#defoption=...'.
In my next posting, I'll introduce a more "ubuntu way" to do this (integration in pm-hibernate and initramfs).
If you experience an error like this while running 'make-kpg' (as Andreas reported at ubuntuforums.org):
exec debian/rules APPEND_TO_VERSION=-tuxonice INITRD=YES ROOT_CMD=fakeroot kernel-image kernel-headers [: 1: 2: unexpected operator [: 1: 2: unexpected operator [: 1: 3: unexpected operator [: 1: 2: unexpected operator [: 1: 2: unexpected operator etc
This has been reported as bug #281699. As a workaround, remove everything 'make-kpkg' created and start again, this time appending "--arch=amd64 --subarch=x86_64" (or "--arch=i386", depending of your cpu's architecture) to the command:
$ sudo rm -rf include/config/* debian/* $ sudo CONCURRENCY_LEVEL=2 make-kpkg --rootcmd fakeroot --initrd --arch=amd64 --subarch=x86_64 --append-to-version=-tuxonice kernel-image kernel-headers
- Added kernel-package to apt-get install
- Removed build-deps of linux-source (thx to Mehmet Kose)
- Added a build command with CONCURRENCY_LEVEL=2 (thx to Mehmet, again)
- Added 'sudo' to the copy of .config
- Changed sed's parameter '-i' to '-i~' to produce a backup
- Added some linebreaks with "\"
- Added sed-expression to disable Xen