pm-utils is the new suspend and powerstate setting framework. It is designed to replace such scripts as those provided by the powersave 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.
A lesser known feature is one that mimmicks toggling done by Laptop Mode Tools.
Used in conjunction with the cpufrequtils package, notebook (and desktop) owners are provided with a complete power management suite.
- 1 Installation
- 2 Basic Configuration
- 3 Advanced Configuration
- 4 How it Works
- 5 Troubleshooting
- 6 Tips and Tricks / FAQ
- 6.1 Triggering suspend manually
- 6.2 Automatically deactivate kwin compositing before suspend
- 6.3 Using another sleep backend (like uswsusp)
- 6.4 Having the hd power management level automatically set again on resume
- 6.5 Restarting the mouse
- 6.6 It seems to not do anything / where is the logfile
- 6.7 Add sleep modes to Openbox menu
- 6.8 Blank screen issue
- 6.9 Handling "sleep" and "power" buttons
- 6.10 HAL will not recognize new devices on resume
- 7 Other Resources
- 8 Credits
The pm-utils package is now available from the Extra repository:
# pacman -S pm-utils
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
Raid swap example:
# (0) Arch Linux title Arch Linux root (hd0,0) kernel /vmlinuz26 root=/dev/md2 resume=/dev/md0 ro md=0,/dev/sda2,/dev/sdb2 md=2,/dev/sda5,/dev/sdb5 vga=773 initrd /kernel26.img
If you want to use the UUID of the device instead then use the following example. The UUID itself can by find out by using the blkid command as root.
# (0) Arch Linux title Arch Linux root (hd0,0) kernel /vmlinuz26 cryptdevice=/dev/sda2:main root=/dev/mapper/main-root resume=/dev/disk/by-uuid/1d893194-b151-43cd-a89e-6f89bd8b9f99 ro 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 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 500M. 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.
Note: you may have to add the resume hook to mkinitcpio, see below
Suspend/Hibernate as regular user
Three methods are available to suspend without the need for a root password: using HAL, using UPower, and giving the user permissions with visudo.
To suspend to RAM:
$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower org.freedesktop.UPower.Suspend
To suspend to disk (hibernate):
$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" \ /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
HAL can be invoked as regular user to suspend by:
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \ /org/freedesktop/Hal/devices/computer \ org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0
and Hibernate by:
$ dbus-send --system --print-reply --dest=org.freedesktop.Hal \ /org/freedesktop/Hal/devices/computer \ org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
User Permission Method
Because the pm-utils 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 Template:Filename file with Template:Codeline, for example:
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
Note: These must come after any user privilege specifications, e.g., "username ALL=(ALL) ALL", or they won't work.
You can now run the scripts without a password by simply typing:
$ sudo pm-hibernate
$ 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...
Write a custom acpid action: Template:File
Be sure not to install Template:Package Official since the rules may conflict.
The main configuration file is /usr/lib/pm-utils/defaults. You should not edit this file, since after a package update it might be overwritten with the default settings. Put your config file into /etc/pm/config.d/ instead. You can just put a simple text file with
named "modules" or "config" into /etc/pm/config.d 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 SLEEP_MODULE="tuxonice uswsusp kernel" # The default sleep/wake systems to try HIBERNATE_MODE="shutdown" # forces the system to shutdown rather than reboot
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 /etc/pm/sleep.d/. Say you want to disable the hook /usr/lib/pm-utils/sleep.d/45pcmcia, 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 /etc/pm/sleep.d. 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 chmod +x /etc/pm/sleep.d/66dummy 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 (pm-action, called via symlinks as either pm-suspend, pm-hibernate or pm-suspend-hybrid) executes so-called "hooks", executable scripts, in the alphabetical sorted order with the parameter suspend (suspend to RAM) or hibernate (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 resume (resume from RAM) or thaw (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.
There is also the possibility to set the machine into high-power and low-power mode, the command pm-powersave is used with an additional parameter of true or false. It works basically the same as the suspend framework.
The hooks for suspend are placed in
- /usr/lib/pm-utils/sleep.d (distribution / package provided hooks)
- /etc/pm/sleep.d (hooks added by the system administrator)
The hooks for the power state are placed in
- /usr/lib/pm-utils/power.d (distribution / package provided hooks)
- /etc/pm/power.d (hooks added by the system administrator)
Hooks in /etc/pm/ take precedence over those in /usr/lib/pm-utils/, so the system administrator can override the defaults provided by the distribution.
If suspend or hibernate did not work correctly, you will probably find some information in the logfile /var/log/pm-suspend.log, for example which hooks were run and what the output of them was.
It has been suggested that some systems, including those using LVM, require the resume hook be added to the initrd image, otherwise the kernel will not resume. To do so, edit /etc/mkinitcpio.conf as root and add resume to the HOOKS array:
HOOKS="base udev autodetect ide scsi sata lvm2 resume filesystems "
Note that this is an example, and your HOOKS array may look different.
resume must be placed after 'ide', 'scsi', 'sata' and/or 'lvm2', 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
If you experience segmentation faults that might result in an unresponsive system and missing keys then try to set the UUID in the resume-path in /boot/grub/menu.lst as explained [above].
Tips and Tricks / FAQ
Triggering suspend manually
If you want to trigger suspend manually for debugging, without using HAL and other frameworks, call pm-suspend or pm-hibernate as root.
Automatically deactivate kwin compositing before suspend
at the moment pm-suspend fails to resume with garbled screen when you resume from suspend with active AIGLX clients, such as kwin compositing (only ati-catalyst?). To automatically deactivate kwin compositing add a new hook under /etc/pm/sleep.d/00togglecompositing with this content:
#!/bin/bash USER=`finger|grep '*:0'|grep -o '^\w*'` DBUS_SESSION_BUS_ADDRESS=`grep -o 'DBUS_SESSION_BUS_ADDRESS=.*' /home/$USER/.dbus/session-bus/*|sed s/DBUS_SESSION_BUS_ADDRESS=//` case $1 in hibernate) ;; suspend) if `sudo -u $USER -i DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS qdbus org.kde.kwin /KWin compositingActive`; then sudo -u $USER -i DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS qdbus org.kde.kwin /KWin toggleCompositing; sleep 1 fi ;; thaw) ;; resume) sudo -u $USER -i DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS qdbus org.kde.kwin /KWin toggleCompositing; ;; *) echo "somebody is calling me totally wrong." ;; esac
I don't know if it's very secure or if it can be done simpler. Feel free to add better versions.
If you are having trouble getting the above script to work, you can try my version. This version removes the use of finger, and fixes the DBUS_SESSION_BUS_ADDRESS resolution which did not work for me (though my solution is admittedly quite dirty). Simply replace the first three lines with:
#!/bin/bash USER=`who | grep ':0' | grep -o '^\w*' | head -n1` . /home/$USER/.dbus/session-bus/*
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
chmod +x 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 i8042) through a hook in /etc/pm/hooks (see 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 pm-suspend or pm-hibernate 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 logfile at /var/log/pm-suspend.log.
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 ~/.config/openbox/menu.xml, 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 Resume Hook for more details on building the new image.
"Sleep" and "power" buttons are handled by acpid in /etc/acpi/handler.sh (see "button/power" and "power/sleep" entries). You may want to substitute the default actions with calls to pm-suspend and pm-hibernate.
HAL will not recognize new devices on resume
With the 2.6.30 kernel, HAL will on some systems bug on resume, not recognizing new USB devices. Adding the following bash script with a name like "02hal" to /etc/pm/sleep.d works around the problem by stopping HAL and starting it again after resuming.
#!/bin/bash case $1 in hibernate) ;; suspend) /etc/rc.d/hal stop ;; thaw) ;; resume) /etc/rc.d/hal start ;; *) ;; esac
Remember to mark it executable with "chmod +x 02hal".
- Understanding Suspend - Ubuntu article explaining how suspend-to-ram works
- Cpufrequtils - CPU Frequency Scaling and CPU Power schemes
- SpeedStep - More information on CPU frequency scaling (some of which is obsolete)
- Acpid - daemon for delivering ACPI events.
This wiki entry was originally sourced from the OpenSUSE Wiki (Licensed under GPL). A big thank you goes to the pm-utils developers and documenters for their time.