I'm trying to setup an overlayfs for a chroot environment. The environment is made up from multiple read-only squashfs file systems (lower) and a single writable directory (upper).
The tricky part is that only one of the squashfs file systems has the root directory for chroot, the others do not contain the full chain of ancestors back to root. So I tried:
mount -o ro,loop base.squash /media/foo/myimage
mount -o ro,loop home.squash /media/foo/myimage/home/
mount -t overlay overlay -o lowerdir=/media/foo/myimage,upperdir=/var/lib/myimage,workdir=/var/chache/myimage /media/bar
This had the (surprising) outcome that /media/bar
is comprised of only base.squash
and /var/lib/myimage
. home.squash
is ignored leaving /media/bar/home
empty.
I've looked in the documents for a way to add home.squash
as an additional lower layer but that all seems to assume that all layers will contain the full chain of ancestor directories back to root /
.
Without changing the contents of the squashfs images, how should I go about mounting this?
Best Answer
This was a surprising finding, and one I'd like to see a solution for. I've tried some variations with bind mounts, but not getting the results I hoped for.
But I saw another question which related to nested overlays, that apparently should work, but there was a regression in Linux kernel 4.2 that prevented it from working in that version. Luckily I am on 4.15 so I tried this method;
That seemed to have the desired effect.
I tried not specifying the "upperdir" and "workdir" parts as it was stated somewhere that it would work but create a read-only overlay. But it didn't work. Not for me at least.