It's pretty sad. Hibernation works so well in Linux, but few people are actually able to experience it. Jon suggested that I put up a little guide as to how I got it working, and I thought that was a good idea. So here I go.

Please note: lots of this was taken from a guide on the Ubuntu forums, an excelent resource. If my guide doesn't work for you, check out that (assuming that you're using Ubuntu).

Also, I'm using Ubuntu, and parts of this guide are Ubuntu specific. I'll do my best to identify those parts and provide alternate directions, but if something gets out that doesn't work for anything non-ubuntu, leave a comment and let me know.

Before we get started, you should know this: we are going to recompile the kernel. Don't let this intimidate you, this is actually fairly easy, so just stick to this and you should be good.

OK, let's get started!

  1. Get the Kernel Source
    I reccomend getting source for the same Kernel you're running.
    If you are using Ubuntu, run this command:
    sudo apt-get -y install build-essential bin86 libncurses-dev alien
    sudo apt-get -y install linux-tree-2.6.12
    Please replace (kernel version) with the version of your running kernel. If you're running something like '2.6.12-9-386', it will be 2.6.12 here.

    If you're not using Ubuntu, you need to download the Kernel source manually. You're best bet is to go to kernel.org and download the vanilla version of your running kernel. If you need help with this, Google around for another guide and come back here once it's unpacked to /usr/src. To obtain your Kernel version, run this command:
    uname -r      (note: you only need to do this if you're not using Ubuntu)
  2. Change to the Kernel source directory
    cd /usr/src
  3. Download Suspend2 Files
    Now's the best time to do it, so become superuser:
    su
    Password: (enter your root password)
    Ubuntu users can download everything using these commands:
    wget http://ubuntu.griffin3.com/software-suspend-2.1.9.9-for-2.6.12-ubuntu5.10.tar.bz2
    wget http://www.suspend2.net/downloads/all/hibernate-1.12-1.i386.rpm
    wget http://www.suspend2.net/downloads/all/suspend2-userui-0.5.1.tar.gz
    If you're not using Ubuntu, you'll need to go to suspend2.net and get the correct patch, userspace UI, and the hibernate script. If you're using Debian, chances are you can do an 'apt-get install hibernate' for the hibernate script, but everything else you need to go to suspend2.net. If you're not using Debian or a RPM based distro, you need to download the source tarball to get the hibernate script. (hint: you'll probably have to go to the Older Downloads section because things listed on the main download page only work with the very latest Kernel). The easiest way to do this is to copy the link in your browser and then go to the terminal we've been using and type in 'wget ' and paste the URL (Right Click > Paste, Ctrl + V doesn't ususally work) Otherwise, make sure you download it to /usr/src. Make sure that the userspace UI version you download is compatible with the version of Software Suspend that you download.
  4. Untar Everything
    Ubuntu users run these commands:
    tar -xjf software-suspend-2.1.9.9-for-2.6.12-ubuntu5.10.tar.bz2
    tar -zxf suspend2-userui-0.5.1.tar.gz
    tar -xjf linux-source-2.6.12.tar.bz2
    If you're not using Ubuntu, do this:
    tar -xjf suspend2-2*.tar.bz2
    tar -zxf suspend2-userui-*.tar.gz
  5. Link Time
    Ubuntu users do this:
    ln -s linux-source-2.6.12 linux
    If you're not using Ubuntu, do this:
    ln -s linux-(version) linux
    Replace (version) with the version of the Kernel you downloaded.

    Now, everyone do this:
    cd linux
  6. Get GCC 3.4
    Now, we need GCC version 3.4. If you're not using Ubuntu, just make sure you have GCC version 3.4 installed. If not, install it.

    Ubuntu users do this:
    apt-get -y install gcc-3.4
    CC=gcc-3.4
    export CC
  7. Prepare the Kernel source
    Everyone do this:
    cp /boot/config-`uname -r` .config
    make oldconfig
    This will make sure the Kernel will be compiled with the same options that are in your running kernel.
  8. The fun part - Patching the Kernel
    Ubuntu users do this:
    ../software-suspend-2.1.9.9-for-2.6.12-ubuntu5.10/apply
    Non-Ubuntu users do this:
    ../suspend2-2*/apply
  9. Get your IDE chipset
    Now we need to find your IDE chipset. The speed of Hibernation will depend on support for your specific IDE. Generic IDE support will give you read/write speeds of around 5 MB/s, while specific IDE support can give you speeds of 40 or 50 MB/s. It really does make all the difference.

    Do this:
    lspci | grep 'IDE'
    Just use common sense here. If you have a computer like mine and have an Intel ICH5 chipset, you'll need to compile the "Intel PIIX" driver when it comes time.
  10. Get your swap info
    Run this command:
    fdisk -l | grep 'swap'
    Remember what device it is for later. For example, my swap is /dev/hda5. Yours will probably be different.
  11. Configure the Kernel
    Now we need to configure the Kernel. Here, just go through the options I have listed and make everything look the same.
    make menuconfig
        General setup --->
            (-hibernate) Local version - append to kernel release
             # Change the -hibernate to whatever you want
        Power management options (ACPI, APM) --->
            <*> Software Suspend 2 --->
             # Press y here to turn < > into <*>
                <*> Swap Writer
                 # If you want, select File Writer too
        Device Drivers --->
            ATA/ATAPI/MFM/RLL support --->
                <*> ATA/ATAPI/MFM/RLL support
                <*> Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support
                <*> Include IDE/ATA-2 DISK support
                <*> generic/default IDE chipset support
                 # Now here's where we need that IDE info. You should select a
                 # Driver that will work for your chipset. For my example, I'll select
                 # the Intel PIIX driver. Only select this if you have a compatible
                 # chipset! If you don't select a compatible driver here, everything
                 # will still work, but it will be slow.
                <*> Intel PIIXn chipsets support
        File systems --->
            <*> Ext3 journalling file system support
             # This is probably already selected, but double check
        Cryptographic options  --->
            <*>   LZF compression algorithm
    # This next part is optional, but it's a good idea to get support for your
    # specific processor
        Processor type and features  --->
            Processor family
                 # I have a Pentium 4, so that's what I'll select. Select the right one
                 # for your system.
                (X) Pentium-4/Celeron(P4-based)/Pentium-4 M/Xeon
    You're done! Give yourself a pat on the back. The hardest part is over.
  12. Install Userspace UI
    Everyone do this:
    cd /usr/src/suspend2-userui-*
    make suspend2ui_text
    cp -p suspend2ui_text /usr/local/sbin
  13. Install Hibernate Script
    Now we'll install the Hibernate script.

    Ubuntu users do this:
    cd /usr/src
    alien -i hibernate-1.12-1.i386.rpm
    Non-Ubuntu users, you have a couple options here. If you're using Debian, you can go to step 3 and download the hibernate script RPM and do the commands listed above, substituting the version for that of which you downloaded. If you're using an RPM based distro, just install the RPM that you should have downloaded in step 3. If you're using anything else, you'll need to compile the hibernate script. I'm not going to be giving directions on that. If you need help doing this, look at the official Suspend2 Documentation.
  14. Configure the Hibernate Script
    Now, we need to set a few options in the hibernate.conf file.

    Everyone
    do this:
    gedit /etc/hibernate/hibernate.conf
      (note: gedit is a Gnome program, so if you don't have it, use another text editor like vi)
    Now, make sure the following options are set:
    ImageSizeLimit nocache
    ProcSetting expected_compression 50
    (add this) ProcSetting userui_program /usr/local/sbin/suspend2ui_text
    SwitchToTextMode no
  15. Compile the Kernel
    Here's the part you've all been waiting for. It's now time to compile the Kernel.

    Everyone do this:
    cd /usr/src/linux
    make bzImage install modules modules_install
    This will take a while. Go get lunch, call your mother, watch TV, whatever. Check back every so often to see how it's doing.
  16. Update Grub
    Now we need to update Grub.

    Ubuntu users do this:
    cd /boot
    rm config vmlinuz System.map [this is optional, less clutter for update-grub]
    update-grub
    Non-Ubuntu users: you need to do this manually. Edit /boot/grub/menu.lst and edit the current entry to your new kernel (vmlinuz-2.6.12-distribution becomes vmlinuz-2.6.12-hibernate or whatever you specified).

    Now, everyone do this:
    gedit /boot/grub/menu.lst
    Here, add a line to the kernel boot line. Remember your swap partition? We're going to need that here.
    Add this to the end of the kernel line:
    resume2=swap:/dev/hdaX
    Replace the X with the number of your swap partition. Mine is hda5, yours may be different.
  17. Set the Power Button to Hibernate
    This step is optional, but reccomended. To suspend, you need to be Root and run 'hibernate', but I seriously doubt that anyone wants to fire up a terminal and type 'sudo hibernate' whenever they want to hibernate. Setting the powerbutton to do this task makes life a lot easier.

    Everyone do this:
    gedit /etc/acpi/events/powerbtn
    Now change the file so it looks like this:
    event=button[ /]power
    action=/usr/sbin/hibernate
    #action=/etc/acpi/powerbtn.sh
    Now do this:
    /etc/init.d/acpid restart
    Note: if you have a laptop, there's probably a way to set that to hibernate when you close the screen. I didn't do this on my laptop, and I don't intend to. Google around, you should find an answer.

That's it! Reboot and press the power button (or, if you skipped that, open a terminal and do 'sudo hibernate' in ubuntu, or do 'su' then 'hibernate' in anything else).

Sidenote: If you want to use Suspend2 with initrd or initramfs (if you're on Ubuntu, don't worry about this) please read this section on the Suspend2 Howto. You need to do something else.

If these steps don't work for you, please leave a comment with your problem and if I made an error, I'll fix it.