Paul Moody's mini-HOWTO on Embedded Linux at:
    http://users.bigpond.com/paulmoody/Mhow11c.html
gives one approach to using a Flash memory drive with Linux, by loading the
contents into a ramdisk at boot time.

RAM is cheaper than Flash, so for the most part this makes sense. However, if
you're stuck with less RAM than Flash, or if you're using a real hard drive,
it may make more sense to mount the root filesystem from the drive read-only.

This retains many of the benefits of resisting corruption of the drive and
avoiding write cycles (which would quickly wear out a flash drive), because no
data is ever written to the root filesystem. Even with a real hard drive, the
root filesystem is not corrupted (and fsck is not run on reboot) if the power
is cycled.

Of course, it's complicated by the fact that Linux usually wants/needs to
write data to its root file system. This problem can be solved principally
by modifying /etc/rc.sysinit to create and mount a ramdisk on the read-only
root filesystem, instead of remounting the root filesystem in read-write mode.

This technique takes advantage of the fact that a read-write device can be
monted on the filesystem of a read-only device, to create a read-write
directory subtree within an otherwise read-only heirarchy. Note that mounting
a new device merely stores an entry in a kernel table and does not write to
the device holding the filesystem upon which the new device is being mounted.

Here's a sketch of the places on the root filesystem where Linux traditionally
wants to write, and how to cope with them:

/var
    Most dynamic stuff happens here, so this is where I mount the ramdisk.
    The mods to /etc/rc.sysinit include creating (or copying) the usual
    directory structure under /var onto the ramdisk before remounting it here.

/tmp
    Usually publically writable, and "sticky". Make /tmp a symlink to a new
    directory /var/tmp, on the ramdisk mounted on /var. Alternatively, mount
    another ramdisk on /tmp.

/dev
    Suprising at first, but login/getty programs change the ownership of
    /dev/tty* files when users log in, so some /dev files need to be on a
    writable filesystem. Again, make /dev a symlink to /var/dev, and "cp -a"
    or mknod all the devices required into the ramdisk.

/etc/mtab
/etc/HOSTNAME
    These get written at various points. Each file is made a symlink to
    /var/etc/..., so they can be written.

/etc/issue
    Some distributions like to rewrite this in the /etc/rc.d scripts. Just
    nuke the part of the scripts which do that.

Everything else is reasonably straightforward. I'd be interested in any
comments or feedback from other people regarding this, or similar techniques.

Regards,
Graham
-- 
Graham Stoney, Senior Hardware/Software Engineer
Canon Information Systems Research Australia
Ph: + 61 2 9805 2909    Fax: + 61 2 9805 2929

Reply via email to