2

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?

Michael
  • 371

1 Answers1

2

Use the standard Ubuntu package "overlayroot". In Ubuntu 16.04, this package is automatically installed. You simply need to enable it by editing /etc/overlayroot.conf and adding the following setting:

overlayroot="tmpfs"

Reboot the Ubuntu 16.04 system, and you're done. You may want to add a kernel boot entry to your grub configuration to make it easy to temporarily disable the read-only root filesystem for patches, etc. The way to do this is to add a grub entry that passes a kernel argument as follows:

overlayroot=disabled

See more at: https://spin.atomicobject.com/2015/03/10/protecting-ubuntu-root-filesystem/