Introduction

Hibernation is a function allowing one to save the current state of their computer to the hard drive, with the computer completely powering down. When the computer is subsequently powered back on, the prior state is restored as if one had not powered down at all. Having hibernation available is a preferred benefit for many reasons:

  • For travelers who want the convenience of saving their last computer session, without risking hardware damage when putting either a still running, or suspended computer into a travel bag.
  • For those who do not want to setup complicated rules for opening up programs upon first start.
  • Better power savings in comparison to suspending or leaving the computer on overnight, or when one goes home for the day.

There are three methods of hibernation:

  • kernel (aka suspend or swsusp): The linux kernel includes built-in support for hibernation. This method is triggered by modifying /sys/power/state.

  • uswsusp: uswsusp is a rewrite of swsusp that does not rely on the kernel. Thus, uswsusp is a "userspace" tool because it is run entirely as a program separate from the kernel. It can be used by installing the package uswsusp and running sudo s2disk. This is reported to work in many situations where swsusp does not. It also supports encryption and compression for hibernation.

  • TuxOnIce (formerly suspend2): TuxOnIce has more features and works with more hardware than the other two. Unfortunately, it requires building and patching your own kernel.

Here is a comparison table of the various hibernation methods. The general impression is that swsusp was first, so is in the main kernel trunk, uswsusp is userspace based, while TuxOnIce is not integrated into the kernel. There is a discussion between the authors, in that although many users greatly prefer TuxOnIce when they try it out ('it just works'), it has yet to be merged into the kernel.

swsusp

In Ubuntu, the default method of hibernation is to use swsusp which is built into the kernel. Gnome and pm-utils will use this method unless configured otherwise.

The way you manually trigger hibernation using this 'kernel' method is to write 'disk' to /sys/power/state. There are two modes of 'kernel' hibernation: platform and shutdown. If one does not work, you can try the other:

sudo -s
echo platform > /sys/power/disk
echo disk > /sys/power/state

Or:

sudo -s
echo shutdown > /sys/power/disk
echo disk > /sys/power/state

Platform is the default and recommended mode of hibernation. Unfortunately, the "platform" mode of hibernation does not work on some systems with a broken BIOS. In such cases the "shutdown" mode of hibernation might work.

swsusp Troubleshooting

Problem: The computer goes to hibernate ok. But after power-on it is loading as if no hibernate state was saved.

Solution based on launchpad answer - add resume parameter to kernel boot options.

In the case of grub2:

  • open /etc/default/grub

  • find GRUB_CMDLINE_LINUX_DEFAULT= line - these are the option added to the regular boot menu choices

  • add the resume=/dev/sda6 option to the list (with correct swap partition path) like this:

Before:

GRUB_CMDLINE_LINUX_DEFAULT="nosplash enable_mtrr_cleanup=1"

After:

GRUB_CMDLINE_LINUX_DEFAULT="nosplash enable_mtrr_cleanup=1 resume=/dev/sda6"
  • save file
  • in the terminal execute command (to actually enable the new configuration settings)

sudo update-grub2

uswsusp

The package uswsusp (for Userspace Software Suspend) includes an executable called s2disk. This program is an alternate method of hibernation. In general, s2disk should not be called directly, but it can useful to do so for testing. Typically, the program pm-hibernate is responsible for calling s2disk.

The s2disk program does the following in order to hibernate the machine:

  1. Tell the kernel to create a snapshot of the current system state.
  2. Read the snapshot data from the kernel and write it to the swap partition, possibly encrypting and compressing the data.
  3. Power off the machine.

When next you power up, the reverse happens:

  1. After a basic system boot, but before mounting any partitions, resume runs from the initrd.

  2. The snapshot data from the swap partition is read (and possibly decrypted and decompressed).
  3. resume tells the kernel to restore the snapshot.

  4. the kernel returns at the place it was before the hibernation.

To install s2disk:

sudo apt-get install uswsusp

It is not generally useful to trigger s2disk manually, unless you are debugging. For example:

sudo tail -f /var/log/pm-suspend.log &
sudo s2disk

When you run s2disk manually like this, it is likely that when you restore a lot of your devices will not be working.

To change your uswsusp settings:

sudo dpkg-reconfigure uswsusp

Alternately, you can edit /etc/uswsusp.conf manually.

Integrating uswsusp with pm-utils

Currently, installing s2disk does not actually make it so that it is used by gnome or pm-utils. To do so, edit /etc/pm/config.d/00sleep_module and change the value of SLEEP_MODULE:

SLEEP_MODULE="uswsusp"

Then, to test, you can run this:

sudo tail -f /var/log/pm-suspend.log &
sudo pm-hibernate

pm-hibernate (part of pm-utils) is the preferred way to run s2disk. By default, when you choose hibernate from within gnome, the command pm-hibernate will get called.

uswsusp Troubleshooting

  • I have encryption configured and when I resume the wrong term is open. To get to the password prompt, I have to hit Alt-1.

See Also

TuxOnIce

  1. tuxonice-userui

  2. PPA Available

  3. Enable TuxOnIce kernel image in GRUB2 menu and select it when booting (grub-customizer is a good tool).

Troubleshooting

For swsusp please see this part of this page

For uswsusp please see this part

Hibernate Disabled by Default

Certain laptops have hibernate greyed out in the menu by default. For more on this please see bug 812394.

  • 13.04 and below: To activate hibernate in Ubuntu or Xubuntu due to this, please see the official documentation.

  • 13.10: In Xubuntu, one will want to install pm-utils, and hibernate via a terminal (as the above doesn't enable the GUI option):
    sudo pm-hibernate

  • 14.04: To activate hibernate in Ubuntu 14.04 read on the official documentation

Links

PowerManagement/Hibernate (last edited 2014-06-09 18:48:18 by cpe-186-23-181-11)