Craig's Linux Notes: Hibernate

Last modified: 04/03/2007

I usually keep my desktop running all the time, but the utility bills are getting to me. I would like it to shutdown when I'm not here, and restart quickly.

Contents

Hibernate
My requirements
Implementation Steps for 2.6.10_rc3
Upgrade to 2.6.11.6
Current Status
Using it
Configuration
/etc/hibernate/suspend2.conf
/etc/hibernate/common.conf
Working with HAL
/usr/share/hal/scripts/hal-system-power-suspend
/usr/share/hal/scripts/hal-system-power-hibernate
/etc/hal/hal-system-power-suspend
/etc/hal/hal-system-power-hibernate

Hibernate

"Suspend" means "Suspend to RAM" (STR) which means the entire running system is paused. System memory (RAM) contains the current system state, and is kept powered on. Screen, disks, and processor are powered off.

"Hibernate" means "Suspend to Disk" (STD) which means the entire running system is paused, saved in non-volatile storage (hard disk) and the system is powered off. On restoring power, the system does not boot normally and instead restores the previously saved state. Laptops do this. I want my desktop to do it, too.

See:

My requirements

Implementation Steps for 2.6.10_rc3

  1. emerge kernel 2.6.10_rc3, because the suspend 2 is not available for my current kernel, 2.6.10_rc1.
  2. Download software-suspend-2.1.5.10-for-2.6.10-rc3 patch from softwaresuspend.berlios.de and apply to 2.6.10_rc3 kernel source with apply /usr/src/linux-2.6.10-rc3. Result: "All happy!" message.
  3. Download cx88-video patch from swsusp.sourceforge.net/wiki/KnownIssues. It's a one-liner.
  4. Configure kernel with Software Suspend 2 options.
  5. Build kernel.
  6. Reorganized my main disk and increased swap to 30% more than my available RAM.
  7. emerge hibernate-script for user space control.
  8. emerge acpid for control via power button.
  9. My Gentoo kernel is not using initrd, so I don't have to worry about it.
  10. What does "Swap file support currently broken" mean for the SOFTWARE_SUSPEND_SWAPWRITER kconfig option?
  11. Add "resume2=" option to kernel boot line.
  12. Experiment with acpid for button-press hibernate.
  13. Experiment with power off method: suspend-to-RAM vs. suspend-to-disk.

Upgrade to 2.6.11.6

  1. emerge 2.6.11.6. Configure and make.
  2. Download software-suspend-2.1.8-for-2.6.11 patch. The kernel version doesn't quite match, but it patches successfully. cd /usr/src/linux; ../software-suspend-2.1.8-for-2.6.11/apply
  3. Adjust kernel configuration according to Software Suspend2's HowTo.
  4. Build & install kernel again.

Current Status

Using it

Configuration

/etc/hibernate/suspend2.conf

UseSwsusp2 yes
Reboot no
EnableEscape yes
DefaultConsoleLevel 1
Compressor lzf
Encryptor none
ImageSizeLimit 200
SuspendDevice swap:/dev/hda3
PowerdownMethod 5
ProcSetting userui_program /sbin/suspend2ui_text
FullSpeedCPU yes

/etc/hibernate/common.conf

Verbosity 0
LogFile /var/log/hibernate.log
LogVerbosity 4
Distribution gentoo

SaveClock restore-only

UnmountFSTypes smbfs nfs

ChangeGrubMenu yes

# Use LoadModules to control load order.
UnloadModules tuner cx88xx snd_mixer_oss uhci-hcd ehci-hcd
UnloadBlacklistedModules yes
LoadModules snd_mixer_oss cx8800 tuner huci-hcd ehci-hcd
GentooModulesAutoload yes

RestartServices hotplug alsasound vixie-cron smartd hdparm

SwitchToTextMode yes
XStatus gnome

Working with HAL

HAL = Hardware Abstraction Layer. It's used by Gnome to better organize the software project. Gnome asks HAL to suspend or hibernate, and HAL knows how. The problem is that HAL may get it wrong on systems with suspend2. These changes get it working.

These changes are for HAL 0.5.7. Following versions do things differently.

/usr/share/hal/scripts/hal-system-power-suspend

Insert stuff in green, including changing the following "if" to "elif".
read seconds_to_sleep


#This one overrides them all.
if [ -x "/etc/hal/hal-system-power-suspend" ]; then
/etc/hal/hal-system-power-suspend
RET=$?

#SuSE and ALTLinux only support powersave
elif [ -f "/etc/altlinux-release" ] || [ -f "/etc/SuSE-release" ] ; then

/usr/share/hal/scripts/hal-system-power-hibernate

Insert stuff in green, including changing the following "if" to "elif".
#This one overrides them all.
if [ -x "/etc/hal/hal-system-power-hibernate" ]; then
/etc/hal/hal-system-power-hibernate
RET=$?

#SuSE and ALTLinux only support powersave
elif [ -f /etc/altlinux-release ] || [ -f "/etc/SuSE-release" ] ; then

/etc/hal/hal-system-power-suspend

If HAL doesn't suspend correctly for your system, create this file and configure as needed for your system.
#!/bin/sh
# Suspend method for hal.
# See /etc/hal/scripts/hal-system-power-suspend
# That script is modified to check for this one first.

# Shut down VPN. Can't restore without password.
if ifconfig tun0 &> /dev/null; then
vpnc-disconnect
fi

# Shut down DSL.
# Do not restart on resume: something is not quite ready and network gets in bad state.
if ifconfig ppp0 &> /dev/null; then
/etc/firestarter/firestarter.sh stop
/etc/init.d/net.ppp0 stop
fi

# Suspend now
/usr/sbin/hibernate-ram --force
STATUS=$?

exit $STATUS

/etc/hal/hal-system-power-hibernate

If HAL doesn't suspend correctly for your system, create this file and configure as needed for your system.
#!/bin/sh
# Hibernate method for hal.
# See /etc/hal/scripts/hal-system-power-hibernate
# That script is modified to check for this one first.

# Shut down VPN. Can't restore without password.
if ifconfig tun0 &> /dev/null; then
vpnc-disconnect
fi

# Shut down DSL.
# Do not restart on resume: something is not quite ready and network gets in bad state.
if ifconfig ppp0 &> /dev/null; then
/etc/firestarter/firestarter.sh stop
/etc/init.d/net.ppp0 stop
fi

# Hibernate now
/usr/sbin/hibernate --force --kill
STATUS=$?

exit $STATUS
Copyright © 2004-2007 Craig Lawson
Index no-thank-you-spam-i-am@i-hate-spam.spam.spam Document made with Nvu