Tuesday, January 5, 2010

Eee PC with Ubuntu (update)

I've done a bit of research today, and got a bit of a better "battery saving" setup for my laptop.

Saving your SSD disk

The default settings for Ubuntu are built to work with a spinning disk. Since you really want your disk to last as long as possible, it's better to minimize the disk writes.
Edit your fstab so that specific directories are sent to memory instead of disk:
tmpfs      /var/log        tmpfs        defaults           0    0
tmpfs /tmp tmpfs defaults 0 0
tmpfs /var/tmp tmpfs defaults 0 0
tmpfs /var/log/apt tmpfs defaults 0 0
From help.ubuntu.com.
The one thing that is annoying though, is anytime you run aptitude, it throws an error about /var/log/apt which it can't make...
So I added "mkdir /var/log/apt" to a start script.

Then You can point different applications to /tmp, for example Firefox:

  • Go to the address 'about:config.'
  • Create a new value 'browser.cache.disk.parent_directory' as a string and set it to '/tmp'
At first I was afraid it would just dump everything there, but don't worry. It makes the folder "Cache" in /tmp

Other Hard Drive tweaks

Another minor fix with the disk is to switch to "deadline". Run:
cat /sys/block/sda/queue/scheduler
and you'll probably get something like:
noop anticipatory deadline [cfq]
Apparently deadline and noop are the options, but deadline is better. Set it to deadline with this:
echo deadline > /sys/block/sda/queue/scheduler
This will need to be a start script.

We can also add FIFO queuing by running the command:

echo 1 > /sys/block/sda/queue/iosched/fifo_batch
Again, this resets on boot, so you'll need to make a start script.

Disabling/Controlling Hardware features

First off, You should install eee-control. The version for Karmic just recently came out, and isn't quite the same now that the developer is declared missing, but it will still turn on and off most of the things you need.

The one thing to note, is that I still haven't figured out how to get wireless to work. It's easy to turn on, but crashes when you turn it off. However, if you turn it off on start up (ie before the gui loads), then somehow it doesn't crash.

In anycase, I like to turn everything off on startup, so I'm going to add the following to a start script:

# camera
echo 0 > /sys/devices/platform/eeepc/camera
# card reader
echo 0 > /sys/devices/platform/eeepc/cardr
# wireless
echo 0 > /sys/devices/platform/eeepc/rfkill/rfkill0/state
That way if I need it, I'll turn it on. If I don't, then it won't use up battery. And Eee-control-tray makes it very easy to enable features when I need them.

Power Management

Ubuntu has some built in things to extend laptop battery life, and still maintain full power while plugged in, but not nearly what it could be.
For example. What if we want to turn our computer's proc the whole way up while we're on AC, turn brightness the whole way up, increase disk writes, and have the screen dim after 10 minutes:
echo 0 > /proc/sys/vm/laptop_mode
# turn brightness up the whole way
echo 15 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
# screen off after 10 minutes
xset dpms 0 0 600
Well, then we want quite a bit different for when the laptop goes into battery mode.
Check this out:
#!/bin/bash
if on_ac_power; then
# Reset back to normal settings
echo 0 > /proc/sys/vm/laptop_mode
# turn brightness up the whole way
echo 15 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
# disk
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
# proccessor on performance
echo 0 > /sys/devices/platform/eeepc/cpufv
# screen off after 10 minutes
xset dpms 0 0 600
else
# Turn on aggressive power savings
echo 5 > /proc/sys/vm/laptop_mode
# turn brightness down the whole way
echo 0 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
# disk
echo 40 > /proc/sys/vm/dirty_ratio
echo 10 > /proc/sys/vm/dirty_background_ratio
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# proccessor on powersave
echo 2 > /sys/devices/platform/eeepc/cpufv
# screen off after 2 minutes
xset dpms 0 0 120
fi
It just so happens that "on_ac_power" returns true if it's on AC power, and false if it's not.

This should be a power script (/usr/lib/pm-utils/power.d/).

Note: on a clean install this should work, though there have been some issues. Make sure you don't link, but actually copy the script, and have the right permissions. Using the "install" tool is recommended.

Start scripts (and action scripts)

So since this post depends so much on action scripts, here's how to make them.

The folders for the ones we've found today are as follows:

 scripts run on startup:    /etc/rcS.d/
scripts on power (on/off): /usr/lib/pm-utils/power.d
The job is pretty easy. What you need to do is write the script, copy it to the folder, and then set it to be executable (the last two actions can be done with one command: the "install" tool.

First, write the script. In this case I have three start scripts:

S95make_tmp_folders

 # apt log
mkdir /var/log/apt\

S96disk_editing

 # Deadline
echo deadline > /sys/block/sda/queue/scheduler
# FIFO
echo 1 > /sys/block/sda/queue/iosched/fifo_batch

S97turn_off_hardware

 # camera
echo 0 > /sys/devices/platform/eeepc/camera
# card reader
echo 0 > /sys/devices/platform/eeepc/cardr

After each file is written, simple run:

install {filename} /etc/rcS.d/
and the file will be installed to this folder.

In the case of our power script we want it to be run on start up, power flux. So we'll run:


install 99power_save /usr/lib/pm-utils/power.d
install 99power_save /etc/rcS.d
Where 99power_save is the name of the script that we wrote above.

1 comment:

  1. So, just fyi, but I think I screwed up on the different /etc/rc* folders.
    Check out
    http://www.debianadmin.com/debian-and-ubuntu-linux-run-levels.html
    I think /etc/rcS.d/ is the wrong folder...

    ReplyDelete