Union mount – AUFS How-to

Recently I was searching for a method to mount two directories in to a single mount point. Any change done in the mount directory, should reflect in one of the directories, while the other remains intact. This feature is called Union-mount, there is a wikipedia link to it .

Here the union-mount refers to both file systems and directories and I was looking specifically for directories which are supported by Aufs. I quickly installed the tool and ran a test to see its working.

Code:

sudo apt-get install aufs-tools


$mkdir aufstest
$cd aufstest
$mkdir rodir  # read only directory
$mkdir rwdir  # writeable directory
$mkdir mntdir # mount point directory
$cd rodir
$mkdir a b c d
$touch a/1 b/2 c/3 d/4
$cd ..

$cd rwdir
$mkdir e f g h
$touch e/5 f/6 g/7 h/8
$cd ..

Union Mount:

sudo mount -t aufs -o br=./rwdir:./rodir none mntdir/
$cd mntdir
$touch a/test e/test
$cd ..
$umount mntdir
$tree
.
├── mntdir
├── rodir
│   ├── a
│   │   └── 1
│   ├── b
│   │   └── 2
│   ├── c
│   │   └── 3
│   └── d
│       └── 4
└── rwdir
    ├── a
    │   └── test
    ├── e
    │   ├── 5
    │   └── test
    ├── f
    │   └── 6
    ├── g
    │   └── 7
    └── h
        └── 8

Leave a Reply

Your email address will not be published. Required fields are marked *