Hibernate-script
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
- First you install the sys-power/hibernate-script package.
# emerge hibernate-script
- 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
- 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"
- For nVidia with binary driver:
- Try out the new hibernate and hibernate-ram commands as root to see if they work correctly.
- 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.
- 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.
- 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:
- /etc/hibernate/suspend2.conf which runs on both hibernate and suspend.
- /etc/hibernate/disk.conf which runs only on hibernate.
- /etc/hibernate/ram.conf which runs only on suspend.
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.
- 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
- 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
- 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
- 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.
- 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
- 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.
- 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
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
- 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
- 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
- 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
- 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.
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.
- ACPI
- 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.
- Audio
- RestartServices alsasound
- If your soundcard isn't able to resume on its own try restarting this.
- Winmodem
- RestartServices hs
- If loading the hsfmodem drivers lead to segfaults try restarting this.
- Clock
- RestartServices ntp-client
- If your clock goes out of sync, to resync it on resume try restarting this.
- Network Manager
- 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.
- Official versus Free
The official nVidia and Ati drivers only come in binary blob form, but unlike the free versions support 3D acceleration. If the current version of the official drivers don't work for you with the below hacks, the open versions may be your only option. You may want to brush up on the official Gentoo Hardware Acceleration Guide. - SwitchToTextMode and UseDummyXServer
These are some basic tweaks that can be added to /etc/hibernate/common.conf. The combination of SwitchToTextMode and UseDummyXServer fixes poor graphics performance after resume for some users.- SwitchToTextMode <boolean> If your X driver is unable to resume properly, you can try switching to a text console first by setting this to yes.
- SwitchToTextModeOnResume <boolean> Use this to, on resume, switch to a text console and back. Some X drivers need this to properly resume.
- UseDummyXServer <boolean> Some X drivers can be reinitialised by launching a dummy X server after resuming to restore the state of the graphics card. Set this to yes to do so.
- VbetoolPost
One possible fix is to enable Vbetool. It runs real-mode video BIOS code to alter hardware state. First you have to install it.# emerge vbetool
Add to the video device section in your xorg.conf file
File: /etc/X11/xorg.conf "VBERestore" "true"
and last add it to your hibernate.conf
File: /etc/hibernate/hibernate.conf EnableVbetool true VbetoolPost true
- Bios settings
Sometimes you need your bios to step in and help reinitialize the video hardware. There are basically three combinations this can be done in when appending the command to your kernel line in grub.confFile: /boot/grub/grub.conf kernel /boot/kernelname root=/dev/hda1 acpi_sleep=s3_bios kernel /boot/kernelname root=/dev/hda1 acpi_sleep=s3_mode kernel /boot/kernelname root=/dev/hda1 acpi_sleep=s3_bios,s3_mode
- NUMA and/or agpart
For some nVideo cards, disabling NUMA and/or agpgart in the kernel will fix issues. Unfortunately, graphics will also run slow.
Other
Not yet Written
Links
Not yet written.
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.
