Power management

From Alpine Linux

Power management is a feature of computer CPUs, GPUs and peripherals such as monitors and printers, that turns off the power or switches the system to a low-power state when inactive based on a standard called ACPI.

Installation

Alpine Linux comes inbuilt with a basic version of acpid as part of BusyBox.

A flexible and extensible acpid2 daemon with Netlink support for delivering ACPI events can be installed with the acpid package:

# apk add acpid

On installation of the above package, the inbuilt Busybox acpid daemon gets replaced.

Service configuration

Enable and start the acpid daemon using the standard OpenRC commands:

# rc-update add acpid && rc-service acpid start

Power management utilities

There are a number of power management utilities available in Alpine Linux. You may want to install one of them, if your Desktop software needs one.

Tool Website Brief Notes
zzz https://github.com/jirutka/zzz A simple program to suspend or hibernate your computer. It supports hooks before and after suspending.
powerctl https://sr.ht/~sircmpwn/powerctl/ A simple command line utility to control power states on Linux i.e. to suspend or hibernate the system.
pm-utils https://pm-utils.freedesktop.org/wiki/ Collection of scripts that handle suspend and resume on behalf of HAL

Busybox acpid

BusyBox acpid allows custom mapping and handling of ACPI events via options -M FILE (Map file) and -a FILE (Action file).

Map file

A Map file maps ACPI events to descriptions (the last column). For example:

Contents of /etc/acpi.map

"EV_KEY" 0x01 "KEY_POWER" 116 1 "button/power PWRF 00000080" "EV_KEY" 0x01 "KEY_POWER" 116 1 "button/power PWRB 00000080" "EV_KEY" 0x01 "KEY_SLEEP" 142 1 "button/sleep SBTN 00000080" "EV_KEY" 0x01 "KEY_SUSPEND" 205 1 "button/suspend SUSP 00000080" "EV_SW" 0x05 "SW_LID" 0 0 "button/lid LID/open 00000080 00000000" "EV_SW" 0x05 "SW_LID" 0 1 "button/lid LID/close 00000080 00000001" "EV_SW" 0x05 "SW_TABLET_MODE" 1 0 "video/tabletmode TBLT/off 0000008A 00000000" "EV_SW" 0x05 "SW_TABLET_MODE" 1 1 "video/tabletmode TBLT/on 0000008A 00000001"

The built-in map file contains only PWRB/PWRF (power button) and LID (lid close).

Action file

An Action file maps the event descriptions specified in the Map file to action scripts relative to the Config directory (/etc/acpi by default). It performs a substring match, so typically only the second part of the description is specified in the Action file. If the target path is not a file, but directory, it executes all scripts in the directory via run-parts. For example:

Contents of /etc/acpid.conf

PWRF power SBTN sleep SUSP suspend LID/open lid/open LID/close lid/close TBLT/off tabletmode/off TBLT/on tabletmode/on

When the power button is pressed, acpid runs script /etc/acpi/power.

Suspend when closing the LID

There are a few ways to suspend a laptop when closing the LID of it.

Installing a power management utility like zzz along with acpid package provides full support for pre/post suspend hooks etc. The default handler script (/etc/acpi/handler.sh) installed with the package acpid package provides out of the box support for suspend on LID closure.

Alternately, this can be achieved using Busybox acpid with a hook in /etc/acpi/LID/00000080. Make the hook executable:

# chmod +x /etc/acpi/LID/00000080

Ensure that the acpid daemon service is running.

Configuring with zzz:

Contents of /etc/acpi/LID/00000080

#!/bin/sh exec zzz

Configuring with pm-utils:

Contents of /etc/acpi/LID/00000080

#!/bin/sh exec pm-suspend

Configuring with raw variant:

Contents of /etc/acpi/LID/00000080

#!/bin/sh echo mem > /sys/power/state

elogind and power management

If elogind is used, add the following line to /etc/doas.conf config file

Contents of /etc/doas.conf

... permit nopass $USER as root cmd /bin/loginctl

You should now be able to suspend as a normal user, using the full path to executable. Refer to elogind page for more detailed information.

Handling the pressing of power button

In case of desktop environments, it might be useful to allow for some control on what happens when you press the power button instead of shutting down the computer. This can be done via inbuilt Busybox acpid by creating/modifying the hook in /etc/acpi/PWRF/00000080. Make the hook executable:

# chmod +x /etc/acpi/PWRF/00000080

Ensure that the acpid daemon service is running.

Configuring for shutdown

In a newly installed system this might be already defined, however you can create the hook as follows:

Contents of /etc/acpi/PWRF/00000080

#!/bin/sh poweroff

Configuring for sleep

Use one of the power management utility, say zzz here and Modify the hook as follows:

Contents of /etc/acpi/PWRF/00000080

#!/bin/sh zzz

Disabling the power button

To disable simply comment or remove the hook. This is useful to allow desktop environments like Gnome or KDE to handle the power button.

Contents of /etc/acpi/PWRF/00000080

#!/bin/sh #Nothing

See also