Hibernate feature in Linux

Reduce TUX’s metabolic activity!

Short URL: http://fsmsh.com/1520

Write a full post in response to this!

For a long time, hibernation has been associated with proprietary operating systems. Now, the feature has started taking the front row in GNU/Linux systems too. What’s more, it’s fast, flexible and is a real time saver!

Introduction

Software hibernation or suspend-to-disk is a very productive operating system feature. It has many advantages over a cold system start or reboot. Not only does the hibernated system load up faster, the user also gets back to his previous session without much effort. This is important because of the time the user saves by avoiding the need to set up a work session again.

So, how is hibernation different? It is different because it saves the contents of the RAM (Random Access Memory) into some non-volatile storage medium before shutting down the system. Consequently, when the system boots up again, the operating system loads the suspended image from disk to get back to the previously stored session.

Software suspend, as hibernation is popularly known in Linux systems, has evolved a lot in present day kernels. It is constantly getting more and more stable and useful. Some implementations are available in the kernel while one is available as a patch that can be applied to the 2.4 or the 2.6 series. This article is meant to introduce you to the implementations available and the features that they provide.

Not only does the hibernated system load up faster, the user also gets back to his previous session without much effort

History and available methods in Linux

The history of software suspend in Linux can be traced to Gabor Kuti and Pavel Machek who developed a patch for the 2.2 series known as swsusp. It was probably an abbreviation for swap suspend as the snapshot image was written to the active swap partition of the system. Gabor used to maintain these patches on his personal page. The code base for this patch became the basis for three different implementations that we have today: swsusp, suspend2 and uswsusp.

swsusp was first incorporated in the 2.5.18 kernel. It subsequently became a part of the 2.6 stable release. Later, a fork of swsusp, known as pmdisk evolved. The difference between swsusp and pmdisk was that the latter’s code was much cleaner and well structured. Moreover, while swsusp used the /proc interface, pmdisk used the /sys interface. pmdisk cleanups were eventually merged into the swsusp code base.

Among all the available methods, the one that generates the maximum excitement is suspend2 by Nigel Cunningham. It introduces some important changes in the way the snapshot image is handled and is also noticeably faster. suspend2 is currently available as a patch for 2.4 and 2.6 kernels and will hopefully be merged into the mainline kernels in future.

Also worth mentioning is uswsusp, abbreviation for userland-swsusp. It is an implementation of an interface for software suspend in the user space. All kernels starting from 2.6.17 have uswsusp merged in them. The module gives access to software suspend functionalities by exposing common file operation methods that can be used to operate on a character device. This is only useful for developers who would like to write their software suspend applications in user space and hence I won’t delve into this topic in detail here.

swsusp

How swsusp works

swsusp works by taking a snapshot of the contents of the RAM. This snapshot or suspend image is copied and then saved in an atomic operation fashion to the active swap partition. Upon rebooting, if a valid image signature is found on the active swap, the image is loaded and the snapshot transferred back to memory. This gets back the saved state to the user. The following illustration shows the sequence in simple terms:

  • User requests for software suspend
  • All the running processes are given the suspend signal
  • The devices are frozen so that they don’t change the system state when the snapshot is taken
  • The memory image is atomically copied with interrupts disabled
  • Frozen devices are awakened so that the image can be written
  • The image is written to swap
  • Devices are suspended and the system powered off

The resume process involves just the inverse of the above steps.

Configuration and running

Configuring and running swsusp is a breeze since it is a part of the 2.6 vanilla kernel. If swsusp has not been compiled in your running kernel, you will have to enable it and recompile your kernel. It is always a good idea to compile a fresh stable version instead of tinkering with the running version because that way you always have a backup with you.

To enable swsusp, bring up the kernel configuration window:

$cd /your/linuxsourcedir
$make xconfig
Don't miss out on the other pages!
12345next ›last »

Write a full post in response to this!

1

Do you like this post?
Vote for it!

Copyright information

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html.

Biography

Bandan Das: Bandan is an active user and supporter of Open Source Softwares. He is currently pursuing Master of Science in Computer Engineering from Syracuse University, NY. He loves programming in C and LISP and loves playing his guitar when he wants a break from gadgets and geek stuff.

Anonymous visitor's picture

Distros that already come with Hibernate

Submitted by Anonymous visitor on Fri, 2007-01-12 15:21.

Vote!
0

I just wanted to mention that for many users, Hibernate on GNU/Linux can be even easier. (Especially of interest to those who consider switching from Windows or the Mac and might be scared off by lengthy walkthroughs like this.)

gNewSense (www.gnewsense.org) and Ubuntu (www.ubuntu.com) both come with Hibernate already configured. So, for the user it's just a matter of clicking "Shut Down" -> "Hibernate". (I'm sure there are others too, but these are the ones I know.)

Raghu Kodali's picture

Distros that already come with Hibernate

Submitted by Raghu Kodali on Sun, 2007-01-14 16:54.

Vote!
0

Debian Etch (Testing still) also has the hibernate built in. It worked out of the box for me on my Thinkpad (R51)

Anonymous visitor's picture

Distro's that come with Hibernate

Submitted by Anonymous visitor on Tue, 2007-01-16 08:38.

Vote!
0

openSUSE 10.2 has it enabled by default too (I haven't tried it yet though), what I don't understand is this:

swsusp will not work with Symmetric Multi Processing (SMP) enabled in your kernel

But openSUSE has 2.6.18 with SMP as default kernel

Anonymous visitor's picture

Mac Suspend Techniques

Submitted by Anonymous visitor on Wed, 2007-01-17 02:10.

Vote!
0

I hear the mack is always updating changes in ram to the hybernation partition so that when a hybernation action is called for there is less writing necessary. I'd really like to see this functionality brought to Linux.

-Joe Baker

Anonymous visitor's picture

Distros that already come with Hibernate

Submitted by Anonymous visitor on Mon, 2007-01-22 18:42.

Vote!
0

Tried nearly all recent versions of Ubuntu to try out the Hibernate feature..works like crap.
Went back to Windows just bcoz I wanted this feature rather than waiting for Ok, Linux booting now.

Anonymous visitor's picture

thanks

Submitted by Anonymous visitor on Sun, 2007-03-25 18:18.

Vote!
0

thanks

UK's picture

It was raining heavily with

Submitted by UK (not verified) on Thu, 2007-06-14 00:43.

Vote!
0

It was raining heavily with lightning while my lengthy fortran code had been running on my dekstop pc for about a day, I simply hybernated Ubuntu and once the rain stopped I was able to continue from where it's left, This is a very useful feature which really worked and helped me,

I'm wondering what'll happen if I unplug the computer after hybernating, I'll see if writes the current state to the RAM or to the Harddisk. I'm assuming the latter is true.

original_jamingrit's picture

Wanted to say thank you!

Submitted by original_jamingrit on Thu, 2008-08-07 01:30.

Vote!
0

I know this probably wasn't the most up to date article on Linux hibernation, but it worked perfectly for me.

Followed the swsup method. I'm running SW 12.1 on a Toshiba Satellite MX40 series. Worked like a charm.



Other sites

Free Software Magazine uses Apollo project management and CRM for its everyday activities!