3

Recently, for an embedded project, I was asked to emulate on Linux the effects of the Enhanced Write Filter (EWF) of Windows XP Embedded.

In particular, I need a sort of EWF for:

  1. avoiding to write too many times on disk (we use CFs);
  2. protecting programs/config files after accidental reboots/failures/erroneous changes.

As far as I know, Linux has no feature similar EWF and it doesn't write as much as Windows on disk (see this answer), but my chief asked me to investigate something that can provide a solution for both the requirements.

At the moment I'm trying this simple strategy:

  1. I've a little partition (mount point: /safe) with the data/directories I should protect (i.e. the whole /etc directory)
  2. during system bootup I mount in RAM (tmpfs) all the directories that I must protect then I copy data from /safe into them.
  3. if all goes right, I can unmount /safe. If needed, a little script allows me to mount /safe and "commit" changes to files, if needed.
  4. I can force / read-only: all programs I need are in RAM and they're writing stuff in RAM.

Any idea/suggestion?

I'm using a stripped-down Debian Lenny with Ext2-formatted partitions on x86 architecture (BTW, any suggestions for a simple journaled/COW filesystem suitable for this task?).

Thanks.

2 Answers2

4

Solved by following the excellent How To: Build A Read-Only Linux System.

From one of the two little scripts making the magic (uses an aufs union):

ro_mount_point="${rootmnt%/}.ro"
rw_mount_point="${rootmnt%/}.rw"

# Create mount points for the read-only and read/write layers:
mkdir "${ro_mount_point}" "${rw_mount_point}"

# Move the already-mounted root filesystem to the ro mount point:
mount --move "${rootmnt}" "${ro_mount_point}"

# Mount the read/write filesystem:
mount -t tmpfs root.rw "${rw_mount_point}"

# Mount the union:
mount -t aufs -o "dirs=${rw_mount_point}=rw:${ro_mount_point}=ro" root.union "${rootmnt}"

# Correct the permissions of /:
chmod 755 "${rootmnt}"

Results: system protected and apps can write their stuff (in RAM).

If I reboot without "committing" all the changes on the system will be lost, but if I need something to stay permanent, I can remount the partition read-write (this time r/w means "on disk" not "on RAM"), do the "commit" and remount the partition as read-only.

Scripts are so elegant that I can also switch between "protected" (for production) or "unprotected" (for development) modes by choosing its correct labelled entry in GRUB.

1

Just for the record, UnionFS is another alternative to aufs that does much of the same things. The popular Live Linux distro KNOPPIX uses UnionFS to merge the read-only CDROM filesystem with a read-write RAM-only tmpfs filesystem.

davr
  • 1,729
  • 3
  • 14
  • 24