Red Hat – How to Mount a Root aufs in Red Hat / Fedora Core

initlinuxrootfsunionfs

I'm trying to set up a virtual machine running Red Hat EL (actually Scientific Linux, but same difference) where the root file system is protected and not writable. I'd like to accomplish this with a union mount using aufs. That is, a writable file system (on a different virtual HDD) is overlayed on the root file system.

Is there a HOWTO on this anywhere? I have the aufs module installed, and I've been able to mount a union file system, but the trick is to do this for the root file system.

I've seen initramfs scripts help.ubuntu.com/community/aufsRootFileSystemOnUsbFlash written for Debian/Ubuntu-style distributions that do this sort of thing inside the /init script: Before the real root is mounted, the protected root is mounted somewhere as read-only, the overlayed file system is mounted elsewhere as read-write, the union file system is created and mounted, and then the union mount becomes the real root. Hence, the original protected root file system is never mounted as read-write.

I'd like to know how to do this in the nash /init script of Red Hat distributions.

Even more specific questions: What exactly do the nash commands "setuproot" and "switchroot" do? The man page for nash(8) documents switchroot with a single argument, but my /init script calls it without any arguments.

(Motivation: the virtual machine will be subjected to software fault injection; I want to protect the root file system from the effects of a faulty system so that I can quickly reboot the VM into a non-faulty state.)

Thanks!!

P.S. Yes, I could just download some LiveCD and see how it's done there, but I thought somebody should have written a HOWTO that my Googling skills have not discovered.

Best Answer

The initrd contains a gzipped cpio dump that's put onto a ramdisk during init. Setuproot loads any necessary modules (contained in the initrd), generally for things like LVM, populates /dev (the initrd contains a limited /dev). Switchroot pivots off the cpio archive to the real root filesystem.

nash is extremely limited. Every binary must be static, scripting is virtually impossible, etc. This may be helpful (build scripts are in his SVN repo).