Thursday, April 17, 2008

Hibernation

Spent the extra hour and got hibernation working last night; here are some basic notes on the experience.

The only truly working suspend-to-disk implementation is Suspend2 AKA Tux-On-Ice (TOI), available as a kernel path from http://www.tuxonice.net/downloads .

Download and path the kernel as follows:

cd /usr/src/linux-2.6.24-2
patch -p1 < /tmp/tuxonice-3.0-rc5-for-2.6.24.patch


Make config/menuconfig/xconfig and ensure the following options are set:

CONFIG_TOI_CORE=y

# Image Storage (you need at least one allocator)
CONFIG_TOI_FILE=y
CONFIG_TOI_SWAP=y
CONFIG_TOI_DEFAULT_PRE_HIBERNATE=""
CONFIG_TOI_DEFAULT_POST_HIBERNATE=""
CONFIG_TOI_CRYPTO=y
CONFIG_TOI_USERUI=y
CONFIG_TOI_USERUI_DEFAULT_PATH="/usr/lib/suspend2-userui/suspend2ui_fbsplash"
# CONFIG_TOI_KEEP_IMAGE is not set
CONFIG_TOI_REPLACE_SWSUSP=y
# CONFIG_TOI_CLUSTER is not set
CONFIG_TOI_CHECKSUM=y
CONFIG_TOI_DEFAULT_WAIT=25
CONFIG_TOI_DEFAULT_WAIT=25
# CONFIG_TOI_PAGEFLAGS_TEST is not set
CONFIG_TOI=y
...
CONFIG_CRYPTO_LZF=y


Rebuild/reinstall the kernel. If you use an initrd or initramfs, a new one must be made according to the instructions at:
http://wiki.tuxonice.net/DistroAndHardwareSetup/Ubuntu_Gutsy_Gibbon

Note that the initramfs files may exist both in /etc/initramfs-tools and /usr/share/initrafms-tools ; in this case, create the file suspend2_do_resume in /etc/initramfs-tools . I had to fill my /etc/initramfs-tools tree with files from the /usr/share/initramfs-tools tree; it now looks like this:

/etc/initramfs-tools/update-initramfs.conf
/etc/initramfs-tools/hook-functions
/etc/initramfs-tools/init
/etc/initramfs-tools/hooks/console_tools
/etc/initramfs-tools/hooks/console_setup
/etc/initramfs-tools/hooks/usplash
/etc/initramfs-tools/hooks/thermal
/etc/initramfs-tools/hooks/kernelextras
/etc/initramfs-tools/hooks/uswsusp
/etc/initramfs-tools/hooks/udev
/etc/initramfs-tools/initramfs.conf
/etc/initramfs-tools/scripts/init-premount/udev
/etc/initramfs-tools/scripts/local-premount/suspend2_do_resume
/etc/initramfs-tools/scripts/local-premount/uswsusp
/etc/initramfs-tools/scripts/nfs
/etc/initramfs-tools/scripts/functions
/etc/initramfs-tools/scripts/nfs-top/udev
/etc/initramfs-tools/scripts/local
/etc/initramfs-tools/scripts/init-top/console_setup
/etc/initramfs-tools/scripts/init-top/framebuffer
/etc/initramfs-tools/scripts/init-top/usplash
/etc/initramfs-tools/scripts/init-top/all_generic_ide
/etc/initramfs-tools/scripts/init-bottom/udev
/etc/initramfs-tools/conf.d/resume
/etc/initramfs-tools/modules

The initramfs is rebuilt with the command
update-initramfs -u -k `uname -r`

The following config settings work fine:

/etc/hibernate/suspend2.conf
UseSuspend2 yes
Reboot no
EnableEscape yes
DefaultConsoleLevel 1
Compressor lzf
Encryptor none
SuspendDevice swap:/dev/sda2
FullSpeedCPU yes


/etc/hibernate/common.conf :
Verbosity 1
LogFile /var/log/hibernate.log
LogVerbosity 4
LogTimestamp yes
HibernateVT 15
Distribution debian # (or fedora/gentoo/mandrake/redhat/slackware/suse)
XDisplay :0
SaveClock restore-only
ChangeGrubMenu yes
GrubMenuFile /boot/grub/menu.lst
AlternateGrubMenuFile /boot/grub/menu-suspended.lst
BackupGrubMenuFile /boot/grub/menu.lst.hibernate.bak
UnloadBlacklistedModules yes
LoadModules auto
SwitchToTextMode yes

Note that /boot/grub/menu.lst must be copied to menu-suspended.lst, which will be the boot menu displayed when the system is hibernating. Add the line "resume=swap:/dev/sda2" (or whatever your swap partition is) to the default kernel boot option, and add a kernel boot option with the No Resume (param is "noresume") option set for easy recovery in case of failure.

The command "hibernate -v3" should now susend the system to disk.

Apropos of nothing: Ubuntu has the default language set to require UTF-8 (e.g. en_US.UTF-8), which really screws up compiler output, man pages, and so forth (in particular, single and double quotes appear as f’s) in non-Unicode terminals (e.g. Aterm, Eterm). One could switch to a unicode terminal, e.g.
rxvt-unicode -bg black -fg orange -fade 25 -fn 'xft:Courier 10 Pitch-12'
...but setting the language to C in ~/.bashrc (export LANG=C) lets you keep using your favorite terminal.

No comments:

Post a Comment