aufsをUbuntu 14.04上で使ってみました。
aufsは、複数のディレクトリを重ねてあるディレクトリにマウントすることができるファイルシステムで、knoppixのように書き込みできないメディアに擬似的に書き込んだり、LXCであるコンテナのディレクトリのスナップショットを使って新しいコンテナを作ったりする時に使われるようです。
使い方は簡単ですので、実験してみます。
まず3つディレクトリを用意します。ここでは、org-dir と rw-dir, mnt とします。
# mkdir org-dir # mkdir rw-dir # mkdir mnt
org-dir に何か適当にファイルを作ります。
# echo org > org-dir/file1 # echo org > org-dir/file2 # echo org > org-dir/file3
次に、rw-dir にも適当にファイルを作ります。
# echo rw > rw-dir/file3 # echo rw > rw-dir/file4
全体のディレクトリとファイル構成はこんな感じになりました。
ll -R .: total 20 drwxr-xr-x 5 root root 4096 Sep 14 01:24 ./ drwx------ 6 root root 4096 Sep 14 01:24 ../ drwxr-xr-x 2 root root 4096 Sep 14 01:24 mnt/ drwxr-xr-x 2 root root 4096 Sep 14 01:58 org-dir/ drwxr-xr-x 2 root root 4096 Sep 14 01:58 rw-dir/ ./mnt: total 8 drwxr-xr-x 2 root root 4096 Sep 14 01:24 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ ./org-dir: total 20 drwxr-xr-x 2 root root 4096 Sep 14 01:58 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 4 Sep 14 01:24 file1 -rw-r--r-- 1 root root 4 Sep 14 01:24 file2 -rw-r--r-- 1 root root 4 Sep 14 01:24 file3 ./rw-dir: total 16 drwxr-xr-x 2 root root 4096 Sep 14 01:58 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4
ここで、org-dir と rw-dir を重ね合わせて、mntディレクトリにマウントしてみます。org-dir がオリジナルのディレクトリで書き込み禁止(ro)として、rw-dir がファイルの変更を書き込む(rw)ことができるディレクトリとしてmntディレクトリにマウントします。イメージは、org-dir に rw-dir を重ねるイメージです。
# mount -t aufs -o br:rw-dir=rw,br:org-dir=ro aufs mnt
mntディレクトリを覗いてみます。
# ll mnt/ total 24 drwxr-xr-x 4 root root 4096 Sep 14 02:02 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 4 Sep 14 01:24 file1 -rw-r--r-- 1 root root 4 Sep 14 01:24 file2 -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4
確かに、org-dir と rw-dir の内容が見えます。rw-dirを上に重ねているので、org-dir の file3 は rw-dir の file3 で隠されてしまい、見えません。
# cat mnt/file3 rw
rw-dir にはマウントした時に、aufsの管理用のディレクトリが作られます。
# ll rw-dir/ total 24 drwxr-xr-x 4 root root 4096 Sep 14 02:02 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -r--r--r-- 1 root root 0 Sep 14 02:02 .wh..wh.aufs drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.orph/ drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.plnk/ -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4
mnt ディレクトリに何か書き込めば、それはすべてrw-dirに反映されます。
# echo new > mnt/new-file1 # ll rw-dir/ total 28 drwxr-xr-x 4 root root 4096 Sep 14 02:07 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -r--r--r-- 1 root root 0 Sep 14 02:02 .wh..wh.aufs drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.orph/ drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.plnk/ -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4 -rw-r--r-- 1 root root 4 Sep 14 02:07 new-file1 # ll mnt/ total 28 drwxr-xr-x 4 root root 4096 Sep 14 02:09 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 4 Sep 14 01:24 file1 -rw-r--r-- 1 root root 4 Sep 14 01:24 file2 -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4 -rw-r--r-- 1 root root 4 Sep 14 02:07 new-file1
ファイルを削除すると、rw-dirに削除情報が書き込まれ、mntディレクトリからは見えなくなります。
# rm -f mnt/file1 # ll rw-dir/ total 28 drwxr-xr-x 4 root root 4096 Sep 14 02:09 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -r--r--r-- 2 root root 0 Sep 14 02:02 .wh..wh.aufs drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.orph/ drwx------ 2 root root 4096 Sep 14 02:02 .wh..wh.plnk/ -r--r--r-- 2 root root 0 Sep 14 02:02 .wh.file1 -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4 -rw-r--r-- 1 root root 4 Sep 14 02:07 new-file1 # ll mnt/ total 28 drwxr-xr-x 4 root root 4096 Sep 14 02:09 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 4 Sep 14 01:24 file2 -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4 -rw-r--r-- 1 root root 4 Sep 14 02:07 new-file1
ちょっと意地悪く、削除情報と同名のファイルをmntに作ってみると、こんなふうに怒られます(笑)
# echo wh > mnt/.wh.file1 -su: mnt/.wh.file1: Operation not permitted
マウントした状態で、org-dir に新しいファイルを書き込み、rw-dir に同名のファイルや削除情報がない場合は、そのままmnt内に見えてしまいます。
# echo org > org-dir/fileA # ll mnt/ total 28 drwxr-xr-x 4 root root 4096 Sep 14 02:09 ./ drwxr-xr-x 5 root root 4096 Sep 14 01:24 ../ -rw-r--r-- 1 root root 4 Sep 14 01:24 file2 -rw-r--r-- 1 root root 3 Sep 14 01:58 file3 -rw-r--r-- 1 root root 3 Sep 14 01:58 file4 -rw-r--r-- 1 root root 4 Sep 14 02:13 fileA -rw-r--r-- 1 root root 4 Sep 14 02:07 new-file1
なお、今回は小さいファイルで試しましたが、org-dir に大きなファイルがあり、mnt上からファイルを書き換えると、org-dir上の大きなファイルが一旦rw-dir上にコピーされ、その後書き換わるため、パフォーマンスかなり落ちてしまいますので、注意が必要です。