Linux

Hibernating a Linux Laptop...FINALLY!

After much searching and hair-pulling Jack Wallen has finally found a means to get a laptop to hibernate. It's not perfect but it works every time. Read this open source entry and discover how to enjoy a full-featured laptop on Linux.

Recently, I had to write an article on Linux green computing. During the writing of that article I was sent on yet another quest to get some form of hibernate and or suspend working on a Linux laptop. This quest had me digging through nearly every configuration file and every package I could find in an attempt to get an off-brand laptop (Everex Zonbook) running Mandriva Spring 2008 to either suspend or hibernate. I was surprised at what I discovered and the results I came up with.

Let's first chat about what I discovered. No I didn't uncover the meaning of life, a cure for cancer, or proof that Linux will drastically lower TCO. What I did discover is that suspend and hibernate are two very different beasts and that suspend is still quite elusive in Linux while hibernate is not so challenging. How are they different? There are two different types of suspend: Suspend to RAM (suspend) and Suspend to Disk (hibernate.) Suspend to RAM is when you save the laptop state to RAM so that it can be quickly brought back. Suspend does continue to consume a small bit of power, so if your laptop is not plugged into a power source, eventually the suspend state could drain the battery.

Suspend to Disk (Hibernate) takes the saved state and stores it in your Linux swap partition. This method isn't an "instant off/instant on" state, but it offers a few bonuses over Suspend. One bonus is that it uses zero power. Hibernate effectively shuts down your machine and, upon waking, brings the machine back to the exact state it was in when it was placed into hibernation. And because the state is saved to the hard disk, it is a bit safer than suspend. On the con side of the fence, hibernate does take far more time to put to sleep and wake up (although not as much time as it would to shutdown/boot.)

The good news and the bad news: The good news is that Linux can do hibernate fairly well. AND there are even GUIs to help you configure hibernate. The bad news is that Linux is a ways away from any sort of reliable suspend.

Let's look at one application that allows you to safely hibernate your Linux laptop: klaptop_acip_helper. This command is part of the kdeutils_klaptop package and is run by simply entering the command klaptop_acpi_helper --hibernate. When you run this, the current state is saved, placed in your swap file, and then the laptop is placed in hibernation. To bring the laptop back up, you simply hit the power button.

Of course having to hibernate a laptop from the command line isn't much good to the average user. To make this easier you can configure a lot of options in the Klaptop system tray applet. In this applet you can configure everything from Power Control, battery options, warning events, and button events. One of the handiest configurations is the button events. Here, you can configure your laptop to go into hibernate upon closing the lid.

Of course there are configurations that must be taken care of that can not be done via the applet. If you look in the file /etc/suspend.conf you will see the following:

snapshot device = /dev/snapshot

resume device =

#image size = 350000000

#suspend loglevel = 2

#compute checksum = y

#compress = y

#encrypt = y

#early writeout = y

splash = y

There are two things you need to do. First you need to replace

with the actual path to your swap file. In my case it was /dev/sda5. The second thing do to is to uncomment compress = y.

Once you have taken care of these edits, save the file, and close the file.

Now close the lid on your laptop. After it is closed for a moment, open it back up and you should see some text indicating how much of the state has been saved. Once the state reaches 100% the laptop will power off. When you reboot the machine it will seem as if it is just going through the boot process. But shortly after you press the power button the progress bar will zip through the process and you will find yourself back where you were when you shut the lid.

Is this a perfect solution? No. But it does at least offer a means to save your battery life and give you a laptop-feature in Linux that all Windows laptop users enjoy.

I hope some day to see the Suspend to RAM function actually work. This would remove one of the biggest hurdles for Linux adoption in the laptop market. Give this application a try and report back here so we know the various laptop models it supports.

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

31 comments
chrisspen
chrisspen

The main problem with Linux's hibernate functionality is that there's no progress display. When I first tried to use this feature, the screen just goes blank for 5 minutes, so I reasonably thought Linux had just crashed. Turns out the painfully long blank screen was "normal", albeit a frustrating part of the hibernate procedure.

Gaius_Maximus
Gaius_Maximus

Why use either? I bought a 13KmA battery for my Eee 1000, turned off the power-saving features (except for blanking the screen when the lid is closed), and still get 6-8 hours of real-world work without having to make sure I press a key occasionally to keep it from dimming, snoozing, or, worse, hibernating in the middle of studying some piece of code. Yep! I code on my Eee. I'll go a step further. I predict, that as NAND gets cheaper and faster, both volatile RAM and spinning HDs will disappear. I mean, if you can address 16 Exabytes, and you can afford 512 GB of SSD, why not just have 512 GB of NAND RAM? The instant/always 'on' computer will be a reality, and OSes will have to evolve away from the mass-storage (disk-based) paradigm. Shrink this to something the size of an Eee 901, add wwan, and the smart-phones and their OSes also disappear, showing why Palm et al need to adopt GNU/Linux ASAP, and why M$ will throw WinCE under the bus, paring Windows (7) back to run on the same devices. (Because their non-disk-based, toy OSes will lose any remaining appeal next to non-disk-based versions of *nix and Win.)

heres_johnny
heres_johnny

I've been using suspend more and more as I develop faith in it. Actually, in my experience, the hibernate doesn't work nearly as well as suspend, but after reading your article I will try it again. Maybe I just wasn't waiting long enough. Suspend works perfectly, though. I have a Presario V2000 (don't laugh) with 1.5 G Ram and a 1.8 mhz amd64 processor (and if Ubuntu ever gets serious about 64-bit, I'm there).

hisham_tj
hisham_tj

hello, is this hibernation feature exclusive for laptops or can it be used on a desktop running linux, & is it available in all linux projects releases or just in mandriva, thank you.

chris
chris

I tried hibernate before, but with my dual boot setup I get some funkiness. or, to be more accurate, got funkiness. I have not tried it in a while.

aroc
aroc

Is it just my SeaMonkey/Ubuntu 8.0.4.1, or is this bit of the article really suffering from a "gap"? "splash = y There are two things you need to do. First you need to replace [... replace WHAT?] with the actual path to your swap file. In my case it was /dev/sda5. The second thing do to is to uncomment compress = y. Once you have taken care of these edits, save the file, and close the file." BTW, running mostly on a Fujitsu Lifebook P5020D, and suspend works about 50/50, have not tried hibernate.

eck0
eck0

ok after reading through all the other comments I have to say that my bad form of using strictly root for years let me do alot rather easily. now that I am attempting to do right and strictly use just my user account I am having to do a lil more work but loving the results. I will have to try getting the sleep thing working later today but every thing else on my laptop works rather well in Linux including my built in mics.

shardeth-15902278
shardeth-15902278

In reading these posts, I find myself wondering how Linux would fair in a thorough comparison to XP and Vista. Does Windows really perform these functions better? Have they built exceptions for all this poorly implemented hardware, where Linux has not? My Windows experience would seem to suggest otherwise. I have tried both suspend and hibernate on a half dozen systems (Dell and HP), and Vista on one. Vista frequently crashes on wake-up. XP either crashed on wakeup, or hung during the hibernate process on most of of the systems I used it on (There were probably 2 of the six systems that I would say worked acceptably). I never did play with hibernate on Linux on those systems, and my current laptop isn't running it (thing came with a dell remix of a broadcom wifi card that doesn't work with Linux. Well, that plus I am testing Vista, and the OS sucks up so much disk space that I don't have room on the drive for both OS's like did w/ XP.

markinct
markinct

As long as users have to do a lot of heavy lifting just to get to the baseline of functionality found in Windows, linux will continue to be an orphan also ran. I've been playing with Ubuntu on an HP laptop. It wasn't until I installed 8.04.1 recently that I got satisfactory results. Sure I can hibernate my laptop. I even got my webcam to work (but not built in microphones)... More work was required to bring my touchpad into line. I configured my finger print reader, but ended up pulling the plug because it was far more trouble than it was worth. Clearly there are many things that linux does right. And I love playing with it. But I still must revert to Vista if I need to get critical work done. I doubt this will change in the next 12-24 months.

ttdlx1989
ttdlx1989

One of three things can make suspend not work. The BIOS doesn't support it, the hardware doesn't support it, or the drivers don't support it. If suspend works on a machine in another OS, then it probably means BIOS and hardware supports it, and the drivers don't. That being said, most of the time, if suspend doesn't work, it's due to proprietary drivers. NDISwrapper is usually the culprit, especially if you're suspending during wireless activity, but, there are other cases. As an example, ATI's fglrx driver had spotty suspend/resume until recently (still not perfect, but better than before). Also, just because a driver is open source doesn't mean it supports suspend/resume. Especially in-progress drivers will not have it, nor will externally (as in outside the kernel tree) created drivers necessarily support it.

abcddd
abcddd

KDE has a new application for this very thing called PowerDevil. It works very well and is reliable.

rt
rt

You need an additional category on your poll: "Been there, done that."

_carlleigh_
_carlleigh_

I have a new Linux EeePC and both Hibernate and Suspend are working fine. My older laptop came with Windows XP and Hibernate and Suspend flaked out with Service pack 2. The manufacturer said there was nothing they could do. So. I installed Fedora 9 and now use it for network testing......

JimMcDish
JimMcDish

Nice! No doubt about it, its about time! JIff www.privacy-center.ru.tc

blah32
blah32

KPowersave would save you writing this article :-S

rickenbacherus
rickenbacherus

HP dv6500, Debian Sid, kernel 2.6.26-5 Both hibernate & suspend 'just work' w/ LXDE (an extremely lightweight WM with very few extra features). Obviously this is going to vary from manuf. to manuf. Not everyone implements the standards very well. You can't always blame Linux.

tracy anne
tracy anne

I'm using Mandriva 2008.1 and my partner is using Mandriva 2008.0, and neither of us has any trouble Suspending or Hibenating, and we certainly don't have to use the command line to do so. My partner just shuts the lid on her machine, the option to do so was set from a GUI called KPowersave. I've chosen not to allow Hibernate or suspend in that manner, and instead have chosen to do it manually by simply by right mouse clicking on the icon, for KPowersave, in the system try. I don't have to do it this way, it's just that I like to have more control over when it happens.

markinct
markinct

I'm now running Ubuntu 8.04.1. Hibernate/Suspend works as advertised. It seems more stable than 8.04. Grub defaults to Linux, so coming up from hibernate isn't affected by my dual-bootness. Boot/login to Gnome/get working is much faster for me under Ubuntu than the same cycle going into Vista. I don't "feel the need" to suspend any where near as much as in Vista.

Neon Samurai
Neon Samurai

If your Windows/Linux then the Windows side does it's own thing for hybernate. The Linux distro side needs it's swap file or partition I would expect. Now, if it's two Linux distros I'd give each there own hybernate partitions. Granted, it's not an area I've mucked with so I'm mostly guessing blindly.

RipVan
RipVan

Ditto on suspend/hibernate in Windows. People I support frequently have problems with it, and home users have an even worse time. I usually end up killing the session and restarting, the system just won't wake up. Who says this stuff "just works" in Windows....?????

alvarocervantes
alvarocervantes

I never had troubles with Thinkpads, they work as they supose with Suse and any other flavour of Linux, they even have specific modules for the special keys they come with. HP and other vendors load hardware that most of the time don't support Linux; they make money with Linux, but they fail to fully support it.

kingttx
kingttx

You equate the finger-print reader, webcam, and mics as "critical"?? Really? I can see having issues with the touchpad, but the other stuff, dunno. Guess your definition of critical takes a different set of priorities than the rest of the world.

parnote
parnote

No, just running KPowersave will NOT have saved him from writing this article. It may work on YOUR laptop, but (even after following the instructions in this article) my Sony Vaio laptop still will not "Suspend-To-Disk". Different ACPI implementations by different manufacturers was, is, and remains, one of the primary problems.

jlwallen
jlwallen

some laptops (mine for example) have a lot of trouble with hibernate/suspend with Linux. i have written about this topic before here to find some people had no problems and many couldn't get it to work to save their source. i was one of those that had a laptop that didn't seem to jive well with hibernate/suspend. i went through Ubuntu, Kubutu, Mandriva, SuSE, OpenSuSE, Fedora, Mepis, PCLinuxOS, gOS (both Rocket and Space) and never found a distribution, out of the box, that would work. it wasn't until I found the tool in the article that i was able to get hibernate to work on this laptop. consider yourself lucky that suspend/hibernate worked out of the box. many wind up giving up after hours of trying.

potter67
potter67

It is working for me on a Mandriva 2008.1 (very stable) and in a less extends on 2009. I use a VAIO TZ serie Chris

pgit
pgit

Actually, you can have one swap file and both Linux distributions will use it the same. Swap is just raw data, not an ordered file system. The system doesn't care what's in there, it considers it blank and available for it's own use when you boot into it. And if you hibernate one system, you're not going to boot into the other without waking up and shutting down first. There's arguments that with RAM getting big and cheap, the swap file is becoming obsolete. Not so, at least on laptop computers, that is if you want to hibernate...

rkuhn040172
rkuhn040172

Hibernation doesn't work in Windows because of a driver issue. Unfortunately, that would/will probably be the case with Linux as well.

markinct
markinct

I should have been clearer - in order to support choices made by my employer or partners I must use Windows (for the time being). But yes, a finger print reader is becoming critical for corporate laptops. It really doesn't matter if the laptop is actually secured by it or not, the finger print reader represents "security magic" - good theater for non-technical executives to understand and repeat for auditors (or a Congressional hearing).

tracy anne
tracy anne

I've instllaed Mandriva on lots of different laptops, and the only one I've had a problem with was a brand new bottom of the range Lenovo. But it has other problems as well, Like if I do enable suspend/hibernate by enabling acpi, it won't recognise the CD/DVD hardware, and so mounting a CD/DVD is impossible, so it's one or the other, and the owner opted for no acpi. The fact is this particular Lenovo has some weird BIOS, or a buggy BIOS.

Neon Samurai
Neon Samurai

In terms of swap file, I didn't suspect much issue sharing a swap partition with it being just a temporary warehouse for ram data. What threw me off was seeing the config setting for hibernate swap space in the kernel source when compiling a custom (mostly just to specify the CPU type). I figured if you where hardcoding a hibernate location, you would want to keep distributions seporate.

pgit
pgit

I run 2008.1 on a Dell Vostro 1000... do NOT buy a vostro if you intend to run Linux. NOT NOT NOT... this is the most Linux unfriendly machine on the planet. 08.1 itself runs great, once I get it installed and tweaked properly, a process few would endure. One reinstall followed merely trying to hibernate. Never again, not on this machine. BTW kpowersave will not run on this machine. Like Jack, I use klaptop. According to Mandriva kpowersave is the default. Another thing I chalk up to this vostro.

Editor's Picks