Is there a Linux distro that will easily run "embedded style" on a Raspberry Pi? [closed]

Most embedded systems use a custom built kernel. One tool to facilitate that is Buildroot, a set of scripts to build the GNU gcc toolchain, the uClibc library in place of the (huge) GNU libc, the Linux kernel, BusyBox and other utilities/packages for an embedded board's root filesystem. The RaspberryPi is a relatively new board, so support of it in Buildroot is still under development, but there are apparently a project, another project and an individual's work. There will probably be more as RP manufacturing ramps up and distribution improves.

Using Buildroot, you could build a Linux kernel and root filesystem exactly as you described in your question. Depending on your Internet connection speed and your development PC's capabilities, you might have the binaries in 1 to 4+ hours. The downside is that resultant binaries are not tested nor guaranteed to successfully boot & execute. A system console is mandatory for debugging the boot sequence. See my answer for How can I access my mini-pc (RaspberryPi / MK802 / Mele A1000 / VIA APC) via ethernet/wifi without having Monitor? But given that the RaspberryPi was designed to be unbrickable, this downside should not be a deterrent to building your custom kernel and RFS.

Regarding "survive power loss": Proper selection of the filesystem can usually alleviate this concern. The MTD device layer plus a journaling filesystem (e.g. jffs2) has shown to be quite robust from experience. For near-absolute protection, there's the initramfs that uses ramfs (not a fixed-sized ramdisk) with no switchover to a R/W filesystem.

Addendum

A 30-slide intro on features of Buildroot is here
At the end (#27) there is mention of a few similar and alternate tools to build embedded systems.


TinyCoreLinux is read only by default (persistence is optional): http://www.tinycorelinux.net/ports.html


Having had a Seagate Dockstar with console access, I installed Debian squeeze onto it. As a starting point to make it run on read-only root, I used this excellent article 1 by Jeff Doozan. The basic strategy involves creating a script that, upon every boot, mounts the necessary writable directories as a tmpfs. I quote the script by Jeff 2 here (kudos to Jeff!)

#!/bin/bash
DIRS="/tmp /var/log /var/run /var/lock /var/tmp /var/lib/urandom /var/lib/dhcp /etc/network/run"
for DIR in $DIRS; do
  echo "Mounting $DIR as tmpfs"
  mount -n -t tmpfs tmpfs $DIR
  if [ -d "$DIR-saved" ]; then
    echo "Restoring $DIR-saved to $DIR"
    tar -C "$DIR-saved" -cf - ./ | tar -C "$DIR" -xpf -
  fi
done

echo "nameserver 4.2.2.1" > /var/tmp/resolv.conf
touch /var/lib/dhcp/dhcpd.leases

exec /sbin/init

Save the lines above as a script called /sbin/init-ro on your target rootfs and make it executable.

chmod 755 /sbin/init-ro

In order to use this script during boot-time, you have to prepare the system rootfs a bit (all quoted from Jeff's script 2 (adapt $ROOT to the actual location of your mounted rootfs).

# Configure dhcp-client to write resolv.conf to /tmp instead of /etc
sed -i 's/\/etc\/resolv.conf/\/var\/tmp\/resolv.conf/' $ROOT/sbin/dhclient-script > /dev/null 2>&1
rm $ROOT/etc/resolv.conf
ln -s /var/tmp/resolv.conf $ROOT/etc/resolv.conf


# make /etc/network/run/ a symlink to /tmp/network/
rm -rf $ROOT/etc/network/run
ln -s /var/tmp/network $ROOT/etc/network/run


# Fixes from http://wiki.debian.org/ReadonlyRoot

rm $ROOT/etc/blkid.tab  > /dev/null 2>&1
ln -s /dev/null $ROOT/etc/blkid.tab

rm $ROOT/etc/mtab  > /dev/null 2>&1
ln -s /proc/mounts $ROOT/etc/mtab

rm $ROOT/etc/rcS.d/S12udev-mtab

rm -rf $ROOT/var/log/*

After having the rootfs prepared like above, you can mount the rootfs read-only in /etc/fstab (replace ext2 with the filesystem you're using or just use rootfs instead).

/dev/root  /                 ext2  noatime,ro   0 1

Finally, you have to append the following to your kernel parameters (i.e. in /boot/cmdline.txt on Raspi) in order to run the script before the actual /sbin/init. (the following is just an example of root and rootdelay parameters. the important part that has to be appended to the line in cmdline.txt is init=/sbin/init-ro.)

root=/dev/mmcblk0p2 rootdelay=2 init=/sbin/init-ro

But be aware that for any software requiring write-access on the rootfs you have to mount the appropriate tmpfs locations or write to external storage.


My 2 cents, it's far easier (and nicer in the end) to make a reliable battery backup for a Pi than it is to live with a read only OS. Of course, that'd mean you'll need some very basic knowledge of electronic (and I mean BASIC; we're talking 3-4 components). This guy made a fancy one with just a few more: https://raspberrypi.stackexchange.com/questions/1360/how-do-i-build-a-ups-like-battery-backup-system

If you do this, DON'T use LiPo; NiCad are what you want. LiPo can't take constant over charging; you've been warned.

Also, you seem to be very worried about something that, in my experience, is a very minor issue. I thrash my Linux boxes all the time and a sudden unscheduled shutdown is a matter of course when I can't be bothered. If you disable the logs then you'll rarely even get any complaints about doing that.

To disable all the logs you can add the following line as the first rule in /etc/rsyslog.conf :

*.* ~

Even when there is a problem, 99.9999% of the time (by that I mean nearly every time in my personal experience) that problem is taken care of when the disk is next scanned. When that happens mainly depends on weather the OS noticed what you did (strangely enough it usually doesn't). Since a Pi uses SD cards I'd imagine that this happens even less on a Pi than it does on my PC.