Debian on read-only media

From Electron Cloud

The system has built-in video, 2 serial ports, parallel... good for home automation. Replaced the fan with a nearly silent Noctua.

Look ma, no spinning media!

I replaced the fansink with one that was designed for overclocking Celerons, then removed the fan. It just gets slightly warm with this low-power processor. The power supply has the only fan.

I wanted to put together a low-power home automation system, with a fixed set of tasks, with read-only rootfs such that if anything goes wrong it's OK to just hit reset. (Or if the power goes out it will reboot drama-free by itself.) For low-power hardware I wanted to make use of an old 233MHz Cyrix MediaGX system which has not had much use until now. With only the motherboard, an AT power supply modified with a Noctua fan, PCI USB and S3 Virge boards, and a 2 GB CF card for the "hard drive", it takes in the range of 20-25 watts... not bad compared to around 100 watts for a more modern PC. A Via EPIA or some such would work just as well if that's what you happen to have lying around. A SheevaPlug might even be enough, actually. My EPIA board died after only a year or two of use, due to bad caps, so I'd just as soon re-use old junk that still works rather than "investing" in a replacement.

So... given that it's not quite a 686-compatible, we need a Linux distro which doesn't make such assumptions about the hardware (increasingly rare). Debian 5.0 still runs on a 486. (I'm normally a gentoo user but not too keen on doing so much building on such a slow machine. And have tried building a custom distro with openembedded too, but bleh... it's too much work, and not every package that I want is available.) So I installed with default options onto the CF card, then went about modifying it to work even if I mount the root filesystem read-only.

grub is already configured "ro" because Debian still mounts the root filesystem ro first, then does fsck then mounts rw again, even with modern journaling filesystems (go figure). It could be there's a good reason for that, but I think to the extent that there are no bugs in ext3 (heh) it should be able to deal with being mounted read-write from the start. At least, reiserfs always could... but ext3 will give you a warning after a while that fsck is recommended because it's been too many days (oh ye of little faith). I think I will just deal with that manually since it's going to be mounted read-only most of the time. This is the kind of system that's going to (in theory) go for years at a time without significant modifications.

So I added a "maintenance mode" entry, and turned off swap on the default entry (/boot/grub/menu.lst):

/var needs to be tmpfs too, but that gets tricky, because /var normally holds more stuff than I could fit in 64 megs of RAM (most of the big stuff isn't really "variable"). So I made /var-ro and /var-tmp, and moved stuff from /var which I wanted to be read-only (in normal mode) into /var-ro, and at boot it mounts /var as tmpfs then copies everything from /var-tmp into there... so we want only the bare directory structures in /var-tmp, as well as symlinks to the stuff that is actually in /var-ro.

And in /etc/init.d/mountkernfs.sh, we do the copying into the tmpfs, right after the part where it optionally mounts /var/run and /var/lock as tmpfs (we don't enable that option since all of /var is basically tmpfs):