In this article, we’ll discuss different ways to optimize the battery life in computers with Linux operating systems. Of course, this article is also relevant for all systems that depend on internal sources of energy and cannot be plugged into the electrical grid, from laptops to other embedded devices.
2. First Steps to Improve Battery Life
There are some things that may look minor but play an important role in our battery lifespan. The first one is tuning off unused system features. This includes (but is not restricted to) WiFi, Bluetooth, VGA ports, ethernet, and more.
All these ports drain energy from the battery, and some devices even have hardware buttons to disable them. If buttons are not available, we can disable their drivers, as described in the next section. Moreover, we can also hibernate instead of suspending/sleeping our system. This means suspending to disk instead of suspending to RAM memory so that the battery spends no energy.
We can also tweak parts of our system to improve the battery life. If the system doesn’t use a Solid State Drive (SSD), defragging the hard drive regularly will reduce the load of the component and its battery use. Another relevant part of every system is the display: Watch out for screen usage.
The first solution is to reduce the screen brightness. We can also get longer battery life with lower screen resolutions (as higher resolutions require more CPU work, which drains the battery more quickly).
Finally, there are other power-saving options that may be readily accessible, depending on our Linux distribution. For example, Ubuntu has some automatic options for battery usage under System/Preferences/Power Management. We can also manually reduce the desktop visual effects.
3. Manual Approach to Managing Unwanted Services
If, after following the previous steps, we still feel that our battery drains faster than we’d like, there are other solutions that we can take.
We can turn off services that we don’t need. Some examples of services that we can turn off are ssh, apache, avahi, pulseaudio, and acpi-daemon (of course, if we are not using them!).
$ service --status-all
Then, we can stop unwanted services with:
$ service "service-name" stop
With systemd, we can retrieve all active services as:
$ systemctl --state=active
As before, we can shut down unwanted services:
$ systemctl stop "application.service"
We can also unload unused kernel drivers, such as usb_storage, webcam, wireless, or Bluetooth drivers. The kernel drivers (also known as modules) that are loaded can be seen with lsmod:
To unload a module, we can use rmmod:
$ rmmod "module"
There is another utility, modprobe, that we can use to unload a kernel driver:
$ modprobe -r "module"
We may need to kill programs that are using the services/drivers that we want to turn off. All processes can be listed with ps, where we can grep the service/driver. Once we retrieve the process ID, we stop the process with kill.
4. Specific Tools Designed for Battery Optimization
In this article, we’ve seen multiple solutions that we can take to optimize and expand the battery life of our devices running Linux.