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.

Wednesday, December 16, 2009

Tale of Three Music Players

Once upon a time I used Amarok. Those were the good days. MySql Databases with statistics, etc. Then Amarok 2 came along. I figured out a way to go back to my former love, with the capabilities instead of cheesy looks.
But this didn't last forever, for then I got a Eee PC, and due to my laziness, I didn't install amarok1.4 (the good one). Instead, since I had lost my database, I tested Rhythmbox.

Rhythmbox was good to me for a while. We played many a piece of music together. Then a friend encouraged me to test out Banshee. Banshee did scores just like Amarok did! So I tried it out.

Banshee had everything I would want in a music player. It had scores (though not nearly as good as I had remembered amarok), it handled libraries for videos, and even though I couldn't embed my tags in the videos, it tagged the videos. What Rhythmbox didn't have was a good library organization, and Banshee handled that too! (kinda... it sorta did it while it was going instead of all at once like I would have wanted... leaving half my music sorted and the other half messy in the same folder).

But Banshee was still new, and so didn't have a good relationship with mp3s. In fact, my poor flash drive was being read/written the whole time the song was playing, so I decided that this was reason enough to go back to Rhythmbox. After all, it's the tried and true that keep us going. Besides, Rhythmbox could handle me dropping new files into the folder right away.

Soon, I bought a CD. Without proper CD ripping equipment, I was forced to copy the *.wav files off the CD, and then encode to mp3. But the mp3s were tagless.
So I tagged them in Rhythmbox.
But Rhythmbox couldn't sort them. Instead I had to deal with "Track 1.mp3" files. Which was unacceptable. If I do this with another CD, the files would get replaced!

Then I discovered a program. EasyTag. EasyTag easily tags the mp3s and sorts them.

So I ran it. The mp3s was now organized.

But my playcounts!! They were gone! Rhythmbox couldn't handle the files being in a new location!


So then I remembered my former love. Even without MySql Amarok is superior in all functionality.


Amarok:
  • Score and Playcounts (which happen to be smarter then Banshee)

  • Scripts/Plugins

  • Lyric support (you know... for my Swahili/Kikuyu music)

  • Last.fm Support (+ queuing if offline)

  • Smart Playlists

  • Good Random tool for Playlist

  • Organize Mode

  • Album Cover Organizer

  • (+ A lot of other options.. in 1.4)


Rhythmbox:
  • Playcount

  • Hot Scanning

  • Very stable

  • Random tool for Now Playing

  • Lyric searching

  • Last.fm support (+ Queuing if offline)

  • Easy to add covers to CURRENTLY playing song


Banshee:
  • Playcount/Score (inferior)

  • Lyric support

  • Unstable

  • Last.fm

  • No organize mode, but it organizes...kinda

  • Video Library!

Tuesday, November 24, 2009

Eee PC (Ubuntu)

The Eee PC is quite a effective, and small unit. It's lasted three months in my hands, which is probably a good sign (realizing how I've screwed up the keyboard with soapy-wet hands)

Ubuntu Netbook remix made a big leap in the latest release, also.
Maximus seems more stable, and the layout is quite a bit better.



The main problem is when you switch to Ubuntu there are certain features, like disabling:
- Camera
- Card Reader
- Wireless
That you can't fully control. Sure you can disable the "wireless" in Ubuntu, but the actual wireless card is still on unless you disable it in bios.

eee-control fixes this though.
The version in Jaunty is quite effective. It controls wireless, camera, card reader, brightness, processor and fan speeds, and probably some other things I forgot.

If you like the newest version of Ubuntu (9.10), then you're out of luck. Building eee-control fails.
Rumor has it that the karmic build will be available soon.

Wednesday, November 18, 2009

Mutt: Scripting mail

With 'mutt' we can generate e-mails and have them sent to our default e-mail address, in this case me@domain.com
mutt -s "Subject line here" me@domain.com < /path/to/message
is the correct command for this e-mail address. You can find more details at http://www.cyberciti.biz/tips/sending-mail-with-attachment.html or the man page of mutt.

In the end, my script looks like this:
# Sends the IP address to default address
to="me"
from="noreply"
domain="domain.com"
temp=`mktemp -t`
ifconfig ppp0 > $temp
mutt -e "set from=$from@$domain" -s "IP address - $HOSTNAME" "$to@$domain" < $temp

$HOSTNAME is set based off the hostname of the computer. In my case this name is specific to the location and is unique. This helps me know which school I'm contacting.
The other main addition is the "-e" command.
If you look online you'll find that in order to send from a specific domain, you need to set up a muttrc file. Since we're running a script, and it makes more sense to keep everything together, I decided it's better to just add the "set from=" command in the script instead of an outside file.
The "-e" command lets you do this. It must be in quotes, otherwise it'll throw an error.

This is also added to the ip-up script that is run when ppp0 makes a connection.

You'll then need to make sure that postfix is installed. The best way, is to set up postfix and have it send through a designated email address. I simply set up a "noreply" email address on our domain that I would log into to send the email.
You can find instructions here: http://serverfault.com/questions/119278/configure-postfix-to-send-relay-emails-gmail-smtp-gmail-com-via-port-587/119296#119296

Squid -- Transparency

Edit: updated for what I'm currently doing in 10.04 and 10.10 (ubuntu)

A few guides gave ideas on how to get iptables to work:
# Add to IP tables
# squid server IP
lan=`ifconfig -s | grep eth | awk '{print $1}'`
s_port="3128"
iptables -t nat -A PREROUTING -i $lan -p tcp --dport 80 -j REDIRECT --to-port $s_port


The problem is on restarting the computer, it seemed to disappear. So I thought I had figured it out, until it didn't work anymore.

Eventually I ended up re-building it each time ppp0 was created by putting it as a process in ip-up.d/

Oh, also don't forget to add "transparent" to the line in the squid.conf file.

http_port 3128 transparent
To learn more about iptables: http://www.frozentux.net/documents/iptables-tutorial/

From here you can directly connect squid to apt-cacher-ng, and have transparent caching of your debian files. Just set up apt-cacher-ng as a peer.

Squid

Squid was relatively easy to set up. There were a few pitfalls, as there are with most programs that seem rather critical to internet usage.

For the most part there was very little deviation from from the regular config, so instead of listing my whole configuration, I'm going to simply list the options I chose and why.

Note: this was written using Squid3

ACL list
In order to define who has access and who doesn't, you probably have noticed that squid.conf has an acl list. In version 3, the acl section is around line 400. It's important to edit this so that the squid server allows connections from your localnet and your localhost.
example:
acl localhost src 127.0.0.1/32
acl localnet src 10.42.43.0/255.255.255.0
I saw many ways to configure the localnet ip address, some being relatively simple (10.42.43.0/32) but this way seems the most obvious, and a bit less confusing.
It's of course important to then set:
http_access allow localnet
http_access allow localhost

http_port
By default the port is set to 3128. But you already knew that. If for some reason you know how to set up a transparent proxy, you can type "transparent" after the port you want to transparently listen. Transparency is a post in and of itself.
What you should realize is that "accel" doesn't refer to accelerating the connection in any way. Unless you know what this means (which I still haven't figured out) you probably shouldn't use it.

Replacement Policies (the cache)
There are two places the cache is stored in: memory and hard disk. For the most part the cache can be left alone, but it makes sense to at least mess around with how the cache works.
The Replacement policy that I used were:
heap GDSF : for the memory
heap LFUDA : for the disk cache
From the config file:

The heap GDSF policy optimizes object hit rate by keeping smaller popular objects in cache so it has a better chance of getting a hit. It achieves a lower byte hit rate than LFUDA though since it evicts larger (possibly popular) objects.

The heap LFUDA policy keeps popular objects in cache regardless of their size and thus optimizes byte hit rate at the expense of hit rate since one large, popular object will prevent many smaller, slightly less popular objects from being cached.

So while LFUDA is most important (saving bandwidth) for our purposes, GDSF might as well be used for memory to increase memory hits.


Paths to know:
/var/spool/squid - where the cache is stored
/var/log/squid - where to access the logs:
access.log should ping whenever someone connects. it's nice to see how effective the server is
cache.log is often used for logging
/etc/squid - where the logs are stored
/etc/init.d/squid - to restart the server

These paths MAY OR MAY NOT have a 3 after them, depending on your version.

Some of the resources I found helpful are:
Squid - The Definite Guide : http://oreilly.com/catalog/9780596001629
Squid by Oskar Pearson : http://proxy.ccu.edu.tw/squid/index.html

Hand in hand with Squid is SquidGuard.

Wednesday, September 23, 2009

Keryx : Download ubuntu updates to a computer with no internet

Part of the initial process before the computers get sent out will be to have the computers mostly updated.

Instead of copying the software from one computer to the other, it would be alot easier to simply have a flash disk, or cd with some mostly recent updates. Once the computers get sent out it will be up to the teachers to keep the computers updated. Software like apt-proxy and squid will help make it less bandwidth intensive to keep the machines updated.

Keryx is fairly intuitive, but I had a bit of a problem with it because I was expecting to have to take the /var/lib/dpkg/source file to the computer with internet.

Keryx does everything for you. Take it to the computer with no internet, start a project, and it copies all the relevant files.

Then take it to the computer with internet access.
First you download the repository list (sudo aptitude update). Then there's an easy button to download updates (sudo aptitude full-upgrade).
There's also a list of all applications (based on the reposotiroy list it downloaded) that can be downloaded. Since it did a check on the original computer before you switched computers, it only downloads the files you need and don't have.
All the files it downloads are conveniently located in a keryx/projects/<project-name>/packages/
This makes it nice for me because since I'm using it for templating I can simply copy them onto a CD and run updates this way.

Maybe I can keep updating this "template" so that I don't have to start over, but can just update the current downloads to be the newest.

Anyway, for a more "official" tutorial, check out
http://crashsystems.net/2009/01/keryx-tutorial/

I'll update the post and post comments on any updates as I use it.