OK, here I made a script inspired by Nicholas A. Schembri that does just what you expected. I use this script to make a union of my squashfs root partition and tmpfs. First it mounts root partition read-only and then any other partition that you would like to use as a read-write in union with root partition:
Code:
#!/bin/sh -e
case $1 in
prereqs)
exit 0
;;
esac
for x in $(cat /proc/cmdline); do
case $x in
root=*)
ROOTNAME=${x#root=}
;;
aufs=*)
UNION=${x#aufs=}
case $UNION in
LABEL=*)
UNION="/dev/disk/by-label/${UNION#LABEL=}"
;;
UUID=*)
UNION="/dev/disk/by-uuid/${UNION#UUID=}"
;;
esac
;;
esac
done
if [ -z "$UNION" ]; then
exit 0
fi
modprobe -Qb aufs
# make the mount points on the init root file system
mkdir /aufs /ro /rw
# mount read-write file system
if [ "$UNION" = "tmpfs" ]; then
mount -t tmpfs rw /rw -o noatime,mode=0755
else
mount $UNION /rw -o noatime
fi
# move real root out of the way
mount --move ${rootmnt} /ro
mount -t aufs aufs /aufs -o noatime,dirs=/rw:/ro=ro
# test for mount points on union file system
[ -d /aufs/ro ] || mkdir /aufs/ro
[ -d /aufs/rw ] || mkdir /aufs/rw
mount --move /ro /aufs/ro
mount --move /rw /aufs/rw
# strip fstab off of root partition
grep -v $ROOTNAME /aufs/ro/etc/fstab > /aufs/etc/fstab
mount --move /aufs /root
exit 0
1. Put this script into /etc/initramfs-tools/scripts/init-bottom/, make it executable.
2. Put aufs into /etc/initramfs-tools/scripts/modules so aufs module will be added to initramfs image later on.
3. Reconstruct initramfs image with update-initramfs -u.
4. Add aufs=<your_union_rw_partition> to your boot loader's kernel parameters. If you would like to use RAM as your read-write store put there aufs=tmpfs.
Bookmarks