Say, we initially have / with the following contents:


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


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


(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" /.

  • Possible duplicate of Merging folders with mv? – MelBurslan Jul 8 '16 at 15:33
  • 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 8 '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. – user2064000 Jul 8 '16 at 16:02

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 /
  • I have a question here: can overlayfs be run this way multiple times? (i.e. once with /stuff, then with /otherstuff and so on)? – user2064000 Jul 9 '16 at 3:43
  • @user2064000 AFAIK it can (I don't remember reading about a restriction) but I don't think I've ever tried it. – Gilles 'SO- stop being evil' Jul 9 '16 at 14:05

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.