4

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?

0

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;

mount -o ro,loop base.squash /media/foo/myimage
mount -o ro,loop home.squash /media/foo/myhome
mount -t overlay overlay -o lowerdir=/media/foo/myimage,upperdir=/var/lib/myimage,workdir=/var/chache/myimage /media/bar
mount -t overlay overlay -o lowerdir=/media/foo/myhome,upperdir=/var/lib/myhome,workdir=/var/chache/myhome /media/bar/home

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.

2
  • Yes the issue with this is the broken down upper layer. Without this you risk mounting into a non-empty directory. It may be this or re-pack the sqauashfs. It's a shame they didn't at least correct the documentation to match. – Philip Couling Oct 22 '19 at 7:44
  • It is what it is at present. I will probably use this solution myself to construct overlays from several mounted squashfs files. Will likely be using containers later on and then the mapping can be accomplished in a slightly different way, but I believe each filesystem mounted directory will still need to be listed separately. – Mats Bengtsson Oct 24 '19 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.