Fix: hibernate
From EasyPeasy Wiki
Tested under Ubuntu EEE 8.04.1
Difficulty: medium
Contents |
[edit] Description
This is a way to set up hibernation in a way similar to how Windows does it, with a separate hibernation file rather than using your regular swap file/partition. It's a bit more difficult to do, but allows you to delete the hibernation file if you need the extra space, and also reduces the number of writes to the flash drive as it will automatically enable the hibernation file as "swap" as necessary during the hibernation process, and disable it after the system has been successfully resumed.
[edit] Required packages
- uswsusp
- array.org kernel
Do NOT install uswsusp until after you set up a swap file/partition!!
Follow the instructions here to install the kernel first: http://www.array.org/ubuntu/setup.html Reboot and use the new kernel before continuing.
[edit] Steps
[edit] Create hibernation file
sudo dd if=/dev/zero of=/.hibernate.img bs=1048576 count=768
change COUNT to however much RAM you have/2 approximately. uswsusp can compress the hibernate image about 50%, often more. I have 2GB RAM in my EEE 701, and the 768MB hibernate file works fine. You can't create a sparse file because the kernel will complain unfortunately, so you have to actually create a regular file.
Format the file as a swap file.
sudo mkswap /.hibernate.img
[edit] Add to fstab
We don't want Ubuntu to use this as a swap file normally, except when we are hibernating, so add the following to /etc/fstab
/.hibernate.img swap swap noauto,defaults 0 0
[edit] Enable swap file for install
sudo swapon /.hibernate.img
If it all worked so far, if you do a "free -m" you should see the additional swap space added to the total.
[edit] Install uswsusp
Now we can install uswsusp.
sudo apt-get install uswsusp
[The following config file changes are not needed for uwsusp in 8.10 (Easy Peasy 1.0). In 8.10 you will be asked to choose the swap file during install]
Do "sudo nano /etc/uswsusp.conf" and change the file to:
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both resume device = /dev/sda1 compress = y early writeout = y image size = 0 RSA key file = /etc/uswsusp.key shutdown method = platform resume offset = 0
The resume device will be the device where your hibernate file is located, so if your root partition is on /dev/sda2 instead, then resume device will be /dev/sda2 instead of sda1!
The resume offset is where the /.hibernate.img file starts on that device. As you can see, this is wrong, because our /.hibernate.img file is certainly not at position 0. Find out the correct offset by running:
sudo swap-offset /.hibernate.img
Open up /etc/uswsusp.conf and change the resume offset to the number reported by swap-offset.
Now we need to run initramfs to update the boot files. Run:
sudo update-initramfs -k `uname -r` -u
This will update the files for your current running kernel. If you wish to create them for other kernels, man update-initramfs is the place to be.
Before we can run s2disk, we have to set the suid bit, so it gets executed as root every time. Do:
sudo chmod u+s /sbin/s2disk
(If you receive an "no such file or directory" error when trying this it may be that s2disk is in another directory of your system, e.g. /usr/sbin/, execute which s2disk to find out where it is.)
If you run sudo s2disk now, it should hibernate correctly. However there's a couple things left to do still to make it work nicely.
[edit] Configure PM-Utils
[edit] Adjust pm-utils local configuration
The default for this distribution doesn't correctly find the s2disk binary so you need to tell it.
copy distribution defaults to current system config:
sudo cp -a /usr/lib/pm-utils/defaults /etc/pm/config.d/config
Make these changes
sudo nano /etc/pm/config.d/config
- uncomment and/or add these lines and save:
S2DISK_BIN="/sbin/s2disk" HIBERNATE_METHOD="userspace"
[edit] Optimize hooks for eeePC hardware
More information about tweaking what gets loaded and unloaded is here: [1]
(When running the entire system off an SDHC card, Should I add anything special. What about unloading noncritical dissertation to save power during suspend?
What about reloading modules that flake out during suspend or hibernate? )
[edit] Automatically enable and disable "swap"
Now we add an additional script to /usr/etc/pm/sleep.d to switch on and off the hibernation file when we go into and out of suspend.
sudo nano /etc/pm/sleep.d/20swapctl
#!/bin/bash
#/etc/pm/sleep.d/20swapctl
case "$1" in
hibernate|suspend)
swapon /.hibernate.img
;;
thaw|resume)
swapoff /.hibernate.img
;;
*)
;;
esac
Then make sure you make it executable.
sudo chmod +x /etc/pm/sleep.d/20swapctl
[edit] Fix TTY consoles
If you end up with X working, but your terminals (Ctrl-Alt-F1) scrambled, add this to the end of /etc/acpi/resume.d
vbetool vbemode set 3
That will reset the graphics mode and fix the terminals.
The only thing I don't have working yet is the battery meter, it reads 0 after resuming from hibernation. But wifi and sound work.
[edit] Freezing on Asus EEE PC 901
Sporadic freezing on this model can be caused by small hibernation file (./hibrenate.img) – EEE PC 901 has relative big RAM compared to whole "disk" space.
System hangs after writing Snapshotting system to the console.
To partially solve this, create the ./hibernate.img file of at least 1 GB size and change the /etc/uswsusp.conf file to
# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both resume device = /dev/sda1 compress = y early writeout = y image size = 1000000000 RSA key file = /etc/uswsusp.key shutdown method = platform resume offset = x
(Note that you have to replace "x" with your resume image offset.)
Please, try if setting the ./hibernate.img file size to 2 GB will solve this problem completely.
[edit] Freezing on other laptops
This pastebin displays problems for Samsung X360

