netzstaub

beatz & funkz

Sunday, March 20, 2005

Fanless Gentoo-Router with read-only CF-root-fs

Our Internet-Router for the last 2 months was a mini-Desktop Gentoo-PC with a conventional harddisk. In the process of minimizing our energy costs and reducing the noise in the kitchen, where our router is hidden away in a cupboard, we bought a NEO-LX barebone PC. The NEO-LX barebone has a 1Ghz VIA Eden Nehemiah processor, and is completely fanless. It comes in a solid black metal housing, with a fantastic design. You can add a 2.5″ IDE-Disk if you want, but we chose to put the whole system on a CF-Card. Our setup is quite hackish, but it works.

We bought a 512 MB CF-Card for 38 EUR, and decide to put all the data we had on the harddisk on it. 512 MB is enough for a whole functional system. The only data that did not fit on the disk was the source and the portage temporary files, which can become quite large. These files were offloaded to an external USB-drive which can be switched on and off by the router when necessary. This automatic switching of the external USB driver is not implemented at the moment, though. The CF-card is mounted as / , and is read-only.

Init.d Dependencies

This is a problem though, as the init.d dependency code needs a writable directory to store the dependencies, for example. This case however is already handled by gentoo itself. All you need to do is to add the “gentoo=tmpfs” parameter at boot-time. When this parameter is passed to the kernel, gentoo creates two ramfs partitions to store the dependency code at boot-time.

Additional programs

However, this is not the only thing that needs to be done. For example, the file /etc/mtab is written when mounting partitions. Our solution was to symlink the file “/proc/mounts” to “/etc/mtab”, which seems to work (/sbin/rc tries to write to /etc/mtab at the beginning apparently, but the warning can be safely ignored). However, a bunch of other files need to be written at boottime, and sometimes need to have default values (one such file is “/etc/hostname”). Our solution was to create a very hackish and simple shell-script, named /etc/diskless.sh. All the files that need to be modified at boot-time are stored in a directory on the read-only root partition, named “/diskless”. At a very early step in booting, /etc/diskless.sh is called by /sbin/rc. diskless.sh mounts a ramfs partition on /tmp, and copies all the files contained in /diskless. The real files point to the directory /tmp/diskless, and can then be written and modified at boot time. Diskless.sh looks like this:

DISKLESSDIR=/diskless/dirs
DISKLESSFILES=/diskless/files

mount -t tmpfs none /tmp

        mkdir -p /tmp/diskless
        for i in $DISKLESSDIR/*; do 
            DIR=${i#$DISKLESSDIR}
            echo "Setting up $DIR"
            cp -r "$i" "/tmp/diskless$DIR"
        done

        find "$DISKLESSFILES" -type f | while read i; do
            FILE=${i#$DISKLESSFILES}
            DIR=`dirname "$FILE"`
            echo "Setting file $FILE"
            mkdir -p "/tmp/diskless$DIR"
            cp "$i" "/tmp/diskless$DIR"
        done

        echo "Directories setup up for diskless operation"

This is pretty ugly, but it was written a 5am after an unnerving night trying to configure the linux kernel to work with the NEO-LX. The distinction between /diskless/dirs and /diskless/files is there in order to differentiate between single files, which can be inside directories a few nodes deep, and complete directories. Our /diskless contains the directories /var/lib (which contains init.d directories), /var/run (which holds the pids of started directories), the chroot for our dhcp server (which writes the active leases to a file inside its chroot), the PPP directory (which somehow needs to be writeable too), and a few environment files inside /etc. /etc/diskless.sh is called by /sbin/rc just after mounting swap directories (we have no swap on our router, though). The portage DB directory needs to be writable too when installing packages, and has been offloaded to the USB disk too.

This is a very hackish solution, but it works. We will rewrite it someday maybe 🙂

posted by manuel at 3:17 pm  

2 Comments »

  1. Hello, I’m very interested to do something similar.
    CF-IDE Router… with the use of quagga + SRRD (somehow) this router will be very powerful what is on the market.

    Can we discuss more about this?

    Good Work.

    Comment by Chan Min Wai — April 17, 2005 @ 8:16 am

  2. Good work man, your article seemed to be very usefull for me)

    Comment by Antony — May 19, 2008 @ 7:59 pm

RSS feed for comments on this post.

Leave a comment

Powered by WordPress