Trying to increase the battery life of Laptops may seem controversial with the purpose of the UbuntuXtreme website but it is tightly related to the number one hardware issue of our Laptops when we want the most out of its battery life.
Three of the most power consumption monsters in a Laptop is the Graphics Card, Hard Disk and the CPU. Nowadays most of the latest CPUS’s have Dynamic CPU frequency scaling (also known as CPU throttling) which is a technique in computer architecture where a processor is run at a less-than-maximum frequency in order to conserve power. Linux Kernel utilize this feature by automatically enabling the so-called Governance (Performance, On-Demand, Conservative, Power-save) For example if you manually set the Power-save state (with CPUfrequtils), you “tell your kernel” to try to increase the battery life of your laptop.
The next too parts (Graphics Card, Hard Disk) have also a Power Saving modes but they are not always utilized well by the Linux Kernel. Personally, the one that I find most annoying when I use my laptop is that the Hard Disk never spins down to conserve power and therefore increase the battery life of my laptop.
Increase the battery life with Laptop Mode Tools
Well that was fixed once I installed and configured Laptop Mode Tools
Laptop Mode Tools is a laptop power saving package for Linux systems. It allows you to increase the battery life of your laptop, in several ways. It is the primary way to enable the Laptop Mode feature of the Linux kernel, which lets your hard drive spin down. In addition, it allows you to tweak a number of other power-related settings using a simple configuration file.
How to install Laptop Mode Tools
According to its developer you should use the latest Debian package which is compatible with Ubuntu because the one that ships on Ubuntu Software Center is crippled so that some options don’t work, the most notable of which are
Supported 2.6.6+ Linux Kernel
After you have downloaded the package, double-click and install it. Once installed you don’t need to do anything ! If everything went OK, laptop mode will be activated automatically the next time you unplug your laptop from the mains.
Tweak Laptop Mode Tools
If you are curious about the options available for Laptop mode Tools (I bet you are !) you can make some minor changes to its configuration file to make it correspond to your personal needs.
- Open as administrator/root/sudo the file at /etc/laptop-mode/laptop-mode.conf
- Read carefully the available options and only make changes to the one that you are sure about
- Save it and close it!
- You are done
For reference here is my changes :
# The drives that laptop mode controls.
# Separate them by a space, e.g. HD=”/dev/hda /dev/hdb”. The default is a
# wildcard, which will get you all your IDE and SCSI/SATA drives.
# The partitions (or mount points) that laptop mode controls.
# Separate the values by spaces. Use “auto” to indicate all partitions on drives
# listed in HD. You can add things to “auto”, e.g. “auto /dev/hdc3″. You can
# also specify mount points, e.g. “/mnt/data”.
# Read-ahead, in kilobytes. You can spin down the disk while playing MP3/OGG
# by setting the disk readahead to a reasonable size, e.g. 3072 (3 MB).
# Effectively, the disk will read a complete MP3 at once, and will then spin
# down while the MP3/OGG is playing. Don’t set this too high, because the
# readahead is applied to _all_ files that are read from disk.
Also, it is valuable to read the Frequently Asked Questions about Laptop Mode Tool, so please read some ports that I thought that are important and if you have more I include the link for more information
How do I check if laptop mode is enabled?
Execute cat /proc/sys/vm/laptop_mode. If it contains a nonzero value, then laptop mode is enabled, if it says 0, then it isn’t.
I have a solid-state disk (SSD) in my machine. Should I enable any of the disk-related parts of laptop-mode-tools, or are they irrelevant?
They may be relevant, because (a) laptop mode will reduce the number of writes, which improves the lifetime of an SSD, and (b) laptop mode makes writes bursty, which enables power saving mechanisms like ALPM to kick in. However, your mileage may vary depending on the specific hardware involved. For some hardware you will get no gain at all, for some the gain may be substantial.
Spinning down too many times may kill hard drives
Desktop hard drives are usually rated for only 40,000-50,000 spinups, and one spinup every 10 minutes will kill your 40,000-spinup HD in 277 days. So this is NOT recommended for server use, unless you increase the spinup interval dramatically, to say once every hour or two. Laptop hard drives are usually rated for around 300,000 spinups, so those will last about 2083 days or 6 years if you have them powered on 24-7.
I have an SATA disk and it doesn’t work.
Spindown timeouts don’t currently work on SATA drives, because the Linux kernel does not support that properly. There are patches available that add this support. Check out http://www.thinkwiki.org/wiki/Problems_with_SATA_and_Linux for all SATA-on-Linux problems. For laptop mode to work, you want the libata_passthru patch. It will be included in the Linux kernel starting from version 2.6.15. Note: You also need a recent version of hdparm in order to make this work!
If my machine crashes or runs out of power, will I lose all my work?
If you have laptop mode enabled and your machine crashes, then you will lose up to MAX_LOST_WORK_SECONDS seconds of work. If you really need to have something written to disk, issue the “sync” command. If you have laptop mode enabled and your machine runs out of power, you will not lose as much work (provided you have an ACPI laptop, as most current PC laptops are) because laptop mode is automatically disabled when the battery almost runs out.
What is the relationship between Laptop Mode Tools and the script in the kernel documentation?
Laptop Mode Tools is a fork of the script in the kernel documentation. The script in the kernel documentation is currently pretty much unmaintained AFAIK, so I don’t recommend using it.
I set PARTITIONS and now it doesn’t work anymore at all.
You have to include the default partitions (the partitions of the drives listed in the HD configuration setting) as well. In version 1.06 and higher you can use the “auto” keyword to indicate “and remount all of the default ones as well”. “Default” here means “partitions that contain the device name of a hard drive in HD”, i.e. if your partition is /dev/hda3 and you have HD=/dev/hda, then /dev/hda3 is part of the default partitions, but if it is aptly named
/dev/hdx7 then it isn’t.
I set REMOUNT_PARTITIONS to “/ /mnt /usr” and it doesn’t work.
You have to include the partitions’ devices, not their mount points. So you should list things like “/dev/hda2 /dev/hdb1″. If you’re using version 1.06 or higher than you don’t have this problem, as this version supports mount points as well as device names in REMOUNT_PARTITIONS (or PARTITIONS, as it’s called in the new config file format introduced in version 1.07).