Friday, August 7, 2009

Solid State Ubuntu

I decided to install Ubuntu 9.04 to my 2GB CF card. I wanted to avoid wearing out the CF with writes, so I settled on this method. I installed the server to one partition, so /usr/local is in the root filesystem. You can create the script anywhere in the root filesystem, but i used /usr/local.

Create a /usr/local/bin/mounttmpfs.sh file with the contents below:

#!/bin/sh
rsync -a /var.perm/ /var/
mount -t tmpfs tmpfs -o mode=1777 /var
rsync -a /var.perm/ /var/

Make a soft link from it to /etc/rcS.d with:

ln –s /usr/local/bin/mounttmpfs.sh /etc/rcS.d/S23mounttmpfs.sh

This will cause it to run right after the filesystems are mounted, before any services which write to /var are running.

Add a cron.hourly script to rsync from /var to /var.perm, and you are all set!

I modified this a bit after the inital post. I changed the mounttmpfs.sh script:


#!/bin/sh
find /var/ -type f -exec rm -f {} \;
mount -t tmpfs tmpfs -o mode=1777 /var
rsync -a /var.perm/ /var/
mount -o relatime /dev/vgraid/lv_squid /var/spool/squid3

The find line is actually only needed once. I just deleted the files from the underlying (flash) filesystems, leaving the directory structure. No need to waste space. After that, I mount the /var manually, then copy the permanent files into it. Finally, since I run squid on this server, I mount the squid cache directories after /var. All the other local filesystems get loaded from the scripts in the /etc/rcS.d directory. I also have an hourly cron job which runs the following:

#!/bin/shrsync --delete-excluded --delete-after --exclude=*.pid \
--exclude=spool/squid3/??/??/* --exclude=cache/apt/archives/*.deb\
-av /var/ /var.perm/

This copies all the directory structure, and most files, from /var to the flash card. I skip the squid cache files, since they take up too much space.

No comments: