Linux – Custom initrd init script: how to create /dev/initctl

bootchrootinitlinuxunionfs

I have a virtual machine (VMM is Xen 3.3) equipped with two IDE HDD's (/dev/hda and /dev/hdb). The root file system is in /dev/hda1, where Scientific Linux 5.4 is installed. /dev/hdb contains an empty ext2 file system.

I want to protect the root file system from writes by the VM by using aufs (AnotherUnionFS) to layer a writable file system on top of the root file system. The changes to / will be written to the file system located on /dev/hdb. (Furthermore, outside the VM, the file backing the /dev/hda will also be set to read-only permissions, so the VMM should also prevent the VM from modifying at that level.) (The purpose of this setup: be able to corrupt a virtual machine using software-implemented fault injection but preserve the file system image in order to quickly reboot the VM to a fault-free state.)

How do I get an initrd init script to do the necessary mounts to create the union file system?

I've tried 2 approaches:

  1. I've tried modifying the nash script that mkinitrd creates, but I don't know what setuproot and switchroot do and how to make them use my aufs as the new root. Apparently, nobody else here knows either. (EDIT: I take that back.)

  2. I've tried building a LiveCD (using linux-live-6.3.0) and then modifying the Bash /linuxrc script from the generated initrd, and I got the mounts correct, but the final /sbin/init complains about /dev/initctl.

Specifically, my /linuxrc mounts the aufs at /union. The last few lines of /linuxrc effectively do the following:

cd /union
mkdir -p mnt/live
pivot_root . mnt/live
exec sbin/chroot . sbin/init </dev/console >/dev/console 2>&1

When init starts, it outputs something like init: /dev/initctl: No such file or directory. What is supposed to create this FIFO? I found no such filename in the original linuxrc and liblinuxlive scripts.

I tried creating it via "mkfifo /dev/initctl", but then init complained about a timeout opening or writing to the FIFO.

Would appreciate any help or pointers. Thanks.

Best Answer

If you're already using a virtualization solution, why are you going through all this trouble? The simplest solution would be to use something like LVM on your host, which already has snapshot support, and present a snapshot to your VM. That is:

  • Create a logical volume (LV) that will hold your root filesystem.
  • Create a snapshot of this LV
  • Configure your VM to boot from the snapshot.

If you want to revert back to the clean filesystem, delete the snapshot and recreate it. Easy, and no fiddling about with initrd or aufs -- in fact, it doesn't require any modifications to the guest OS.