Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

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!).

First, we need to check the services running on the system. We might have service or systemd depending on our distribution. With the former, we can see the running services as:

$ 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:

$ 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 section, we present three tools that have been created with battery optimization in mind.

powertop is an application that analyzes the power consumption of laptops, especially for Intel processors. We need to execute it with super-user rights:

$ sudo powertop

This will present us with a detailed analysis of our battery usage, including services that are running unneeded background tasks. We can manually set individual options for power management, but we can also let the tool optimize them:

$ sudo powertop --auto-tune

Some users may experience problems with powertop. If we’re using an external USB mouse or keyboard, powertop may ask about auto-suspending USB (which, if we do, will suspend the input devices, stopping their communication with the system). Also, some displays become unresponsive with powertop, which may indicate a problem with the acpi modules.

If we’re happy with the performance of our system with the configuration, we can keep the settings to be automatically applied when booting up. We can create a service for systemd or simply append to /etc/rc.local the call to powertop (before the exit 0 line, if present):

powertop --auto-tune
exit 0

Another useful package is laptop-mode-tools, which mainly allows using the laptop mode in the kernel, slowing down the hard drive. However, this doesn’t mean that it cannot be useful with SSD, as it also supports other power management features: starting and stopping daemons, adjusting screen blanking, hibernating with a low battery, and so on. Newer versions of Ubuntu don’t need this package.

To conclude this section, we can also mention TLP as an alternative to powertop. Moreover, we can tweak the CPU frequency scaling to be proportional to the performance requirements of the system.

5. Conclusion

In this article, we’ve seen multiple solutions that we can take to optimize and expand the battery life of our devices running Linux.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!