7

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?

2 Answers 2

3

I found a workaround for this issue: using mergerfs to re-map a hierarchy of multiple nested mounts into a single mount point, where overlayfs will work. E.g.

mount -o ro,loop file1 /mnt/dir/part1
mount -o ro,loop file2 /mnt/dir/part2
mount.mergerfs /mnt/dir /mnt/view
mount -t overlayfs lowerdir=/mnt/view,... 
1
  • strange, mount.mergerfs / /mnt works and ls displays listing correctly, but mc doubles every entry in /mnt: /bin /bin /boot /boot /dev /dev /etc ...
    – Alek
    Apr 4, 2022 at 20:52
1

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. Oct 22, 2019 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. Oct 24, 2019 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .