Power Management
Configuring Hardware - Power Management
If you have a laptop, you will probably want to make a few measures to extend your battery life, such as throttling down your CPU, dimming your LCD backlight, and other things. In this case you will want to make sure the laptop USE flag is set in your /etc/make.conf. If you have a dell laptop, you will also want to add the dell USE flag. Chances are you have already built some of the packages that accept these USE flags, so you may want to rebuild all affected packages on your system.
$ sudo emerge -avDN world
If it hasn't been installed already, you'll want to install the acpi (Advanced Configuration and Power Interface) daemon.
$ sudo emerge -av apcid
Once the package is emerged, we'll start the apci daemon and add it to startup.
$ sudo /etc/init.d/acpid start $ sudo rc-update add acpid default
The next we'll create a "battery" runlevel for your system.
$ cd /etc/runlevels $ sudo cp -a default battery
This action creates a copy of the default runlevel called battery. From now on, whenever you add a service to the default runlevel, if you want it to start up when you are running only on your battery, you will need to add it to the battery runlevel as well. The next step will be to create a script that can intercept from the acpid whether or not your system is running on batteries and be able to switch to the appropriate runlevel. This script was blatantly stolen from the gentoo handbook.
$ sudo mkdir /etc/acpi/actions $ sudo nano -w /etc/acpi/actions/pmg_switch_runlevel.sh
/etc/acpi/actions/pmg_switch_runlevel.sh
#!/bin/bash
# BEGIN configuration
RUNLEVEL_AC="default"
RUNLEVEL_BATTERY="battery"
# END configuration
if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ]
then
logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting."
exit 1
fi
if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ]
then
logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting."
exit 1
fi
if on_ac_power
then
if [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]]
then
logger "Switching to ${RUNLEVEL_AC} runlevel"
/sbin/rc ${RUNLEVEL_AC}
fi
elif [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]]
then
logger "Switching to ${RUNLEVEL_BATTERY} runlevel"
/sbin/rc ${RUNLEVEL_BATTERY}
fi
We'll also need to make this script executable.
$ chmod 755 /etc/acpi/actions/pmg_switch_runlevel.sh