I want to set up Ubuntu 16.04 like a live CD. This worked great in Ubuntu 12.04 but with 16.04 there are problems. Services are crashing, CRON doesn't work, X doesn't work, I can't even login to the shell. So I think 16.04 needs some modification. If I mount the root drive as read/write, everthing works like it should. So, the OS itself is OK.
To let Ubuntu boot in read-only mode I replace the kernel parameter "rw" by "ro" and use a script in initramfs:
/etc/initramfs-tools/scripts/init-bottom/ro_root
#!/bin/sh
PREREQ=''
prereqs() {
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
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}"
# Make sure the individual ro and rw mounts are accessible from within the root
# once the union is assumed as /. This makes it possible to access the
# component filesystems individually.
mkdir "${rootmnt}/ro" "${rootmnt}/rw"
mount --bind "${ro_mount_point}" "${rootmnt}/ro"
mount --bind "${rw_mount_point}" "${rootmnt}/rw"
# ro_root end
How to set up Ubuntu 16.04 with ro root drive and rw fs layer correctly?