Battery Powered Linux Mini-HOWTO Hanno Mueller, hanno@lava.de http://www.lava.de/~hanno/ Dec 21, 1997 This document describes how to reduce a Linux system's power consump­ tion by tweaking some of its configuration settings. This will be helpful for everyone who runs Linux on a portable computer system. There is also some general information about how to take care of your battery. If you are using Linux on a desktop system, you probably don't need to read all this. 1. Introduction ``Ages 6 and up. Batteries included.'' 1.1. Before you ask This document does not describe how to install Linux on laptops, but how to optimize a ready-configured Linux for use on laptops. Please read the Installation-HOWTO or your distributor's handbook for help with installing Linux. This document does not describe how to use an uninterruptable power supply and the powerd daemon, either (even though a ups is a big battery). Read the UPS-HOWTO for details about that subject. 1.2. What this document is about More and more people own portable computers these days and in turn, more and more people install Linux on such machines. Installing and using Linux on a laptop is usually no problem at all, so go ahead and give it a try. Unlike some other operating systems, Linux still supports and runs well on even very old hardware, so you might give your outdated portable a new purpose in life by installing Linux on it. If you need help with installing Linux on a laptop or if you have questions about laptop hardware, you can check the excellent Linux Laptop webpage at http://www.cs.utexas.edu/users/kharker/linux-laptop/ where you will find a lot of useful information and detailed help. The Linux Laptop page describes hardware configuration for specific laptop models and chipsets. This HOWTO however will focus on the one problem that is common to all portable systems: Power consumption. Yet, I have not found a Linux distribution that comes with a configuration optimized for laptops. Since I could not find this kind of information anywhere else, I have started to collect a few simple but effective tricks that will help you save battery power and in turn increase your system's uptime while running on battery. (Sidenote. I received a complaint by a reader that these tips were not very effective with his laptop. So does all this really work? Yes, but don't expect miracles. I was able to increase my laptop's battery time from 90 minutes to more than 120 minutes.) 1.3. Roadmap If you are a laptop pro, you can probably skip the ``General Information'' section. If you are a Linux pro, what you really want to know can be found in the ``Changing some general system settings'' section. If you are a Linux distributor, please read ``A message to Linux distributors''. 1.4. Feedback Your feedback is welcome. Please send comments to hanno@lava.de. Did it work on your system? Do you have new tips? Are there any outdated links or addresses in this text? I am sorry, but I will not be able to help you with questions about specific laptop models. I don't claim to be a laptop guru, I just happen to own one laptop myself and I simply want to share the information I collected. Please check the Linux Laptop webpage first, probably someone else has already written a page dedicated to your model. Ask your manufacturer's technical support. Or go the the laptop newsgroup comp.sys.laptops and ask there. 1.5. Disclaimer All methods described here were tested by me and worked fine on my laptop, unless noted otherwise. However, I cannot guarantee that any of this won't crash or seriously damage your system. Life is dangerous, so keep backup copies of your important files before playing with your Linux configuration. If things go wrong, I do not take any responsibility for your data loss. In other words: Don't sue me. Thank you. 1.6. Copyright This document shall be distributed under the standard HOWTO-copyright notice, found in the HOWTO folder at http://sunsite.unc.edu/mdw/linux.html. 2. General information This section describes a few technical things about laptop batteries and some general power saving tips. This information is not Linux- specific and if you are experienced with laptops, you might already know all this. 2.1. Be kind to your battery (Please note the ``credits'' for this section.) There are currently three types of batteries commonly used for portable computers. · NiCd batteries were the standard technology for years, but today they are out of date and new laptops don't use them anymore. They are heavy and very prone to the ``memory effect''. When recharging a NiCd battery that has not been fully discharged, it ``remembers'' the old charge and continues there the next time you use it. The memory effect is caused by crystallization of the battery's substances and can permanently reduce your battery's lifetime, even make it useless. To avoid it, you should completely discharge the battery and then fully recharge it again at least once every few weeks. (A sidenote about the memory effect. James Youngman knows of a rather drastic method to - uhm - ``repair'' batteries: ``If your NiCd battery is suffering from the memory effect, remove it from your computer, hold it about 30cm above a desk or the floor, and drop it (make sure it lands flat).'' He says that this will break the whiskers that have formed in the battery and that are the cause of the memory effect if your battery is already affected by it. ``I don't know if this works for non-NiCd batteries or not.'') Cadmium is a very hazardous poison, but if returned to your dealer, the material can almost be fully recycled. Just in case you might be interested, here are some specs for NiCd: Cell voltage: 1,2 V Energy / mass: 40 Wh/kg Energy / volume: 100 Wh/l max. Energy: 20 Wh Charge temp.: 10 to 35 C (50 to 95 F) Discharge temp.: -20 to 50 C (-5 to 120 F) Storage temp.: 0 to 45 C (30 to 115 F) · NiMh batteries are the current standard used in most low price laptops to date. They can be made smaller and are less affected by the memory effect than NiCd. However, they have problems at very high or low room temperatures. And even though they use less hazardous and non-poisonous substances, they cannot be fully recycled yet (but this will probably change in the future). NiMh specs: Cell voltage: 1,2 V Energy / mass: 55 Wh/kg Energy / volume: 160 Wh/l max. Energy: 35 Wh Charge temp.: 10 to 35 C (50 to 95 F) Discharge temp.: 0 to 45 C (30 to 115 F) Storage temp.: 0 to 30 C (30 to 85 F) · The new high performance batteries use LiIon technology. In theory, there is no memory effect at all with these batteries, but on occasion, they seem to have similar problems. Their substances are non-hazardous to the enviroment, but they should be returned for recycling as well. LiIon specs: Cell voltage: 3,6 V Energy / mass: 100 Wh/kg Energy / volume: 230 Wh/l max. Energy: 60 Wh Charge temp.: 0 to 45 C (30 to 115 F) Discharge temp.: -20 to 60 C (-5 to 140 F) Storage temp.: -20 to 60 C (-5 to 140 F) Even if the battery case looks the same, you cannot just upgrade to another battery technology. The recharging process is different for the kind of battery you use. Some manufacturers integrate the recharging circuit inside the laptop's external ac adapter, so you might just get away with buying a new power supply to upgrade. A good indication for an external recharging unit is when your ac adapter uses a proprietary connector with a lot of power lines. Other manufacturers put the recharging unit inside the laptop case where users cannot simply replace it with a newer technology. If your ac adapter only uses two power lines to connect to the computer (just like mine), the recharging unit is probably inside the laptop. When in doubt, ask your manufacturer if your laptop supports a more modern battery. A battery that is not used for a long time will slowly discharge itself. And even with greatest care, a battery needs to be replaced after 500 to 1000 recharges. But still it is not recommended to run a laptop without the battery while on ac power - the battery often serves as a big capacitor to protect against voltage peaks from your ac outlet. As the manufacturers change the shapes of their batteries every few months, you might have problems to find a new battery for your laptop in a few years from now. Buy a spare battery now - before it's out of stock. 2.2. Power saving - The obvious stuff There are some obvious things that you can do to reduce your system's power consumption. Well, maybe not so obvious, since not very many people follow these rules... · Decrease or turn off your display's backlight when you don't need it. By the way, tft displays use more power than dstn (so now you have a fine excuse why you bought the cheaper laptop...). (David Bateman tells me that using a crt screen while on battery and turning off the laptop display will extend battery time by about 30%: ``Not that this is a very useful piece of knowledge though, if you've got the crt plugged in then why not the laptop too.'') · How much processing power do you really need? I doubt that you will be doing very much more than text editing when on the road (well, at least I don't compile linux kernels then). While on battery, reducing the cpu clock speed will decrease power consumption, too. Quite a few laptops offer a cpu clock selector that will toggle between normal and slow speed. · Turn off the cpu cooler (if you have one). Many recent laptops offer a bios option called ``cooling control''. If your system's cpu is becoming too hot, this option allows you to have it cooled by a tiny fan (setting ``performance'') or to have its cpu clock slowed down (setting ``silence''). To increase your uptime while on battery, use ``silence''. · Avoid using external devices (printer, crt screen, zip drive, portable camera etc.) with your computer while on battery. When connected to a standard ink jet printer, my laptop's battery time is reduced from up to 120 minutes down to 20 minutes. · Avoid using any built in device unless necessairy: Diskette drive, harddisk, cd-rom. Especially cd-rom access will dramatically decrease your battery time. · Pcmcia cards can also consume a lot of power, so don't leave your modem or network adapter plugged in when it is not in use. But this is different between the various pcmcia manufacturers, so check the product specs before you buy (e. g. some cards never turn themselves off even when not in use). (By the way, I recently read that pcmcia cards are the biggest problem for windows ce palmtops - they drain so much power that the tiny machines' little batteries have to be replaced within minutes...) · Use simple software. A full blown multimedia application will create a lot more system load and harddisk / cd-rom activity than a small simple word processor. · Grant Taylor has a tip for those of us who want to upgrade their system: ``Newer versions of some upgradable components consume less power. For example, IBM's Travelstar 2.5 inch 1.6 gigabyte ide harddisk drive consumes 20 percent less than the 500 megabyte toshiba harddisk my laptop came with.'' · If you are yet about to buy a laptop - don't buy a laptop with a 2nd level cache if battery uptime is important. A computer with 2nd level cache is about 10% to 20% faster and it will be a lot better with multimedia applications and number crunching, but it consumes a lot of power. Bjoern Kriews tells me that he has two almost identical laptops and the one without cache ram runs 4h30 compared to 2h30 with cache. If you already have 2nd level cache installed, turning it off will probably not help you very much. Give it a try and write me about your experience. · Another tip for those still buying a laptop - don't buy the latest, fastest cpu type. Usually, the older generations are optimized by the manufacturer after some time without notice. The ``new'' versions of old cpu types often create less heat and consume less power than the product's premiere version. There are also frankenstein laptops available that use cpus not optimized for portable systems. As I wrote this in May 97, the newest generation pentium-200 laptops ran about 20 minutes on battery and became so hot that they burnt your lap. When writing the second revision in Oct 97, pentium-233 laptops run two hours or longer without ac power. Go figure. Well, you get the idea. Most of these are restrictions that will probably stop you from doing any serious work with your Linux system. (The best way to save power while on battery is... not to do anything at all. That increases my laptop's battery uptime by almost 100 percent.) So let's go ahead to some other, more useful measures that will save power without disturbing your work. 3. Advanced Power Management Portable systems in general, but even many desktop computers come equipped with support for apm, the ``advanced power management'' scheme. This section describes how to activate apm support in your Linux kernel. People who are experienced with Linux may find this section rather boring and want to skip to the next. 3.1. What APM can do for you I won't describe it in detail here, check the Linux APM drivers page at http://www.cs.utexas.edu/users/kharker/linux-laptop/apm.html for more information. All that you need to know is that with the help of apm, the cpu can tell the bios when there's nothing really exciting going on so that the bios can take care of some power saving by itself - e. g. reducing the cpu clock, turning off the harddisk, turning off the display's backlight etc. Apm is also responsible for the ``system suspend'' (or ``sleep'') mode and for the ``suspend to disk'' (or ``hiberntation'') mode. And yet another cool, though not very important feature is that with the help of apm, shutdown -h will not just halt your system, but also turn it off. (By the way, most Linux systems put a shutdown -r in their /etc/inittab and map it to pressing control-alt-delete. I prefer having shutdown -h there, so when pressing the famous key combination, my laptop simply turns itself off.) Not all manufacturers implement a correct apm bios, so some laptops have trouble with the Linux apm drivers (if your machine has trouble with apm, it will most likely either lock up at Linux' boot up or after returning from suspend). If you are not sure, check the Linux laptop page for your specific model. 3.2. How to activate APM support in Linux It's easy - just recompile the Linux kernel. Check the Kernel-HOWTO if you don't know how to do that. When the configuration script reaches the ``character devices'' section, the default setting for full apm bios support in kernel version 2.0.30 or higher is: Advanced Power Management BIOS support: Yes Ignore USER SUSPEND: No Enable PM at boot time: Yes Make CPU Idle calls when idle: Yes Enable console blanking using APM: Yes Power off on shutdown: Yes Please read the configuration script's help texts. They explain in detail what each option does, so I won't repeat them here. If your system does not fully support the apm bios standard, some of those options might crash your system. Test all apm features with the new kernel to make sure that everything works as it should. (A sidenote about console blanking: David Bateman tells me that you should not enable it because it can cause problems with the current version of XFree 3.2: ``The symptoms are that the screen will be blank when X starts, and it can be fixed usually by just hitting a key. It's a small but annoying problem. The next relase of XFree, will have pretty good DPMS support for a lot of laptop chipset, which should include code to turn off the LCD. Check out the manpage for xset in XFree 3.2A.'' David also notes that the lifetime of your display's backlight is determined by the number of times it's switched on and off: ``So its a compromise, lifetime of the battery versus lifetime of the backlight.'') (Update: With XFree 3.3, this problem still remained on my laptop. I am told that this will be fixed in a future kernel version.) 3.3. APM support and the PCMCIA drivers After recompiling the kernel, don't forget to recompile the linux pcmcia drivers as well. The precompiled pcmcia drivers that come with most linux distribution have apm support disabled, so that the bios can't instruct your card adapters to turn off. Also, you must recompile the drivers if you upgrade to a new kernel version and your old kernel was compiled with module version information turned on (this option is found in the ``loadable module support'' section of the kernel configuration). Read the PCMCIA-HOWTO for detailed instructions on how to compile the drivers or go to the Linux PCMCIA drivers homepage at http://hyper.stanford.edu/HyperNews/get/pcmcia/home.html. 3.4. The apmd package Now that you have APM support installed, go and get the apmd package from the Linux APM drivers page. You don't really need it, but it is a very useful collection of programs. The apmd daemon logs your battery's behaviour and it will send out a warning if you are on low power. The apm command will suspend your system with a shell command and xapm shows the current state of your battery. (BTW, if you have problems with pcmcia cards after returning from suspend, you can check out an alternative apmd package at http://www.cut.de/bkr/linux/apmd/apmd.html. It unloads the pcmcia driver module before going to suspend and reloads the module on resume.) Grant Taylor has been playing a little with the apmd package and came up with helpful tips. He found that his laptop's harddisk forgets its hdparm -S standby period when returning from suspend: ``I modified apmd to reset this setting on each resume. This may be system-specific; but it's an important thing to do...'' (Note: On my own laptop, the bios takes care of the harddisk standby period and resets the value on resuming. So I could not test if this little problem is system-specific. If it happens to you as well, send me a message.) Grant also had a nice trick for screen blanking with ``the XFree86 package'' and the help of the apmd package, you'll find it there. 3.5. And if my laptop does not support APM? If your computer's bios does not offer any power saving settings (even the old ones without apm should at least allow to set harddisk and display standby), you can use hdparm -S to define your harddisk's standby period. This will already help a lot, since harddisk activity consumes a lot of power. Your system should have hdparm installed, so read man hdparm for the command syntax. 4. Changing some general system settings After I got Linux up and running on my laptop, I found it accessing the harddisk every few seconds, even when there was no user logged in to the system. The harddisk could never enter its power saving mode. Reducing harddisk activity can greatly increase the battery runtime, so this is why I collected the following recipes. I tested all this with RedHat 4.1, the locations of some configuration settings may be different for your distribution. (If so, please let me know.) 4.1. The crond daemon and atrun Check your /etc/crontab file if it starts a process every minute. You will often find atrun there. With the at command, you can spool commands that must be invoked some time in the future. Some Linux systems use a dedicated atd daemon to take care of this, others (e. g. RedHat) let the crond daemon run atrun once every minute. This is not really necessairy on most systems, since at commands rarely depend upon being invoked on exact time. So if you find a line like this in your /etc/crontab: # Run any at jobs every minute * * * * * root [ -x /usr/sbin/atrun ] && /usr/sbin/atrun Then you can safely change this to: # Run any at jobs every hour 00 * * * * root [ -x /usr/sbin/atrun ] && /usr/sbin/atrun Read man 5 crontab for details. Some folks can even work fine without the crond daemon, so if you know what you are doing, you might want to consider disabling it completely. 4.2. The update / bdflush daemon Linux deals with a lot of open file buffers at any given moment, so the system must make sure that file changes are saved to the harddisk as soon possible. Otherwise, those changes will be lost after a system crash. The update / bdflush daemon takes care of this. (These are two names for the same program, so you can use either name to start the daemon). The default settings will make this daemon call flush every 5 seconds and sync every 30 seconds. With my Fujitsu disk this caused non-stop access. (It seems that this harddisk flushes its ram cache even when nothing has changed. But this depends on your harddisk's firmware: Other people told me that their harddisk does enter its power saving mode even without the following modification.) Since Linux does not crash very often anymore, I have changed both values to 3600 seconds (= one hour). This caused no problems at all and the constant disk access has stopped. (But if my system crashes now, there will be more broken files, of course.) RedHat 4.1: In /etc/inittab, change the update call to: ud::once:/sbin/update -s 3600 -f 3600 Suse 4.4.1: update is called in /sbin/init.d/boot. Slackware: update is called in /etc/rc.d/rc.S. See man update for details. 4.3. The syslogd daemon The syslogd daemon is responsible for the various Linux system log files that are found in the /var/log/ directory. By default syslogd will sync the log file each time after logging a system message. You can turn that off by preceding the filename with a dash in /etc/syslog.conf. Here's an example as found in my system's syslog.conf: # Log anything (except mail) of level info or higher. # Don't log private authentication messages! *.info;mail.none;authpriv.none -/var/log/messages This again means that if the system crashes, the message that reported the problem may not have been stored to disk. Dilemma... 4.4. The init command During the bootup, the initial processes and daemons will be started using the init command. This command (yet again) calls sync before each process it creates. You can change this by removing the sync() call in the source code and recompiling the command. To avoid problems with lost file buffers, you should add a call to sync in your system's /etc/rc.d/init.d/halt script, right before the script unmounts the file systems. 4.5. The swap partition The Linux swap partition is used to increase the physical ram space with virtual memory. This again is a possible reason for harddisk access. If your laptop already has a lot of ram or if the applications that you use are quite simple (think of vi), you might want to consider turning it off. This of course depends on what you plan to do. 4 to 8 megs are not enough, you must use a swap partition then. With 8 to 16 megs, text console applications will work fine and if you can avoid using a lot of multitasking features, you can safely disable swap. The X-Windows enviroment requires a lot of ram and you should not use it without a swap partition unless you really have a lot more than 16 megs. (Sidenote: My laptop with 16 megs and disabled swap partition can run an emacs session, four bash shells and compile a kernel without running out of memory. That's enough for me.) If you already have installed a swap partition, you can disable it by preceding the swapon command that is called in /etc/rc.d/rc.sysinit with a hash mark. If you don't want to make it a permanent move, let the system ask during boot if you want to use the swap partition. In /etc/rc.d/rc.sysinit (RedHat 4.1) or /sbin/init.d/boot (Suse 4.4.1): echo "Should the system use swap?" echo " 0: No." echo " 1: Yes." /bin/echo "Your choice: \c" read SWAPCHOICE case "$SWAPCHOICE" in 0) # Do nothing. echo "(Swap partitions disabled)" ;; *) # Start up swapping. echo "Activating swap partitions" swapon -a esac Then you can use the swap partition while on ac power and drop it while on battery. 4.6. The apache httpd webserver daemon I am using my laptop to develop and test cgi scipts for websites, that is why I am running a local webserver on it. The standard configuration is a bit too much if all you want to do is just test a script or check a page from time to time. In httpd.conf, just change the values of MinSpareServers and StartServers to 1. This will be enough for a local test site. If you wish to turn off the webserver's logging, you must recompile the httpd daemon. Read the documentation for details. Grant Taylor recompiled apache's logging and found that this ``didn't make it stop churning the disk. So I used another, IMHO better, solution: I configured apache to run from inetd instead of standalone.'' Read man inetd for details. 4.7. The XFree86 package Configuring XFree86 for laptops is a story of its own. And yet again, I have to refer you to the Linux Laptop page where you will find a lot of help on this. X's console blanking only turns the screen black, but does not turn it off. As mentioned in the ``sidenote about console blanking'', you can use xset's dpms option to change this. However, this feature depends on your laptop's graphics chipset and bios. Grant Taylor uses the following setup to send his laptop to sleep with the help of apmd and the screensaver: # Run xscreensaver with APM program xscreensaver -timeout 5 \ -xrm xscreensaver.programs:apm_standby \ -xrm xscreensaver.colorPrograms:apm_standby & Where ``apm_standby is a suid perl script that allows only certain people to run apm -S.'' 4.8. The emacs editor Ok, emacs is not an editor, but a way of life. Here's a tip from Florent Chabaud: ``If you use emacs, perhaps you have noticed that the editor makes some automatic saves. This is of course useful and should not be disabled, but the default parameters can be adjusted to a laptop use. I have put in the file /usr/share/emacs/site-lisp/site-start.el the two following lines: (setq auto-save-interval 2500) (setq auto-save-timeout nil) This disables auto-saving based on time, and makes the auto-saving be done every 2500 keyboard actions. Of course if you are typing a text this last parameter should be reduced, but for programming it is sufficient. Since every action (up, down, left, backspace, paste, etc...) is counted, 2500 actions are reached very rapidly.'' 4.9. How to find more ways to optimize If your Linux system still seems to access the harddisk too often, you can find out what is going on inside by using the ps ax command. This will show all running processes and their full name, sometimes it also reveals the command line arguments of each process. Now read the man page of each process to find out what it does and how to change its behaviour. With this method, you will most likely find the process that is responsible. You may also find strace helpful. Please send me an email if you found something new. 5. Appendix 5.1. A message to Linux distributors If you happen to be a Linux distributor, thank you for reading all this. Laptops are becoming more and more popular, but still most Linux distributions are not very well prepared for portable computing. Please make this document obsolete and change this for your distribution. · The installation routine should include a configuration, optimized for laptops. The ``mimimal install'' is often not lean enough. There are a lot of things that a laptop user does not need on the road. Just a few examples. There is no need for three different versions of vi (as found in Suse Linux). Most portable systems do not need printing support (they will never be connected to a printer, printing is usually done with the desktop system at home). Quite a few laptops do not need any network support at all. · Don't forget to describe laptop-specific installation problems, e. g. how to install your distribution without a cd-rom drive or how to setup the plip network driver. · Add better power management and seamless pcmcia support to your distribution. Add a precompiled kernel and an alternative set of pcmcia drivers with apm support that the user can install on demand. Include a precompiled apmd package with your distribution. · Add support for dynamically switching network configurations. Most Linux laptops travel between locations with different network settings (e. g. the network at home, the network at the office and the network at the university) and have to change the network id very often. Changing a Linux system's network id is a pain with most distributions. Please mail me if your distribution is optimized for portable computing and what kind of features you added for that. Future versions of this HOWTO will include a section where you can advertise your distribution's laptop features. 5.2. Credits · The information about battery technology is mostly based on the article ``Stromkonserve'' by Michael Reiter, published in ``c't Magazin fuer Computertechnik'' (Heise Verlag Hannover, Germany), edition 10/96, page 204. Used by permission. Visit their website at http://www.heise.de/. · The following people contributed to this document: Frithjof Anders David Bateman Florent Chabaud Markus Gutschke Kenneth E. Harker Bjoern Kriews R. Manmatha Juergen Rink Grant Taylor James Youngman 5.3. About this document This text mentions batteries 53 times. The current version of this and many other HOWTOs, most of them a lot more useful than this one, can be found at the main Linux documentation site http://sunsite.unc.edu/mdw/linux.html or at one of its many mirror sites. Most of this text was written during my trips between Hamburg and Hannover on German rail. (The new ice-2 coaches have power outlets for laptops, yeah!). And now hum along with me: ``...on the road again...''