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)

While apt is downloading, go to http://www.tuxonice.net/downloads/all/ and download the latest TOI-Patch for you're system, for example current-tuxonice-ubuntu-intrepid.patch.bz2.

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

Update 2008-12-05:

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

Other changes:

  • 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

Comments

Thanks for this great howto.
You may want to set CONCURRENCY_LEVEL=2 env for dualcore systems. Then make-kpkg will run 'make' with -j2 parameter.
Build dependencies of linux-source is not necessary because they are required for building linux-source package itself.

Build dependencies of linux-source is not necessary because they are required for building linux-source package itself.

It should not be necessary to change to "root=" parameter. Just edit your menu.lst and append "resume=swap:/dev/sda5" (assuming that sda5 is your swap partition) to the line starting with

# defoptions=quiet splash

When this line looks like this:

# defoptions=quiet splash resume=swap:/dev/sda5

Execute update-grub and the parameter should automatically be added to your default entry's arguments (do NOT remove the '#'!)

Another solution is to follow my instructions in Integrate TuxOnIce into Ubuntu's hibernation process, which is safe for suspend to swap (and experimentel for suspend to file).

For me, fstab lists two different UUIDs, one for an ext3 partition (sda1), and the other for my swap partition (sda5). Which one should go into the "kernel" line of the entry I'm adding to menu.lst?

Right now, the entry I've written looks like this, but it's kind of a shot in the dark:

title TuxOnIce
root (hd0,1)
kernel /boot/26test root=UUID=5d62b956-2107-4d10-a5a2-9c0543d4d820 ro quiet resume=swap:/dev/sda5 vga=791
initrd /boot/initrd.img.gz
savedefault
boot

Sorry for being such a newbie, but getting suspend/resume to work as well in Intrepid as it did in Gutsy is worth a lot to me.

Can you report the output of "ls -dl .config"? Sound's like you have a directory or something like this with the same name...

Hi Roland. Thanks for the quick reply. .config does appear to be a directory:

$ ls -dl .config
drwxr-xr-x 6 j j 4096 2009-02-20 10:59 .config

What should I do, rename it?

It contains the following:

compiz gtk-2.0 tracker user-dirs.locale
config-2.6.27-11-generic totem user-dirs.dirs

No, don't! You're in the wrong directory (in $HOME)! Switch to /usr/src/linux-2.6.27 (if you're trying to patch a 2.6.27 kernel) and start again from "sudo cp /boot[....]".

Oh, and you can remove ~/.config/config-2.6.27-11-generic :-)

In /usr/src, I have the following directories & files. To which one should I navigate in order to execute "sudo cp /boot etc" ?

linux-headers-2.6.27-11 linux-headers-2.6.27-7-generic
linux-headers-2.6.27-11-generic linux-source-2.6.27
linux-headers-2.6.27-7 linux-source-2.6.27.tar.bz2

linux-source-2.6.27 is the right one (see second block of commands in the article).

Oops! Sorry. For some reason, I assumed that "sudo cp /boot etc" should be executed in a new terminal. That's why I had a problem. Thanks again for your patient help.

no problem :)

From above, entering this:

$sudo sed -i~ -r -e \ 's/^(CONFIG\w*DEBUG\w*)=.*$/# \1 is not set/g' .config

Gave me this error:

sed: couldn't edit .config: not a regular file