OverlayFS – Fix OverlayFS Over Read-Only Rootfs Fail

overlayfs

I need to keep one system as much intact as possible. Only soldering of HW stuff is allowed :-). I need to install a test software package and this package must not stay there in the future.

I have a following situation:

  1. mmcblck partition mounted as /, ext4, read only, kernel v4.6.0
  2. usb stick (only one partition), mounted to /tmp/usbstick, ext4
  3. Created directories on usbstick /tmp/usbstick/upperdir, /tmp/usbstick/workdir
  4. Using the following line: mount -t overlay overlay -o lowerdir=/,upperdir=/tmp/usbstick/upperdir,workdir=/tmp/usbstick/workdir /

After that the / is still read only.
The only partial success I had was when I created /tmp/usbstick/merged and gave it as a "merged" directory, instead of / to the module. Then I saw all my rootfs in that directory and it was rw mounted, but I can't use it there. What should I do?

Best Answer

I tried to chroot to the merged directory. The result was just as expected: I had rw rootfs, the only thing I missed was virtual kernel filesystems. So after mounting the overlay I did the following:

TARGETDIR="/tmp/usbstick/merged"
mount -t proc proc $TARGETDIR/proc
mount -t sysfs sysfs $TARGETDIR/sys
mount -t devtmpfs devtmpfs $TARGETDIR/dev
mount -t tmpfs tmpfs $TARGETDIR/dev/shm
mount -t devpts devpts $TARGETDIR/dev/pts

And then linked the mtab:

chroot $TARGETDIR rm /etc/mtab 2> /dev/null 
chroot $TARGETDIR ln -s /proc/mounts /etc/mtab
chroot $TARGETDIR
Related Question