Difference between revisions of "Pm-utils"

From ArchWiki
Jump to navigation Jump to search
(archive page)
 
(278 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Power management (English)]]
+
#redirect [[ArchWiki:Archive]]
[[Category:HOWTOs (English)]]
+
[[Category:Archive]]
 
 
{{Article summary start}}
 
{{Article summary heading|Available Languages}}
 
{{i18n_entry|English|Pm-utils}}
 
{{i18n_entry|简体中文|Pm-utils 电源管理}}
 
{{Article summary end}}
 
 
 
== Introduction ==
 
'''pm-utils''' is the new suspend and powerstate setting framework.  It is designed to replace such scripts as those provided by the <tt>powersave</tt> package.
 
 
 
It is usually used by HAL to execute the various hacks needed to work around bugs in drivers and subsystems that are not yet aware of suspend. It is easily extensible by putting custom hooks into a directory, which can either be done by the system administrator or those hooks can be part of a package, especially if this package needs special attention during a system suspend or power state transition.
 
 
 
Used in conjunction with the [[Cpufrequtils]] package, notebook (and desktop) owners are provided with a complete power management suite.
 
 
 
== Installation ==
 
 
 
The <tt>pm-utils</tt> package is now available from the [http://www.archlinux.org/packages/search/?q=pm-utils Extra] repository:
 
# pacman -S pm-utils
 
 
 
== Basic Configuration ==
 
=== Hibernation (suspend2disk) ===
 
In order for suspend2disk (hibernate) to work, we need to edit ''/boot/grub/menu.lst'' as root and add '''resume=/path/to/swap/drive''' (e.g. /dev/sda2) to the kernel options, for example:
 
# (0) Arch Linux
 
title  Arch Linux
 
root  (hd0,0)
 
kernel /vmlinuz26 root=/dev/sda3 '''resume=/dev/sda2''' ro vga=0
 
initrd /kernel26.img
 
 
 
When the machine is placed into hibernation, it will now move all data from RAM to the swap partition... you ''did'' make your swap partition large enough to hold your RAM data, right?
 
 
 
Even if your swap partition is smaller than RAM, you still have a big chance in hibernating successfully. According to [http://www.mjmwired.net/kernel/Documentation/power/interface.txt kernel documentation], ''/sys/power/image_size controls the size of the image created by the suspend-to-disk mechanism'', which has a default value of 512M. ''The suspend-to-disk mechanism will do its best to ensure the image size will not exceed that number.'' You may either decrease it due to a small swap partition or increase it in purpose of possible hibernation speed up.
 
 
 
=== Execute suspend/hibernate without root password ===
 
Because the <tt>pm-utils</tt> scripts must be run as root, you may want to make the scripts accessible to normal users by running sudo without the root password. To do so, edit the <tt>/etc/sudoers</tt> file with visudo, for example:
 
# visudo
 
 
 
add the following lines, replacing ''username'' with your own:
 
''username''  ALL = NOPASSWD: /usr/sbin/pm-hibernate
 
''username''  ALL = NOPASSWD: /usr/sbin/pm-suspend
 
save and exit visudo
 
 
 
Or you can enable it for a group, using the following lines, of course replacing ''group'':
 
''%group''  ALL = NOPASSWD: /usr/sbin/pm-hibernate
 
''%group''  ALL = NOPASSWD: /usr/sbin/pm-suspend
 
 
 
You can now run the scripts without a password by simply typing:
 
$ sudo pm-hibernate
 
or
 
$ sudo pm-suspend
 
 
 
Also, add yourself to the ''power'' group so that way using things like applets to do suspend will work. If you do not do this, when you try to use suspend though things like the gnome shutdown applet to suspend/hibernate your computer will just play a very annoying loud triple beep and lock the screen.
 
 
 
# gpasswd -a ''username'' power
 
 
 
You should now be able to use gnome power management tools (and kpowersave?) to automatically suspend/hibernate when doing things like closing the laptop lid, running low on battery power etc...
 
 
 
== Advanced Configuration ==
 
The main configuration file is '''<tt>/usr/lib/pm-utils/defaults</tt>'''. You ''should not edit this file'', since after a package update it might be overwritten with the default settings. Put your config file into '''<tt>/etc/pm/config.d/</tt>''' instead.
 
You can just put a simple text file with
 
SUSPEND_MODULES="button uhci_hcd"
 
named "modules" or "config" into <tt>/etc/pm/config.d</tt> and it will override the settings in the system wide configuration file.
 
 
 
=== Available Variables for use in config files ===
 
SUSPEND_MODULES="button" # the list of modules to be unloaded before suspend
 
 
 
=== Disabling a hook ===
 
If a hook is run which you do not like or which you think is not useful or even harmful, we'd appreciate a bugreport for that.
 
You can however easily disable hooks by just creating an empty file corresponding to the hook in <tt>/etc/pm/sleep.d/</tt>. Say you want to disable the hook <tt>/usr/lib/pm-utils/sleep.d/45pcmcia</tt>, you can do this easily by calling
 
# touch /etc/pm/sleep.d/45pcmcia
 
Do not set the executable bit on that dummy-hook.
 
 
 
=== Creating your own hooks ===
 
If you want to do something specific to your setup during suspend / hibernate, then you can easily put your own hook into <tt>/etc/pm/hooks</tt>. The hooks in this directory will be called in alphabetic order during suspend (that's the reason their names all start with 2 digits, to make the ordering explicit) and in the reverse order during resume.
 
 
 
I'm showing a pretty useless demonstration hook here, that will just put some informative lines into your logfile:
 
 
 
#!/bin/bash
 
case $1 in
 
    hibernate)
 
        echo "Hey guy, we are going to suspend to disk!"
 
        ;;
 
    suspend)
 
        echo "Oh, this time we're doing a suspend to RAM. Cool!"
 
        ;;
 
    thaw)
 
        echo "oh, suspend to disk is over, we are resuming..."
 
        ;;
 
    resume)
 
        echo "hey, the suspend to RAM seems to be over..."
 
        ;;
 
    *)  echo "somebody is calling me totally wrong."
 
        ;;
 
esac
 
 
 
Put this into /etc/pm/sleep.d/66dummy, do a <tt>chmod +x /etc/pm/sleep.d/66dummy</tt> and it will spew some useless lines during suspend / resume.
 
 
 
'''''Warning:''' All the hooks run as user root. This means that you need to be careful when creating temporary files, check that the PATH variable is set correctly etc. to avoid security problems.''
 
 
 
== How it Works ==
 
The concept is quite easy: the main script (<tt>pm-action</tt>, called via symlinks as either <tt>pm-suspend</tt>, <tt>pm-hibernate</tt> or <tt>pm-suspend-hybrid</tt>) executes so-called "hooks", executable scripts, in the alphabetical sorted order with the parameter <tt>suspend</tt> (suspend to RAM) or <tt>hibernate</tt> (suspend to disk).
 
Once all hooks are done, it puts the machine to sleep. After the machine has woken up again, all those hooks are executed in reverse order with the parameter <tt>resume</tt> (resume from RAM) or <tt>thaw</tt> (resume from disk).
 
The hooks do various stuff, for example preparing the bootloader, stopping the bluetooth subsystem or unloading of critical modules.
 
 
 
Both pm-suspend and pm-hibernate are usually called from HAL, initiated by desktop applets as gnome-power-manager or kpowersave.
 
 
 
{{Box Note|<tt>suspend-hybrid</tt> is a placeholder right now, it is not completely implemented.}}
 
 
 
There is also the possibility to set the machine into high-power and low-power mode, the command <tt>pm-powersave</tt> is used with an additional parameter of <tt>true</tt> or <tt>false</tt>. It works basically the same as the suspend framework.
 
 
 
The hooks for suspend are placed in
 
* <tt>/usr/lib/pm-utils/sleep.d</tt> (distribution / package provided hooks)
 
* <tt>/etc/pm/sleep.d</tt> (hooks added by the system administrator)
 
 
 
The hooks for the power state are placed in
 
* <tt>/usr/lib/pm-utils/power.d</tt> (distribution / package provided hooks)
 
* <tt>/etc/pm/power.d</tt> (hooks added by the system administrator)
 
 
 
Hooks in <tt>/etc/pm/</tt> take precedence over those in <tt>/usr/lib/pm-utils/</tt>, so the system administrator can override the defaults provided by the distribution.
 
 
 
== Troubleshooting ==
 
If suspend or hibernate did not work correctly, you will probably find some information in the logfile '''<tt>/var/log/pm-suspend.log</tt>''', for example which hooks were run and what the output of them was.
 
 
 
=== Resume Hook ===
 
 
 
It has been suggested that some systems require the <tt>resume</tt> hook be added to the initrd image, otherwise the kernel will '''not''' resume. To do so, edit <tt>/etc/mkinitcpio.conf</tt> as root and add <tt>resume</tt> to the HOOKS array:
 
HOOKS="base udev autodetect ide scsi sata '''''resume''''' filesystems "
 
 
Note that this is an example, and your HOOKS array may look different.
 
 
 
<tt>resume</tt> must be placed ''after'' 'ide', 'scsi' and/or 'sata' but before 'filesystems'. Of course there has to be an appropriate 'resume' file in /lib/initcpio/hooks, it should already be there, as it is part of the package 'mkinitcpio'.
 
 
 
Finally, you must rebuild the initrd image for these changes to take effect:
 
 
 
# mkinitcpio -p kernel26
 
 
 
{{Box Note|If you use a custom kernel then you might have to change the value of the '-p' option.}}
 
 
 
== Tips and Tricks / FAQ ==
 
=== Triggering suspend manually ===
 
If you want to trigger suspend manually for debugging, without using HAL and other frameworks, call '''<tt>pm-suspend</tt>''' or '''<tt>pm-hibernate</tt>''' as root.
 
 
 
=== Using another sleep backend (like uswsusp) ===
 
Create a file with a SLEEP_MODULE variable, like this:
 
$ cat /etc/pm/config.d/module
 
SLEEP_MODULE=uswsusp
 
I don't know but you may have to <code>chmod +x</code> it. To list available modules, use:
 
$ pacman -Ql pm-utils | grep module.d
 
 
 
=== Having the hd power management level automatically set again on resume ===
 
Do it like this:
 
$ cat /etc/pm/sleep.d/50-hdparm_pm
 
#!/bin/dash
 
 
if [ -n "$1" ] && ([ "$1" = "resume" ] || [ "$1" = "thaw" ]); then
 
hdparm -B 254 /dev/sda > /dev/null
 
fi
 
 
 
=== Restarting the mouse ===
 
On some laptops the mouse will hang after an otherwise successful suspend. One way to remedy this is to force a reinit of the PS/2 driver (here <tt>i8042</tt>) through a hook in <tt>/etc/pm/hooks</tt> (see [[#Creating_your_own_hooks|hooks]])
 
 
 
#!/bin/sh 
 
echo -n "i8042" > /sys/bus/platform/drivers/i8042/unbind
 
echo -n "i8042" > /sys/bus/platform/drivers/i8042/bind
 
 
 
=== It seems to not do anything / where is the logfile ===
 
If it seem to not do anything when called via the desktop applets, then try to call <tt>pm-suspend</tt> or <tt>pm-hibernate</tt> [[#Triggering_suspend_manually|manually from a root shell in a terminal]]. Maybe you'll already get some output that will point you to the problem.
 
The suspend scripts also write a [[#Troubleshooting|logfile at '''<tt>/var/log/pm-suspend.log</tt>''']].
 
 
 
=== Add sleep modes to Openbox menu ===
 
Openbox users can add the new scripts as additional shutdown options within the Openbox menu by adding the items to a new or existing sub-menu in <tt>~/.config/openbox/menu.xml</tt>, for example:
 
<menu id="64" label="Shutdown">
 
<item label="Lock"> <action name="Execute"> <execute>xscreensaver-command -lock</execute> </action> </item>
 
<item label="Logout"> <action name="Exit"/> </item>
 
<item label="Reboot"> <action name="Execute"> <execute>sudo shutdown -r now</execute> </action> </item>
 
<item label="Poweroff"> <action name="Execute"> <execute>sudo shutdown -h now </execute> </action> </item>
 
'''''<item label="Hibernate"> <action name="Execute"> <execute>sudo pm-hibernate</execute> </action> </item>'''''
 
'''''<item label="Suspend"> <action name="Execute"> <execute>sudo pm-suspend</execute> </action> </item>'''''
 
</menu>
 
 
 
=== Blank screen issue ===
 
Some users have reported having issues with their laptops not resuming after a suspend or hibernate. This is due to the autodetect HOOK. This can be disabled using the same method for adding the resume HOOK. Just remove autodetect from the list and follow the steps to build the new image. See [http://wiki.archlinux.org/index.php/Pm-utils#Resume_Hook Resume Hook] for more details on building the new image.
 
 
 
== Other Resources ==
 
*[http://people.freedesktop.org/~hughsient/quirk/ HAL Quirk Site] - Common solutions and frequently asked questions<br/>
 
*[[Cpufrequtils]] - CPU Frequency Scaling and CPU Power schemes<br/>
 
*[[SpeedStep]] - More information on CPU frequency scaling (some of which is obsolete)<br/>
 
*[[Acpid]] - daemon for delivering ACPI events.
 
 
 
 
 
== Credits ==
 
''This wiki entry was originally sourced from the [http://en.opensuse.org/Pm-utils OpenSUSE Wiki] (Licensed under GPL).  A big thank you goes to the <tt>pm-utils</tt> developers and documenters for their time.''
 

Latest revision as of 21:38, 25 November 2017

Redirect to: