Union mount – AUFS How-to

Recently I was searching for a method to mount two directory in to single mount point. Any change done in the mount directory should reflect in one of the directory 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 filesystems and directories and I was looking specifically directories which is supported by Aufs. I quickly installed the tool and ran a test to see its working.

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 ..
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 *