Hibernate-script

From ArchWiki
Revision as of 18:48, 6 June 2006 by Patrokov (Talk | contribs) (Created first draft of article)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This article will describe how to Suspend a computer (usually a laptop) to Disk. This means that all programs in use will be saved to the hard drive and power will completely shut down. This article uses suspend2 software and does not cover all options within suspend2. See the Suspend2 website for complete documentation.

Obtaining Suspend2

Suspend2 is a kernel patch and set of scripts and UI components. They are available as part of the -beyond kernel patchset conveniently available through pacman. You will also need ACPI.

# pacman -S kernel26beyond acpi

Note that if you are not currently using the beyond patchset you may need to also download the -beyond version of certain drivers, particularly wireless card and video drivers. If you have custom compiled modules, you will need to recompile them. On my Compaq Presario 2715US laptop I needed to download ndiswrapper-beyond and ati-fglrx-beyond packages. You can search for all precompiled -beyond modules with:

# pacman -Ss beyond

I suggest that you make sure all of your -beyond drivers are working together properly before configuring Suspend2. Note that the precompiled vmlinuz26beyond kernel uses initramfs instead of the traditional initrd, so you will need to change your boot script accordingly.

Configuring Suspend2

In order to use Suspend2, you need to do two things

  1. Edit your Bootloader script (/boot/grub/menu.lst)
  2. Edit your /etc/hibernate/hibernate.conf file

Editing the Grub menu.lst

Before your can use the suspend function, you need to boot your computer with the "resume2" parameter. The examples below assume that you use the precompiled -beyond kernel and initramfs.

menu.lst: Boot with this option before trying to Suspend for the first time!

title ArchLinux Fresh Boot/Restore
kernel /boot/vmlinuz26beyond root=/dev/hda2 resume2=swap:/dev/hda3
initrd /boot/initramfs-beyond.img

This assumes that you installed Archlinux onto the second hard drive partition, and that your swap partition is the third. (Windows would presumably still be on the first partition, or perhaps the first partition is /boot.) Failure to include the initrd statement will result in a kernel panic and failed boot.

Editing /etc/hibernate/hibernate.conf

Make sure the following lines are uncommented and appropriately configured

UseSuspend2 yes
Reboot no
EnableEscape yes
DefaultConsoleLevel 1
Compressor lzf
Encryptor none

Uncomment the lines for any filesystems that have the potential to change while your computer is suspended. Resume will then remount them when you resume. Failure to follow this could result in filesystem corruption.

### filesystems
# Unmount /nfsshare /windows /mnt/sambaserver
# UnmountFSTypes smbfs nfs
# UnmountGraceTime 1
# Mount /windows

Do not uncomment the Grub lines below, as it will work once or twice, but after two or three suspend/resumes it will hang on resuming and corrupt your menu.lst file causing you to have to try and remember how to boot from a "grub>" prompt--not fun.

### grub
#ChangeGrubMenu yes
#GrubMenuFile /boot/grub/menu.lst
#AlternateGrubMenuFile /boot/grub/menu-suspended.lst
#BackupGrubMenuFile /boot/grub/menu.lst.hibernate.bak

You can have Suspend2 unload problematic modules. The blacklisted modules list is found in the /etc/hibernate directory. I did not change the settings here or in the blacklisted modules.

### modules
# UnloadModules snd_via82cxxx usb-ohci
# UnloadAllModules yes
UnloadBlacklistedModules yes
LoadModules auto
# LoadModulesFromFile /etc/modules

These settings can be used to customize your hibernation and resume messages.

### xhacks
SwitchToTextMode yes
# UseDummyXServer yes

### xstatus
## This can be set to gnome, kde or x:
# XStatus gnome
# XSuspendText Preparing to suspend...
# XResumeText Resuming from suspend...
## When using XStatus x, and you have xosd installed:
# XosdSettings --font -misc-fixed-medium-r-semicondensed--*-120-*-*-c-*-*-* --colour=Green --shadow 1 --pos bottom --align center --offset 50

Using Suspend and Resume

Now that you've installed the necessary software and edited the configuration files, you need to reboot once using the resume2 enabled boot option from your Grub menu. You can then try hibernating with the hibernate script.

# hibernate

If all goes well, you should be able to resume using the same Grub menu selection. If you make that option the default for Grub, you will always default to resuming if a resume image is available. It is recommended that you test the suspend/hibernate from a text console first and then once you have confirmed that it works try it from within X.

Once you've done your testing, you will want to make it so that regular users can use the hibernate script. You can either use sudo or you can use desktop specific functions such as making a menu item with the command "kdesu hibernate" (KDE only). Unfortunately, using kdesu still requires the root password, so it's probably better to go with sudo.

Miscellaneous

  1. Suspend2 also includes a suspend to RAM function which I have not explored yet.
  2. There is a good Gentoo wiki article that covers a lot of the same material.