Friday, April 27, 2007

Hibernate Your Laptop

Hibernate has the ability to take a snapshot of the state of a computer's memory and save it to disk, and restore that image later. This allows you to fully power down a computer at an arbitrary point in time and not need to reload programs and reopen documents on power-up. In modern laptops, suspension is not done by the BIOS. They use ACPI and ask the operating system to do most of the job. If you can't satisfy yourself with standby mode (suspend to RAM) because you leave your computer in suspend mode for too long (or because you're not using a 2.5 or later kernel and therefore lack suspend-to-RAM support), then you have to suspend to disk. Now, we can hibernate into not only a swap partition, but also a file. And to complete this task, you should patch your linux kernel firstly. I practised the suspend2 in my notebook with Gentoo Linux. Also you can follow the HOWTO docuements at suspend2 official website, which is a nice tutorial. If you also use Gentoo, you need not patch the linux kernel manually. You just only run the command below:
# emerge suspend2-sources
And portage system will patch your linux kernel automaticly, then:
# cd /usr/src/linux
# make menuconfig
Select suspend2 options, here is the path:
  Power management options (ACPI, APM)  --->
  [*] Suspend2  ---> 
      --- Suspend2 
      ---   Image Storage (you need at least one allocator)
      [*]   File Allocator   
      [*]   Swap Allocator 
      ---   General Options 
      (swap:/dev/hda8) Default resume device name
      [*]   Allow Keep Image Mode
      [*]   Replace swsusp by default
And make sure your .config contains such settings, and "swap:/dev/hda8" is the default swap partition to be suspended:
Then compile and install your new kernel, then reboot. *ATTATION* DO NOT forget to backup your original working kernel. If you find such content when "dmesg| less", (eg, "Software Suspend Suspending enabled."), it means you can hibernate your computer now. Now, It's time to manage the hibernate actions. Firstly, fetch the hibernate-script by emerge or from suspend2 website:
# emerge hibernate-script
If you use Thinkpad, you can use the hotkey "Fn+F12" to hibernate with acpid. The event files lie in the directory /etc/acpi/events, and Here is the content of /etc/acpi/events/hibernate:
event=(button/power|ibm/hotkey HKEY 00000080 0000100c)
action=/usr/sbin/hibernate -F /etc/hibernate/suspend2.conf
The HKEY number 00000080 0000100c is the action to press the hotkey "Fn+F12". Here is the detail. If you mount vfat filesystems, you'd better to umount them, when hibernating. Put such settings into the configuration file /etc/hibernate/suspend2.conf
UnmountFSTypes vfat fat msdos
And remount them when re-booting your system with this setting in /etc/hibernate/ususpend-disk.conf:
Mount /path/to/vfat/

No comments: