Longer Battery Life

When I saw Harald Sitter’s post about longer battery life on Linux, I decided to give it a try. Especially since, at the time, he hadn’t posted his script. Here is what I came up with:

  #!/bin/sh    # powertop says beagle takes up a lot of power  killall beagled    ###############################################  # http://www.lesswatts.org/tips/disks.php  # Disks!  ###############################################    # I don't need no stinkin' atime  sudo mount -o remount,noatime /    # Laptop mode works by submitting all future pending disk IO (such as  # pending VM cache writebacks as described in the VM writeback time tip)  # at once when the kernel has to do an IO to the disk for any reason  sudo sh -c 'echo 5 > /proc/sys/vm/laptop_mode'    # Only write to disk every 15s - we have a battery and few crashes.   sudo sh -c 'echo 1500 > /proc/sys/vm/dirty_writeback_centisecs'    # Turn on power management after 1 minute  for i in `echo /dev/sd?`; do      [ -e $i ] && sudo hdparm -B 1 -S 12 $i  done    # Turn off cdrom polling  for i in `echo /dev/scd?`; do      [ -e $i ] && sudo hal-disable-polling --device $i  done    ###############################################  # http://www.lesswatts.org/tips/wireless.php  # Wireless!  ###############################################    # WiFi power saving  sudo iwpriv eth1 set_power 5    # turn off bluetooth  sudo /etc/init.d/bluetooth stop  sudo modprobe -r rfcomm  sudo modprobe -r l2cap  sudo modprobe -r bluetooth    ###############################################  # http://www.lesswatts.org/tips/cpu.php  # CPU!  ###############################################    # Enable the power-aware SMP scheduler  sudo sh -c 'echo 1 > /sys/devices/system/cpu/sched_mc_power_savings'    ###############################################  # http://www.lesswatts.org/tips/ethernet.php  # Ethernet!  ###############################################    # turn off gigabit ethernet  sudo ethtool -s eth0 autoneg off speed 100    # turn of WOL  sudo ethtool -s eth0 wol d    ###############################################  # http://www.lesswatts.org/tips/graphics.php  # Graphics/Video!  ###############################################    # turn the LCD backlight down to 12%  # I found that xbacklight only works for certain values on my x60  xbacklight -set 12    # Turn off screen aff after 2minutes  xset +dpms  xset dpms 0 0 120    ###############################################  # http://www.lesswatts.org/tips/misc.php  # Misc!  ###############################################    # Turn on audio power saving  if [ -e /sys/module/snd_hda_intel/parameters/power_save ]; then      sudo sh -c 'echo 10 > /sys/module/snd_hda_intel/parameters/power_save'  fi    if [ -e /sys/module/snd_ac97_codec/parameters/power_save ]; then     sudo sh -c 'echo 1 > /sys/module/snd_ac97_codec/parameters/power_save'     sudo sh -c 'echo 1 > /dev/dsp'  fi  

Of course, you’ll want something to turn everything back on when you get back on power:

  #!/bin/sh    # Turn Beagle back on!  beagled&    # Turn off wifi powersaving  sudo iwpriv eth1 set_power 6    # Write to disk more often  sudo sh -c 'echo 300 > /proc/sys/vm/dirty_writeback_centisecs'    # Disable the power-aware SMP scheduler  sudo sh -c 'echo 0 > /sys/devices/system/cpu/sched_mc_power_savings'    # turn on bluetooth  sudo modprobe bluetooth  sudo /etc/init.d/bluetooth start    # turn on gigabit ethernet  sudo ethtool -s eth0 autoneg on speed 100    # turn the LCD backlight up  xbacklight -set 100    # Turn off screen aff after 30 minutes  xset +dpms  xset dpms 0 0 1800    # Turn on cdrom polling  for i in `echo /dev/scd?`; do      [ -e $i ] && sudo hal-enable-polling --device $i  done  

Note that I don’t reverse every step in my power-saving script. Just most of them.