Hi.
I've been doing the same thing to clone "host" environment
into "guest" for NFSroot/OpenVZ virtualization. This is a
BIG WIN of aufs as I can instantly create test environment
which is 100% same as running server.
To do this, you will need some tricks in initramfs.
Actual detail depends on what you want to accomplish, so
I'll try to explain it in following.
=== Case #1: Writable / on read-only media ===
If you just want to have "on-memory /" like many CD-based distributions,
following trick in initramfs will do:
1. Mount "root" partion to /ro
2. Mount tmpfs to /rw
3. Mount /rw and /ro to / with aufs
I use "rootaufs" initramfs hook script (attached) to run Debian
on flash memory, but with all writes going to RAM.
=== Case #2: AUFS-able / for host-cloning ===
I believe this is what you want. You (probably) have a single-
partitioned Linux system, and since aufs inhibits "loop" structure,
you're denied to aufs-mount "/" onto some subfolder.
To workaround this, you will need to split root partion into
2 folders - the former for "/", and the latter for keeping
aufs-mountpoints. In initramfs, you can bind mount the latter
into the former and then aufs will not complain.
I'm not sure if this was clear enough, so let me restate
differences between standard configuration and this "aufs-on-
outerspace" configuration:
[standard configuration]
1. Has / on /dev/sda1
2. In initramfs, mounts /dev/sda1 to /
["outerspace" configuration]
1. Has /real_root and /work_area on /dev/sda1
2. In initramfs...
a) mounts /dev/sda1:/real_root on /
b) mounts /dev/sda1:/work_area on /aufs (or anywhere you like)
I have attached my "outerspace" initramfs hook script as an example,
but please note my disk setup (pathname) is different from the above.
I have /dev/sda1:/disk/base as "/", and /dev/sda1:/disk/ as "/..." for
aufs mounting.
I think you can also do it by loopback-mounting some writable image
and then aufs-mount in that mounted area (I haven't tried it - actually,
I don't do this "outerspace" configuration anymore as now I have multi-
partitioned setup).
Hope this helps.
>> I require to use aufs to unify & mask "/" root file system, like :
>> mount -t aufs -o br=/.rw:/.ro/=ro none /
>>
>> Pls advice how to make the fstab entry compatible as above or there're
>> alternatives ..
>
> Generally people executes chroot or switch_root.
> I'd suggest you to check the init (linuxrc) script in LiveCDs or
> diskless sample in aufs1.
>
> J. R. Okajima
>
------------------------------------------------------------------------------
#!/bin/sh
#
# Hook script to remount rootfs on aufs+tmpfs
# Usage: vmlinuz ... aufs=tmpfs
#
######################################################################
# standard preamble
######################################################################
case "$1" in
prereqs) exit 0;;
esac
echo 1>&2
echo "Checking if rootaufs is enabled..." 1>&2
for p in `cat /proc/cmdline`; do
case "$p" in
*=*) eval $p;;
*) eval $p=1;;
esac 2> /dev/null
done
test "$aufs" = "tmpfs" || exit 0
echo "Settings up rootaufs on $rootmnt..." 1>&2
######################################################################
# main
######################################################################
## load aufs
modprobe -q aufs
## prepare root-as-aufs
mkdir -p /ro /rw /aufs
mount --move $rootmnt /ro
mount -t tmpfs none /rw
mount -t aufs -o dirs=/rw:/ro=ro none /aufs
## switch to root-as-aufs
mkdir -p /aufs/ro /aufs/rw
mount --move /ro /aufs/ro
mount --move /rw /aufs/rw
mount --move /aufs $rootmnt
######################################################################
# generate fstab
######################################################################
fstab=$rootmnt/etc/fstab
## preamble
cat <<EOF > $fstab
##
## autogenerated by rootaufs script in initramfs
##
none / tmpfs defaults 0 0
$root /ro ext2 ro,noatime,nodiratime 0 0
EOF
## copy entries
cat $rootmnt/ro/etc/fstab | grep -v $root | grep -v tmpfs >> $fstab
## append entries
cat <<EOF >> $fstab
# for chroot env
/dev /ro/dev none bind 0 0
/dev/pts /ro/dev/pts none bind 0 0
/sys /ro/sys none bind 0 0
/proc /ro/proc none bind 0 0
#/mnt/sda1 /ro/mnt/sda1 none bind 0 0
EOF
exit 0
#!/bin/sh
if [ -d /root/base/... ]; then
mkdir /disk
mount --move /root /disk
mount --bind /disk/base /root
mount --bind /disk /root/...
umount /disk
fi
------------------------------------------------------------------------------