Gentoo Wiki ArchivesGentoo Wiki

Pm-utils

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

For desktop environments that utilize the Hal framework, like Gnome and KDE, usage of hibernate-script has become depreciated in favor of pm-utils. Short for Power Management Utilities, pm-utils does most of the needed legwork outside of the kernel. This package gives you three commands to play with once installed: pm-hibernate, pm-suspend and pm-suspend-hybrid. One of the strengths of pm-utils is Hal intermediates the hibernation commands, allowing user usage without unnecessary fuss with permissions. A prerequisite to this page is setting up a form of suspend support in the kernel, such as TuxOnIce.

Contents

Installation and Setup

  1. Make sure the acpi USE flag is enabled universally. sys-power/pm-utils should be installed automatically.
  2. Log in as root in a terminal and try the pm-hibernate and pm-suspend commands to see if they work without errors.
  3. If something went wrong, check the log at /var/log/pm-suspend.log for clues. Usually it is a module or video card problem. Check out the troubleshooting section below for ideas. pm-utils has a common errors section at Freedesktop.org.
  4. When done, continue to the Advanced Configuration section.

Advanced Configuration

Advanced configuration of pm-utils can be much more pain in the butt than hibernate-script. If you're uncomfortable with bash, you may want to check out a tutorial to brush up. To make pm-utils do anything fancy, you're going to have to play with the its hooks functionality by adding some scripts to /etc/pm/sleep.d.

Basically, all executable scripts in the /etc/pm/sleep.d directory are run in alphabetical order when hibernate/suspend is called. When returning from hibernate/suspend, all files in the directory are called in reverse alphabetical order. If you name your hook the same name as one of the predefined hooks in /usr/lib/pm-utils/sleep.d, it will override it with your own. This can be good or bad. An example custom hook skeleton file is below.

File: /etc/pm/sleep.d/50custom
#!/bin/bash
case $1 in
   hibernate)
       echo "Hibernating"
       ;;
   suspend)
       echo "Suspending"
       ;;
   thaw)
       echo "Returning from hibernation"
       ;;
   resume)
       echo "Returning from suspend"
       ;;
esac

You can test your custom hook without actually hibernating/suspending by calling it with the correct argument. For example, /etc/pm/sleep.d/50custom suspend. I hope this was enough to get you started in the right direction. Below are some examples that you may find useful.

Change TuxOnIce Kernel Variables

Unlike hibernate-script, your only choice for forcing some settings will be by echoing some strings directly at files in /sys/power/tuxonice from one of your custom hooks. For example, from the command line you can use the line below to temporarily change the userui variable without recompiling the kernel.

echo "/sbin/tuxoniceui_text" > /sys/power/tuxonice/user_interface/program

Thus you could make a custom hook with this code.

#!/bin/bash
case $1 in
   hibernate|suspend)
       echo "/sbin/tuxoniceui_text" > /sys/power/tuxonice/user_interface/program
esac

If you think one of the special fixes of hibernate-script may apply to you like extra_pages_allowance for you video card and pm-utils doesn't do it automatically, this is how you can force the setting.

Restarting Services

Restarting services can be accomplished with:

#!/bin/bash
case $1 in
   hibernate|suspend)
       /etc/init.d/serviceName stop
   thaw|resume)
       /etc/init.d/serviceName start
esac

Unmounting Automounted Drives

Unmounting all automounted drives on hibernation or suspend can be done with:

#!/bin/bash
case $1 in
   hibernate|suspend)
      for drive in $( ls /media/ ); do
         gnome-umount -bnp ${drive} > /dev/null
         if [ $? -eq 0 ]; then
            echo "Unmounting ${drive} successful"
         else
            echo "Unmounting ${drive} failed"
         fi
   done
esac

Hibernate Script through Power Management Utilities

Making hal use the hibernate scripts isn't so much difficult as pain in the butt. This is because whenever a new update is emerged, the custom scripts get overwritten. One way around this is to create a hook for pm-utils that reapplies the changes to the hal scripts whenever it is run. The idea is this script would only get run when hal is not using the hibernate scripts.

File: /etc/pm/sleep.d/01hibernateScripts
#!/bin/bash

HAL_HIBERNATE="/usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux"
HAL_SUSPEND="/usr/lib/hal/scripts/linux/hal-system-power-suspend-linux"

case $1 in
    hibernate)
        /bin/mv ${HAL_HIBERNATE} ${HAL_HIBERNATE}.original
        /bin/echo "#!/bin/bash"              >> ${HAL_HIBERNATE}
        /bin/echo "/usr/sbin/hibernate"      >> ${HAL_HIBERNATE}
        /bin/echo "exit \$?"                 >> ${HAL_HIBERNATE}
        /bin/chmod +x ${HAL_HIBERNATE}
        /usr/bin/killall pm-hibernate
        /usr/bin/chvt 7
        /usr/sbin/hibernate
        ;;
    suspend)
        /bin/mv ${HAL_SUSPEND} ${HAL_SUSPEND}.original
        /bin/echo "#!/bin/bash"              >> ${HAL_SUSPEND}
        /bin/echo "/usr/sbin/hibernate-ram"  >> ${HAL_SUSPEND}
        /bin/echo "exit \$?"                 >> ${HAL_SUSPEND}
        /bin/chmod +x ${HAL_SUSPEND}
        /usr/bin/killall pm-suspend
        /usr/bin/chvt 7
        /usr/sbin/hibernate-ram
        ;;
esac

The the script above automatically makes a backup of the previous script, but it is usually easier to just reinstall hal if you want to reset it to the default settings and then delete the custom hook.

# emerge --oneshot hal
# rm /etc/pm/sleep.d/01hibernateScripts

Troubleshooting

There is a script that may help you figure out exactly what to do here at freedesktop. Screens that stay black or becomes glitchy during resume are strong signs of video adapter problems. Some services can become confused when coming out of suspend. In that case you should try simply restarting them. If that doesn't fix it, it's probably a module problem.

Modules

If you figured out a module is causing a problem, you need to unload/load it during suspend/resume. Of course there is the prerequisite that the driver must be compiled as a module in the kernel first. Once that is done, create a file like the one below.

File: /etc/pm/config.d/modules
#the list of modules to be unloaded before suspend
SUSPEND_MODULES="modulename1 modulename2 modulename3"

Services

Restarting services automatically can be accomplished with the hooks functionality of sys-power/pm-utils. Since the file is basically a bash script, you just just have to add /etc/init.d/servicename restart to the appropriate places. Please go to the Advanced Configuration section for more information. If restarting the service doesn't fix it, you're likely dealing with a problematic module.

Video Adapters

General video adapter quirks should be detected by sys-apps/hal. If not, you can try the script at freedesktop to get some ideas what might be going wrong or use pm-suspend --help to get a list of all possible quirks you can try out. To apply the quirk permanently, look at the documentation at freedesktop to add your machine to the quirk list of Hal. The --quirk-radeon-off quirk requires app-laptop/radeontool to be installed and the --quirk-vbe quirks require sys-apps/vbetool to be installed.

Other

Not written yet.

Links

Retrieved from "http://www.gentoo-wiki.info/Pm-utils"

Last modified: Thu, 09 Oct 2008 22:43:00 +1100 Hits: 25,890

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