Hibernating my MacBook under Ubuntu Intrepid Ibex

No matter what they say, [[Hibernate (OS feature)|hibernating]] Linux laptops has always been a problem. I managed to get my MacBook to [[sleep mode|suspend]] to RAM quite reliably without much of a hassle. It suspends when I close the lid, and it resumes when I open the lid back. I even configured it to suspend when battery is critically low. This way, and due to the really low power consumption while suspended, I can safely forget my laptop on and unplugged for extended periods of time, and the worst that can happen is that I will have to resume it. A huge difference from the nasty surprise of finding it off and losing all the information not saved to disk.

However hibernating to disk is a whole different business. I never managed it to work, and that was an itch I wanted to scratch. Finally I managed, with the following recipe.

HowTo

First, make sure that you have enough [[paging|swap space]] available in disk. In Linux you generally create a swap [[disk partitioning|partition]] when installing the OS. The old adage states that one should make the swap partition twice as big as the RAM memory of the computer. With modern computers this is both unnecessary (because the big RAM makes sure you’ll never run out of it, and if you do, you are screwed anyway) and wasteful (if you have a 4GB RAM, it means that you dump 8GB of disk space). However, if you intend to hibernate your computer, all the information in the RAM memory has to be copied to the hard disk, so you sure need at least as much swap as RAM (but not twice).

Second, you need to use the correct tool. I use [[Xfce]] as desktop environment under Ubuntu, and the Exit menu presents me with six options: “Switch user”, “Log out”, “Restart”, “Shut down”, “Suspend” and “Hibernate”. I think that the latter two make use of the tools in the acpi-support package. The suspend action seems to work OK, but the hibernate one doesn’t (for me). It runs the command /etc/acpi/hibernate.sh, and it gives me problems. Thankfully I found some utilities that work reliably, namely pm-utils.

The pm-suspend command seems to work as correctly as the “Suspend” button in the Exit menu of Xfce. The pm-hibernate, on the other hand, works perfectly, unlike the “Hibernate” button. The drawback is that only root can run it. My solution is to put a launcher button in the Xfce task bar, that will run “gksudo pm-hibernate”. This way I am asked for my password and, if sudo is correctly set up, pm-hibernate will run.

More info

Sometimes it is very interesting to run some commands at suspension/hibernation moment, or at resuming/thawing. One such command is [[hdparm]], with which you can fix the long known load/unload cycle problem (you can google about it). Another one is one to fix a problem that apparently appears on MacBooks: the [[touchpad]] is lost when the computer wakes up back. The keyboard works, and USB mice work, but the touchpad doesn’t. This problem can be fixed by reloading the appletouch [[Loadable kernel module|kernel module]]:

# modprobe -r appletouch && modprobe appletouch

You can fix both issues above by creating a file named, e.g., 99-macbook_fix, in /etc/pm/sleep.d/, and making it executable. Then write in it the following:

#!/bin/sh

if [ $1 = ‘thaw’ ]; then
# The appletouch module has to be reloaded after hibernating
# (not after suspending, though), because otherwise the touchpad
# remains frozen upon awakening.
modprobe -r appletouch
modprobe appletouch

# Correct the load/unload cycles problem
/sbin/hdparm -B 254 /dev/sda
fi

if [ $i = ‘resume’ ]; then
# Correct the load/unload cycles problem
/sbin/hdparm -B 254 /dev/sda
fi

Leave a Comment