Namespaced directories in Linux

Every now and then, I have a need for namespaced directories.  What do I mean by that? I want a path in my filesystem that has the same name, but different contents, depending on which shell (namespace) it is accessed from.  Linux makes this fairly easy:

Setup

Create test directories and directory contents:

In a shell, unshare into a new mount namespace, rbind mount base1 to namespace_dir, then inspect the contents of namespace_dir:


In a different shell, unshare into another new mount namespace, rbind mount base2 to namespace_dir, then inspect the contents of namespace_dir: You'll notice that in the first new shell, namespace_dir will contain file1.txt, whereas in the second new shell, namespace_dir will contain file2.txt.

Comments

Popular Posts