1

I want to mount the following directories using overlayfs:

(lowerdir) /chroot in /merged
(lowerdir) /home   in /merged/home
(upperdir) /tmpfs  in /merged

...so that the resulting merged directory is a COW system that contains both the /chroot and /home.

I cannot find any way to do that.

1) Trying multiple lower dirs:

mount -t overlay -o lowerdir=/chroot:/home,upperdir=/tmpfs,workdir=/workdir overlay /merged
ls /merged

==> failure, the /home contents merge with the /chroot contents directly in /merged without getting inside a /merged/home subdirectory.

2) Trying bind-mounts:

mount --bind /home /chroot/home
mount -t overlay -o lowerdir=/chroot,upperdir=/tmpfs,workdir=/workdir overlay /merged
ls /merged/home

==> empty, the /chroot/home submount contents do not show up in /merged/home.

Any ideas? Thank you.

alkisg
  • 550
  • 7
  • 6

3 Answers3

0

I ran into this exact problem tonight, however I was using /, /usr, /var as the test since I wanted to capture changes to the filesytem from a package install and skim it out of the OverlayFS 'upperdir'.

I figured out that OverlayFS wasn't designed for this, then I remembered about unionfs-fuse... I also saw that OverlayFS could use itself as a lowerdir, so I took a shot with using unionfs-fuse instead and it worked.

Keep in mind this is just a quick 'lab' PoC test, and I'm sure you'll want to tweak the unionfs-fuse options quite a bit for your needs...

mkdir merged union upper work
sudo unionfs-fuse /=RO:/usr=RO:/var=RO:/home=RO union
sudo mount -t overlay overlay -olowerdir=union,upperdir=upper,workdir=work merged
sudo echo test > merged/newtestfile
ls merged/newtestfile # exists
ls upper/newtestfile # exists

Overall, the solution is a bit twisted/demented but it seems to work ok at least for what I was trying to accomplish by isolating the changes that could be skimmed from the ./upper directory.

muru
  • 197,895
  • 55
  • 485
  • 740
Terra
  • 1
  • Hi, thanks for the answer, but both unionfs and aufs were working fine, the problem was specifically with overlayfs. Also sorry for the late reply, I didn't receive a notification email. – alkisg Oct 18 '16 at 05:35
  • The command unionfs-fuse /=RO:/usr=RO:/var=RO:/home=RO union seems quite random in the sense that union will contain the content from all four directories mixed together. Why would I want the content of /usr, /var and /home mixed into /?! - Being new to unionfs it took me some time to figure out that this should be separate mount calls, more like here: https://github.com/rpodgorny/unionfs-fuse/blob/master/examples/unionfs-fuse-nfs-root#L90-L106. Man page here: https://linux.die.net/man/8/unionfs – Martin Rüegg Oct 30 '23 at 19:59
0

One solution is to make a separate overlay for what should end up as /chroot/home somewhere else, then bind it on top of the overlay for /chroot

-2

We committed the solution in: http://bazaar.launchpad.net/~ltsp-upstream/ltsp/ltsp-trunk/revision/2652

alkisg
  • 550
  • 7
  • 6
  • 2
    Can you expand your answer here a bit to explain in principle what you did, or even better include the full solution? – Zanna Sep 04 '18 at 08:01