Increase Battery Life in Linux

The main drawback I have experienced in using Linux on my laptop is the battery life.

Fortunately, there are several things you can do to extend the life of your battery. Now my laptop is running close to the same length of time as it would under Windows 7, and is going much longer than when I was testing the Windows 8 Consumer Preview.

Discrete Graphics

Some laptops include more than one graphics card. My laptop includes both an Intel chipset for power efficiency and an ATI chipset for performance. Sometimes, both of the graphics cards will be active when you are running Linux. Not only is this an obvious waste of power, it can generate additional heat and create extra fan noise as well.

For my needs, I decided to disable the ATI graphics card while I am running in Linux. It handles all the NME and Humble Bundle games I have thrown at it, and helps preserve my battery while I am not playing a game.

Disable the card on start-up

Modern versions of Ubuntu include “vgaswitcheroo,” which helps you toggle multiple graphics cards on a single system. I was able to edit “/etc/rc.local” to add the following command:

echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

You can use “sudo vi /etc/rc.local” if you are comfortable with vim, or “sudo gedit /etc/rc.local” for a more traditional editor.

Disable the card when resuming from standby

I also made a file in “/etc/pm/sleep.d/” called “10_disable_radeon”, but the name does not matter very much. This helps make certain that the extra graphics card remains disabled even when the system comes out of standby.

#!/bin/sh
 
case "${1}" in
  resume|thaw)
 
    echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
 
;;
esac

The script will need to be executable, so run a command like “sudo chmod +x /etc/pm/sleep.d/10_disable_radeon” to make it work.

Power Settings

If you would like to get better information on what is using power on your system, and suggestions for how it can be improved, I would recommend that you install “powertop.” In Ubuntu, you should be able to get powertop from the repositories using “sudo apt-get install powertop”. While you are at it, you might also consider installing “ethtool”, which can disable the Wake-On-Lan feature of your ethernet card.

Battery/AC adapter power-saving profile

I created my script at “/etc/pm/power.d/00-powersave”. It is not perfect, but I hope that it is helpful for you. A lot of the recommendations I found online were either very specific to a certain model of laptop, or were designed for older versions of the Linux kernel.

case $1 in
  true)
 
    # Running on battery
 
    # Disable the NMI watchdog
    echo 0 > /proc/sys/kernel/watchdog
 
    # Reduce power for SATA link power management
    for i in 0 1 2 3 4 5 ; do
        echo min_power>/sys/class/scsi_host/host${i}/link_power_management_policy
    done
 
    # Runtime power-management for PCI devices
    for i in /sys/bus/pci/devices/*/power/control ; do
        echo auto > ${i}
    done
 
    # Runtime power-management for USB devices
    for i in /sys/bus/usb/devices/*/power/control ; do
        echo auto > ${i}
    done
 
    # Disable Wake-on-LAN and ethernet port
    ethtool -s eth0 wol d
    ifconfig eth0 down
 
    # Use the "ondemand" CPU governor
    for i in /sys/devices/system/cpu/cpu?/cpufreq/scaling_governor ; do
        echo ondemand > ${i}
    done
 
    # Reduce the VM write-back timeout
    sleep 1000 && echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
 
  ;;
  false)
 
    # Running on charger
 
    # Enable the NMI watchdog
    echo 1 > /proc/sys/kernel/watchdog
 
    # Increase the VM write-back timeout
    echo 60000 > /proc/sys/vm/dirty_writeback_centisecs
 
    # Change power-saving for SATA devices
    for i in 0 1 2 3 4 5 ; do
        echo min_power>/sys/class/scsi_host/host${i}/link_power_management_policy
    done
 
    # Enable full power for PCI devices
    for i in /sys/bus/pci/devices/*/power/control ; do
        echo on > ${i}
    done
 
    # Enable Wake-on-LAN and ethernet port
    ethtool -s eth0 wol g
    ifconfig eth0 up
 
    # Use the "ondemand" CPU governor
    for i in /sys/devices/system/cpu/cpu?/cpufreq/scaling_governor ; do
          echo ondemand > ${i}
    done
  ;;
esac
exit 0

Most of these settings are inline with the recommendations “powertop” provides.

This should reduce the amount of power your hard disk uses, allow the kernel to suspend PCI and USB devices that are not in use, disable Wake-On-LAN, turn off the ethernet card and make sure the CPU uses a good governor for performance and power saving.

When your system is on AC power, it will switch some of these settings back to defaults.

Other Recommendations

The brightness of your screen will make a significant difference in your battery life. I have also omitted a large number of kernel settings which are traditionally included in instructions to optimize performance. Since upgrading to Ubuntu 12.04, these extra parameters seem unnecessary, as they are enabled (when appropriate) by default.

I also enabled “Aggressive Link Power Management”, which can save power for hard disks, but may not work properly for some systems. You can find more information about enabling ALPM (which I do not believe is enabled by default in Precise) here: https://wiki.ubuntu.com/Kernel/PowerManagementALPM

If you are looking for more tips, you should be able to find more information here: https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks

  • Don Morrison

    The gnome cpu throttling panel is very useful. Some system events on Ubuntu (like using the synaptic package manager) will reset it to the OnDemand setting though, which is annoying.

  • Curtis Shimamoto

    I want to thank you for this one stop power saving extravaganza. I was using powertop on Arch Linux to determine how I could extend battery life. Googling for each and every fix seemed like it was going to be a drag, but on the third one I found your post here, and you mentioned every /sys location of what I needed.

    For me, though, I have made the switch to systemd, and had to use unit files. It was amazingly easy, though I am unsure if there is a way to use ‘for’ statements in the tmpfiles.d. So for instance, to enable power saving with bus devices, I made /etc/tmpfiles.d/usbpower.conf and in it were lines like this

    # type – path – mode – uid – gid – age – arguments
    f /sys/bus/usb/devices/usb1/power/control 0644 root root – auto

    So maybe this might help someone who is using systemd. I am not sure when you would use ‘age’ but for unused parameters, jut insert a “-” as above. I don’t think you can use wildcards in these files, but I am unsure.

    For the paramters with a starting path of /proc/sys, these are controlled by sysctl and the config file /etc/sysctl.conf. So anything further down the tree from /proc/sys can be controlled here. I use two config files and # sysctl –load=[file] to simplify my acpid script for on/off battery power.

    Hopefully this information suppliments the awesome post. Thanks again Joshua!

  • Martin

    wohou…works! finaly no problems with ubuntu! thanks very much