Monday, September 1, 2008

airplanemode.sh

I've mentioned this script to a couple of people, and I thought I might share where it's at right now, in case anybody's interested. A lot of the commands in here are things that I got from a program called PowerTOP, which I think is indespensible to anybody planning on using their laptop with a battery. This script runs on Ubuntu 8.04 (Hardy Heron) on a Thinkpad R61i, but I think it could be easily adapted to your own environment. In my case, it extended the life of my 4 cell battery from about 1 1/2 hours to almost 3 1/2 hours (even watching movies from the hard drive).

Most of these options are pretty self-explanatory to the professional Linux user, who should adapt them for their own needs. For instance, I definitely would take out the "hal-disable-polling" option if I planned on using the optical drive. And yes, I do run both MySQL and PostgreSQL at the moment (long story, but it's only temporary), I expect you'll only be running one of them, assuming you run either at all. But I found disabling them to add an extra 15 minutes or so to my normal 1 1/2 hours, and that's a lot.

A note about brightness. I don't mind turning the brightness down all the way anyway, at least on an airplane. I can still see it just fine. I did discover something interesting about the brightness though. If you go to System >> Preferences >> Power Management and click the "On Battery Power" tab, you will find an option for "Dim display when idle" and another for "Reduce backlight brightness". This seems like a good idea at first. If you don't touch your notebook for a couple of minutes (on full brightness), it will turn the brightness down for you. When you press a key in this state, it turns it back up to 50% brightness. The problem is, if you were already at 20% (the lowest value that seems to work, which is what my script sets it to) before the system went idle, it still turns it up to 50%.

Imagine that, a power saving option that, in the wrong hands, actually wastes power. I'm sure this is a kernel option in /proc/ or /sys/, but I haven't found it yet to add to my script. In the meantime, I just took the checkmarks out of those boxes. If anybody knows where those settings are, I would love to add them to my script.

I don't have a more elegant way at the moment to kill NetworkManager. Then again, I haven't really looked. I do know that Red Hat likes to use an /etc/init.d/NetworkManager script, but Ubuntu seems to be without. If you know of a more graceful way to kill it, let me now.

It should also be noted that this script is for somebody that turns their notebook on while on battery power, and then turns it off when finished. If you plan on using suspend or sleep modes (neither of which I really care for), you may want to rethink some of the other lines in here. I'm thinking about setting up a Grub option for this script, and maybe setting up a different runlevel (maybe the infamous runlevel 4?) to handle the /etc/init.d/ services for me. Add that to the "when I get around to it" list. On that note, it should be obvious that this script needs to be run as root (or at least with sudo), but I thought I'd toss in a reminder anyway.

Without any further ado, the script:

echo 20 > /proc/acpi/video/VID0/LCD0/brightness
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
hal-disable-polling --device /dev/cdrom 'hal'
ethtool -s eth0 wol d
modprobe -r hci-usb
/etc/init.d/apache2 stop
/etc/init.d/mysql stop
/etc/init.d/postgresql-8.3 stop
/etc/init.d/avahi-daemon stop
/etc/init.d/cupsys stop
/etc/init.d/bluetooth stop
/etc/init.d/dhcdbd stop
/etc/init.d/winbind stop
/etc/init.d/stunnel4 stop
/etc/init.d/bluetooth stop
/etc/init.d/networking stop
pkill NetworkManager

No comments:

Post a Comment

Comments for posts over 14 days are moderated

Note: Only a member of this blog may post a comment.