2

Say, we initially have / with the following contents:

/bin/foo
/usr/bin/bar
/usr/lib/libfoo.so

We also have another directory, say /stuff, with the contents:

usr/lib/mystuff/mystuff.so
etc/foo/qux/buzz
bin/stuff

Is there a way to create a union between / and /stuff, so that I get:

/bin/foo
/bin/stuff
/usr/bin/bar
/usr/lib/libfoo.so
/usr/lib/mystuff/mystuff.so
/etc/foo/qux/buzz

(with all of the content from /stuff there as well, just not shown there.)

This union should be of a temporary nature (just like filesystem mounts are), otherwise I could have used cp, mv or rsync as well.

How should I go about doing this?

One would expect that an answer to this would be easy to find; and indeed, there are many online resources that mention creating unions between two directories and mount them elsewhere, but none really cover this particular case of mounting a directory "over" /.

  • you are looking for rsync as the tool of choice. Your question has been discussed many times, on may places online. Please see the command syntax on the duplicate post. – MelBurslan Jul 08 '16 at 15:34
  • 1
    @MelBurslan: what? Did you even read the question? It explicitly states: "This union should be of a temporary nature, otherwise I could have used cp or mv as well." I'm looking for answers covering union filesystems; but the thing is that I can't find a resource that discusses my specific case (mounting onto /); and if I try to adapt the resources I did find to my case they either don't work or emit strange errors. –  Jul 08 '16 at 16:02

1 Answers1

0

Look at live distributions with persistence for an example of this.

Not all union mount methods work with the root directory. Amongst those that do are unionfs, aufs and overlayfs. Overlayfs is the way to go on modern Linux systems.

In overlayfs, you get the union of the lower filesystem and the upper filesystem, with the upper filesystem taking precedence and receiving writes. To get a writable union, you need to specify a work directory for overlayfs to store metadata; this must be an empty directory on the same filesystem as the upper directory.

mkdir /stuff/.overlayfs.work
mount -t overlay -o lowerdir=/,upperdir=/stuff,workdir=/stuff/.overlayfs.work overlay /