- 1 Introduction
- 2 Installation
- 3 Basic Configuration
- 4 Advanced Configuration
- 5 How it Works
- 6 Troubleshooting
- 7 Tips and Tricks / FAQ
- 8 Other Resources
- 9 Credits
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.
Used in conjunction with the Cpufrequtils package, notebook (and desktop) owners are provided with a complete power management suite.
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
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 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 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 /etc/sudoers file with visudo, 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
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...
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
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/hooks. 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 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 resume filesystems "
Note that this is an example, and your HOOKS array may look different.
resume 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
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.
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.
- HAL Quirk Site - Common solutions and frequently asked questions
- 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.