I’m planning on reducing the power consumption of and the noise from my VIA EPIA EN12000EG based home server. The server acts as media center, file server, backup server and authoritative DNS server. In a not so distant future it will probably also act as router and IPv6 tunnel endpoint. My plan is to replace its ordinary PSU with a more efficient and fanless picoPSU and to make its hard drive spin down when it hasn’t been used for a while. In addition, I will connect the server to my LAN with a cable rather than through wireless, which means I can retire the Linksys WRT54G that acts as a wire-wireless bridge for the server. I expect to go from approx 50 to 30 watts, on average, which is a saving of approx 0.02 kW · 24 hours/day · 365.25 days/year · 2 DKK/kWh = 350 DKK/year. Do you also smile when the units fit? 🙂
Okay, let’s get down to business. In order to have the hard drive spin up only when I access my music, videos and stuff, I need to move the server’s operating system – OpenBSD – to another disk. I will use a USB flash drive, as I happen to have one lying around and since they are silent and practically don’t consume power. The downside is that they are slow and die if you write to them often. That is solved using the server’s memory and a little ingenuity – the main topic of this post.
Frankly, I’m shocked at how little it takes to make OpenBSD run off a flash drive with some of its file systems in memory. You only need to follow seven steps:
1. Add a number of mfs’es to your /etc/fstab:
614940548185a78b.b none swap sw
614940548185a78b.a / ffs rw 1 1
swap /dev mfs rw,nosuid,-P=/mfs_backup/dev,-i=256 0 0
swap /var mfs rw,nodev,nosuid,-P=/mfs_backup/var,-s=60M 0 0
swap /root mfs rw,nodev,nosuid,-P=/mfs_backup/root 0 0
swap /home mfs rw,nodev,nosuid,-P=/mfs_backup/home,-s=20M 0 0
swap /tmp mfs rw,nodev,nosuid,-s=20M 0 0
(Note 1: The special “swap” entails default configuration parameters for mfs;
Note 2: The option “-i=256” ensures that we have enough inodes on /dev)
2. Install rsync (of course there is a precompiled package).
3. Create a synchronization script in e.g. /bin/mfs_sync.sh:
[ -d $DEST ] || mkdir $DEST
echo -n "Synchronizing directories to $DEST..."
for dir in dev var root home; do
$RSYNC -a --delete /$dir $DEST/
echo -n " $dir"
find $DEST -type s | xargs rm
4. Test the script!
5. Let the script be run at shutdown by calling it from /etc/rc.shutdown.
6. Let the script be run e.g. once a day at 3:30 AM by adding the following line to root’s crontab:
30 3 * * * /bin/mfs_sync.sh >/dev/null
You should end up with something like this:
$ df -hi
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/sd1a 3.4G 798M 2.5G 24% 37452 430258 8% /
mfs:24156 6.9M 32.0K 6.5M 0% 1263 6927 15% /dev
mfs:11736 58.0M 6.0M 49.2M 11% 679 14679 4% /var
mfs:29956 7.7M 9.0K 7.3M 0% 9 2037 0% /root
mfs:27787 19.3M 10.0K 18.3M 0% 12 5106 0% /home
mfs:1527 19.3M 4.0K 18.3M 0% 5 5113 0% /tmp
I would like to thank Stephane Kattoor and Joel Knight for inspiration.
Now go and read the bloody details in mfs(8), fstab(5), rsync(1), find(1), rc.shutdown(8) and crontab(5) and make yourself worthy of their use.