Contents

Prerequisites

First of all, make sure that button module is loaded (check the output of lsmod). If it is not, load it manually with modprobe and to load it automatically at boot time add it to your /etc/rc.confMODULES array.

Note: Some machines only fire the power button acpi event after the power button is held down for some seconds, e.g. Thinkpads ~ 3 seconds.

Create a file in /etc/acpi/events/ named power with following content:

# /etc/acpi/events/power
# This is called when the user presses the power button
event=button/power (PWR.||PBTN)
action=/sbin/poweroff

To be able to test it, make sure the acpid daemon is started, see Daemon for instructions. To test it without actually shutting down, comment out the poweroff line and check your user/messages logs.

From now on, pressing the power button (lightly, not for a few seconds) should properly shutdown the system.
Note that if you have hibernate configured and working you may want to change the last line with:

action=/usr/sbin/hibernate

If you are using a more sophisticated Window Manager, you should use its own shutdown call, so it would save its session etc.

KDE 4

Select "Edit Profiles" and choose the current profile. (In KDE 4.4, the default profile is "Powersave.")

Select "Shutdown" as the action for "When power button is pressed."

Press Apply.

Note:

With dcop and PowerDevil, the power button works only when KDE is running. Also, KDE needs to start from KDM (it probably also works when started from GDM). It does not work if you start KDE with a "startx" command.

The PowerDevil configuration is per user. To configure the power button for other users, repeat these steps for each user's account.

Note: For a more robust solution (If you are facing frequent WM crashes or working on a sacrificial PC for developing or testing your software...), you should take a look at "/usr/src/linux/Documentation/sysrq.txt", which is a kernel facility for yielding you (the user...) the CPU so that it could be used for any rescue work.