Gentoo Wiki ArchivesGentoo Wiki

Hibernate-script

Note: This page was copied from the TuxOnIce page. The information should probably be externalized to here to reduce the length and size there.

Hibernate-script is supplied by the TuxOnIce guys and is the default Gentoo hibernate script. The script execution is modified through a configuration file that is detailed in man hibernate.conf. Hibernate-script by far has better documentation and is much more mature than it's competitor, pm-utils. If something goes wrong, this is the one that is easier to fix, but takes slightly more work to set up. Though hibernate-script doesn't have the hal integration of pm-utils, it works very well in a terminal only environment and has less dependencies.

Contents

Setup and Installation

  1. First you install the sys-power/hibernate-script package.
    # emerge hibernate-script
  2. Add the hibernate-cleanup service to the boot startup level. This will invalidate any stale suspend images from swap partition and TuxOnIce filewriter files.
    # rc-update add hibernate-cleanup boot
  3. If you have an Ati or nVidia card with binary drivers, some extra settings will be required. You can add these to /etc/hibernate/common.conf. The recommendations are:
    • For nVidia with binary driver:
      ProcSetting extra_pages_allowance 0 or
      ProcSetting extra_pages_allowance 7200 for onboard Geforce
    • For Ati with binary driver:

      ProcSetting extra_pages_allowance 5000 or
      ProcSetting extra_pages_allowance 7500 for fglrx

    nVidia cards with binary drivers will also have to add a line to the devices section in xorg.conf.

    Option "NvAGP" "1"
    
  4. Try out the new hibernate and hibernate-ram commands as root to see if they work correctly.
  5. If one didn't work, consult the terminal output or log at /var/log/hibernate.log for clues why. Fixing hibernation problems usually comes down to unloading problematic modules, restarting confused services, or hacks to fix misbehaving video cards. Check out the trouble shooting section below and the official trouble shooting section of TuxOnIce for ways to deal with the errors.
  6. If you dual boot or have network drives, consider setting them to automatically unmount on hibernation to avoid file corruption with the command Unmount drivename1 drivename2... in /etc/hibernate/hibernate.conf.
  7. Programs that use Hal for hibernation like Gnome's or KDE's will require some hacks to use hibernate-script. When Hal attempts to call pm-utils, the below script will rewrite the hal scripts so they point at hibernate-script. For more information, check out the pm-utils wiki's Advanced Configuration section.
    File: /etc/pm/sleep.d/01hibernateScripts
    #!/sbin/bash
    
    ECHO="/bin/echo -e"
    MV="/bin/mv"
    KILLALL="/usr/bin/killall"
    CHVT="/usr/bin/chvt"
    CHMOD="/bin/chmod"
    
    #Variables that change depending on hibernate or suspend
    case $1 in
        hibernate)
            HAL_SCRIPT="/usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux"
            HIBERNATE="/usr/sbin/hibernate"
            PM="pm-hibernate"
            ;;
        suspend)
            HAL_SCRIPT="/usr/lib/hal/scripts/linux/hal-system-power-suspend-linux"
            HIBERNATE="/usr/sbin/hibernate-ram"
            PM="pm-suspend"
            ;;
        *)
            HAL_SCRIPT=""
            HIBERENATE=""
    		PM=""
            ;;
    esac
    
    #Create the data for the file
    LN01="#!/bin/bash"
    LN02="if [ -x \"${HIBERNATE}\" ] ; then"
    LN03="\t${HIBERNATE}"
    LN04="\tRET=\$?"
    LN05="else"
    LN06="\techo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2"
    LN07="\techo No hibernate script found >&2"
    LN08="\texit 1"
    LN09="fi"
    LN10="#Refresh devices as a resume can do funny things"
    LN11="for type in button battery ac_adapter"
    LN12="do"
    LN13="\tdevices=\`hal-find-by-capability --capability \$type\`"
    LN14="\tfor device in \$devices"
    LN15="\tdo"
    LN16="\t\tdbus-send --system --print-reply --dest=org.freedesktop.Hal \\"
    LN17="\t\t\t  \$device org.freedesktop.Hal.Device.Rescan"
    LN18="\tdone"
    LN19="done"
    LN20="exit \$RET"
    
    case $1 in
        hibernate|suspend)
    	#Back up the old script
            ${MV} ${HAL_SCRIPT} ${HAL_SCRIPT}.original
    
    	#Create the new script
            ${ECHO} ${LN01} >> ${HAL_SCRIPT}
            ${ECHO} ${LN02} >> ${HAL_SCRIPT}
            ${ECHO} ${LN03} >> ${HAL_SCRIPT}
            ${ECHO} ${LN04} >> ${HAL_SCRIPT}
            ${ECHO} ${LN05} >> ${HAL_SCRIPT}
            ${ECHO} ${LN06} >> ${HAL_SCRIPT}
            ${ECHO} ${LN07} >> ${HAL_SCRIPT}
            ${ECHO} ${LN08} >> ${HAL_SCRIPT}
            ${ECHO} ${LN09} >> ${HAL_SCRIPT}
            ${ECHO} ${LN10} >> ${HAL_SCRIPT}
            ${ECHO} ${LN11} >> ${HAL_SCRIPT}
            ${ECHO} ${LN12} >> ${HAL_SCRIPT}
            ${ECHO} ${LN13} >> ${HAL_SCRIPT}
            ${ECHO} ${LN14} >> ${HAL_SCRIPT}
            ${ECHO} ${LN15} >> ${HAL_SCRIPT}
            ${ECHO} ${LN16} >> ${HAL_SCRIPT}
            ${ECHO} ${LN17} >> ${HAL_SCRIPT}
            ${ECHO} ${LN18} >> ${HAL_SCRIPT}
            ${ECHO} ${LN19} >> ${HAL_SCRIPT}
            ${ECHO} ${LN20} >> ${HAL_SCRIPT}
    
    	#Finish up
            ${CHMOD} +x ${HAL_SCRIPT}
            ${KILLALL} ${PM}
            ${CHVT} 7
            ${HIBERNATE}
            ;;
    esac
    

When finished here, you can continue to the optional Advanced Configuration section.

Advanced Configuration

man hibernate.conf is the first place you should look for general information. You can insert those directives in the configuration files in /etc/hibernate/. The three files you should pay attention to are:

Some of the more difficult things to setup have guides below that may be helpful.

Suspend to More than One Swap Partition/File

First you need a working TuxOnIce setup. It doesn't matter what swap partition/file you use, just choose one. Then use swapon to temporarily add additional swap partitions/files like below.

# swapon /etc/dev/sda1
# swapon /swapfile

It really is this simple. Since swapon is not permanent, it is a lot easier to just add the partitions and files to your fstab file instead.

File: /etc/fstab
/dev/sda2   none   swap   sw 0 0
/swapfile   none   swap   sw 0 0

If you want to learn how to make swapfiles, use the first two steps of the Using a Swapfile section

Using a Swapfile

Using a swapfile instead of a swap partition is handy because you can change the size and location depending on your needs and whims. The method described here creates a special swap partition that TuxOnIce activates and deactivates as needed. This would be most useful for people who do not have any swap partition at all and want to keep the system from casually using the swapfile. Check out the Suspend to More than One Swap Partition/File section for more information on the alternative. Since we edit the bootloader at the end, you might want to review Configuring the Bootloader from the Gentoo Handbook.

  1. The first step is to create the file. The file we use here will be at the location /swapfile and 600MB in size.
    # dd if=/dev/zero of=/swapfile bs=1M count=600
    
  2. What we have now is a 600MB contiguous file containing only zeros. To apply a swap filesystem, we use the mkswap command on our swapfile.
    # mkswap /swapfile
    
  3. We now need the location of the swap file to feed to the bootloader. One way to do this is to temporarily activate the swapfile for the system and then ask TuxOnIce. To activate the swapfile, we use the swapon command.
    # swapon /swapfile
    
  4. Now we ask TuxOnIce for the location by using cat on /sys/power/tuxonice/swap/headerlocations. Notice how it outputs the location of all available swap partitions/files to the system.
    # cat /sys/power/tuxonice/swap/headerlocations
    For swap partitions, simply use the format: resume=swap:/dev/hda1.
    For swapfile `/swapfile`, use resume=swap:/dev/sda3:0xf7778.
    
  5. Do you see the last line that popped out? It has the exact information we need for our bootloader. It should be appended to the end of the kernel lines in grub.conf with the resume variable.
    File: /boot/grub/grub.conf
    kernel /boot/vmlinuz root=/dev/sda2 resume=file:/dev/sda3:0xf7778
    
  6. Reboot and use dmesg | grep TuxOnIce to figure out if TuxOnIce recognizes the swapfile with no problems.

Using a Dedicated File

Using a dedicated file is very similar to using a swapfile with many of the same strengths. It differs in that you can't easily use groups of dedicated files for TuxOnIce storage. Since we edit the bootloader at the end, you might want to refresh on the procedure from the Gentoo Handbook's Configuring the Bootloader section.

  1. First you need to create your file. The basic layout has a TuxOnIce header with trailing zeros until the file reaches the desired size. So first echo TuxOnIce to your desired location. Here we use /suspend_file.
    # echo TuxOnIce > /suspend_file
    
  2. Pack Zeros onto the file until it reaches the desired length using the dd command. In this case, the file will be 600mbs. Notice how we are piping the output of dd instead of writing directly to the file. This is to preserve the "TuxOnIce" header. Your screen should look something like below when done with this step.

    # dd if=/dev/zero bs=1M count=600 >> /suspend_file
    600+0 records in
    600+0 records out
    629145600 bytes (629 MB) copied, 26.7159 s, 23.5 MB/s
    
  3. Now that you have a file with the correct layout, we need to figure out it's exact position on the hard drive for TuxOnIce to be able to use it on bootup. As a handy trick, we can get TuxOnIce to tell us the information we need. First point TuxOnIce at the file by echoing the path to /sys/power/tuxonice/file/target.
    # echo /suspend_file > /sys/power/tuxonice/file/target
    
  4. Next, TuxOnIce will tell us the location of the file is by using cat on the file at /sys/power/tuxonice/resume.
    # cat /sys/power/tuxonice/resume
    file:/dev/sda2:0xdc008
    
  5. Do you see that line that popped out? This is the exact information we need for our bootloader. It should be appended to the end of the kernel lines in grub.conf with the resume variable.
    File: /boot/grub/grub.conf
    kernel /boot/vmlinuz root=/dev/sda2 resume=file:/dev/sda2:0xdc008
    
  6. Reboot and use dmesg | grep TuxOnIce to figure out if TuxOnIce recognizes the dedicated file with no problems.

Swap on LV/dm-crypt

Initrd/initramfs with TuxOnIce

If this setup is done incorrectly, you will most likely suffer from filesystem corruption, so be careful. To use initramfs with TuxOnIce you will need to edit your linuxrc (or init) script to contain:

echo 1 > /sys/power/tuxonice/do_resume

It must be inserted AFTER the script mounts /sys, but BEFORE the script mounts your filesystem. The TuxOnIce website has additional documentation on using an initrd/initramfs with TuxOnIce.

Note: sys-kernel/genkernel-3.4.9 contains support for TuxOnIce by way of calling function tuxonice_resume in /usr/share/genkernel/generic/initrd.scripts from /usr/share/genkernel/generic/linuxrc. The function is called before even the correct root device is determined so it should be safe. This function should also behave correctly if the noresume kernel parameter is used. Note that the linuxrc script checks for real_resume in the list of kernel parameters before calling tuxonice_resume. The actual contents of real_resume are currently ignored but it must be set to a non-zero value. See Gentoo Bug 220913

Troubleshooting

The script on the Hal quirks website can help you figure out what combinations of hacks below you may need. Some services can become confused when coming out of suspend. In that case restarting them can be the easy answer. If that doesn't fix it, it's probably a module problem.

Modules

Have a look at /etc/hibernate/blacklisted-modules to get an idea what should be compiled as modules (it's not that long.) But keep in mind this list is not all inclusive by any means. If you have an idea who the offender is and they are already compiled as modules, edit common.conf to unload and reload those modules as appropriate:

File: /etc/hibernate/common.conf
UnloadModules sd_mod
LoadModules sd_mod

Modules can also be autoloaded from the list at /etc/modules.autoload.d/kernel-2.6 using GentooModulesAutoload <boolean> and unloaded with UnloadBlacklistedModules <boolean>.

Services

A lot of times the simplest fix is to restart the service with RestartServices in hibernate's config files. If it doesn't fix it, you may actually be dealing with a module issue and not a service issue.

RestartServices acpid
If your laptop suspends when the lid is closed, it might double suspend because the opening of the lid triggers the suspend process again try restarting this.
RestartServices alsasound
If your soundcard isn't able to resume on its own try restarting this.
RestartServices hs
If loading the hsfmodem drivers lead to segfaults try restarting this.
RestartServices ntp-client
If your clock goes out of sync, to resync it on resume try restarting this.
RestartServices NetworkManager NetworkManagerDispatcher
If TuxOnIce hangs on atomic restore randomly try restarting these.

Video Adapters

Since the video adapter driver cannot be unloaded when suspending, it must function properly during this operation. Check out the TuxOnIce Hardware Compatibility List to get an idea what to expect. The farther you read down the list, the less recommended and more equivical the fix is.

Other

Not yet Written

Links

Not yet written.

Retrieved from "http://www.gentoo-wiki.info/Hibernate-script"

Last modified: Fri, 10 Oct 2008 19:59:00 +1100 Hits: 20,682

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.