Mon 13 Aug 2007
How To: Increase Battery Life in Ubuntu or Debian Linux
Posted by Robert under HowTo , Linux , Mobile[6] Comments
With the popularity of the last How To on Domain Controllers, I thought we should do some more. So here’s how I’ve nearly doubled my battery life on my laptop (2 hours max with Windows to 3:30 average with Ubuntu, which was originally 2:30). I used to use a series of programs on Debian Etch which are also available in Ubuntu. However, probably because of their lack of nice GUI interfaces, they’re not installed by default. If you are more interested in increasing your battery time, however, follow along.
- Install laptop-mode-tools and cpufreqd
sudo apt-get install laptop-mode-tools cpufreqd cpufrequtils - Make sure that the proper CPU governers are installed for your processor. I have an Intel Centrino Duo 1.6Ghz (which clocks down to 1Ghz).
sudo modprobe acpi-cpufreq(or speedstep-centrino or powernow-k8|k7|k6 or longhaul, depending on architecture – acpi-cpufreq should be the most compatible)
sudo modprobe cpufreq-conservative
sudo modprobe cpufreq-ondemand
sudo modprobe cpufreq-powersave
I use ondemand and conservative – ondemand for when I’m plugged in – no point running at 1.6Ghz when I’m idle – it just heats up the system and overworks the fan – and conservative on battery life – it only steps up slowly as requires, and I can still limit it well with cpufreqd. However, having powersave available on a moments notice to keep the processor locked at 1ghz is nice. - Add
acpi-cpufreqor whichever cpufreq driver you picked in the previous step to the end of/etc/modulesto force the system to load them at bootup. Ubuntu didn’t pick this up properly for me on any install yet (Dapper, Edgy or Feisty), but Debian did in Sid and Etch - Now open up a terminal (or Konsole) window and edit the files (or replace them with my versions). I’ve attached my versions below.
laptop-mode.conf
cpufreqd.conf - A few things to look out for when editing these files
- set your cpufreqd.conf to the proper CPU speed limits. You can get the hardware limits for your processor from
cpufreq-info -l
Mine are obviously (when you read my cpufreqd.conf) 1000000 to 1667000 - Note which steps are available to you. On my Centrino Core Duo, I only have 3 steps, but on one Celeron processor I saw 10 steps from 2GHz down to133MHz.
- Make sure in this configuration that you’re disabling CPU monitoring in laptop-mode.conf. Laptop-mode-tools seem to do this well, but when I last read the man pages, it does all its switching with the usermode driver, which is a more expensive operation than kernel mode – where cpufreqd runs at; letting the speedstep operations run as intended in the core is much more efficient, cpu-cycle-wise… which saves even more battery life. Yes, every second counts.
- I personally set “
noatime” as a default mount option in/etc/fstabfor every physical drive in my laptop. However, you’ll also see my laptop-mode.conf has “control_noatime=1” set, in case I forget, or edit fstab. This does amount -o remounton all drives when you unplug from the wall, setting thenoatimemount option ONLY on battery power. This got confusing to me, having access timestamps sometimes, so I just disabled it completely, and know that my access timestamps are 100% worthless, rather than 50% worthless. - Look closely at the cpufreqd.conf that I’ve created – you’ll see several different scenarios for how to control the CPU limits, based on utilization, battery life, AC status, and even which programs are running. These are settings that work very well for me – I doubt they’ll work well for everyone, but they do cover pretty much every situation I’ve been in on battery power, from doing a presentation out of VMWare to taking notes in a 4 hour meeting. I rarely play games in Linux, much less on battery power, so I can’t speak much to that. But I can get a full DVD easily, and 2 movies if they’re ripped to DivX on the HDD.
- set your cpufreqd.conf to the proper CPU speed limits. You can get the hardware limits for your processor from
- Last step is to check the brightness of your laptop. In mine, I can set the brightness on battery power vs. AC power in the BIOS. I also have controls for it. Lowering your brightness by half increases your battery life a HUGE amount. I try to keep it as low as required to see it – in a dark meeting room, that means “as low as it goes”. Being a touch-typist becomes important here, cause that’s not bright enough to see the keyboard on my system.
That’s it. For reference, this whole post written on battery power tonight, while doing other things (like cooking dinner and going for a walk), never in sleep mode. Percentage battery remaing thanks to bat-stats.sh
robert@laptop:~$ bat-stats.sh
# Using governor powersave
# Battery max design 5100 mWh, last 4321 mWh
# Using last max for percentages.
22.0319
robert@laptop:~$ uptime
23:00:51 up 3:09, 4 users, load average: 0.20, 0.14, 0.10
February 11th, 2008 at 9:18 pm
question, you didn’t include the paths where to edit the configuration files… like cpufreqd.conf , where is it located..
also, when running cpufreq-info, I receive the following message:
cpufrequtils 002: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which need to switch frequency at the same time: 0
hardware limits: 600 MHz – 1.70 GHz
available frequency steps: 1.70 GHz, 1.40 GHz, 1.20 GHz, 1000 MHz, 800 MHz, 600 MHz
available cpufreq governors: conservative, ondemand, powersave, userspace, performance
current policy: frequency should be within 1.70 GHz and 1.70 GHz.
The governor “ondemand” may decide which speed to use
within this range.
current CPU frequency is 1.70 GHz.
I can’t change it to conservative etc…
I am using Aser Aspire 5502 ZWXMi Laptop, Intel Pentium M processor 735 1.7 GHz 400 MHz FSB 2 MB L2 Cache.
February 12th, 2008 at 3:41 pm
Karlo – cpufreqd.conf lives directly in /etc – it’s installed as part of “cpufreqd” via “apt-get install cpufreqd”. Without the daemon from that package, the conf file won’t help.
You’re probably having an issue getting the Conservative governer loaded, because it’s not being loaded. Above you’ll see my modprobe commands for loading “cpufreq_conservative” by hand. To make it load every time, you can edit /etc/modules and add “cpufreq-conservative” and any others you want, to the end of that file – one module per line.
Otherwise, your setup looks good, since all the governors are available, and cpufreq-info is giving the proper information back.
September 23rd, 2008 at 10:40 am
And what about Power Manager being part of Gnome by default ?
It is managing power in userspace mode and that’s not the best as you mentioned, but won’t all your tweaks be in conflict with Power Manager settings ? Is it necessary to uninstall (or deactivate ?) Power Manager befor using these tricks ?
October 6th, 2008 at 8:03 am
[...] totalnetsolutions.net » How To: Increase Battery Life in Ubuntu or Debian Linux (tags: ubuntu tutorials linux howto optimization notebook mobile laptop) [...]
November 10th, 2008 at 1:32 am
There are some severe problems with acpi laptop mode. Harddisk load cycles increase rapidly causing Harddisk failure. Bugs exist on launchpad and forums also.
November 11th, 2008 at 12:33 pm
aditya, yeah, that’s why laptop_mode is disabled in /etc/default/acpi on install. However, on the IBM T60 and Dell D620 and D630 that I’ve used, I haven’t run into a single problem, and the benefits have been huge (I ran 2 VMWare workstation guests the whole flight from Chicago to LA last night on battery power).