AuFS (another union file system) allows us to merge two trees into one, even when those trees overlap. We can then direct writes to the merged tree towards one of the branches and reads to another.
The classic use of this is with a flash file system and a ram disk, like this (ref 1) to create a read-only root file system that does not break Linux. All file writes go to ram. After a reboot the system restore itself to the as-shipped configuration.
/dir1
= read only/dir2
= read/write/aufs
= merge of/dir1
and/dir2
/aufs
is then re-mounted with --move
to make it /
(root)
Simplified, the example in (ref 1) just does this
mount -t aufs br=/dir2:/dir1 /aufs
mount --move /aufs /
However, I want to use it such that the writable (/dir2
) is on a real disk, not a ramdisk. That way after a reboot it will retain it's data.
But I need to ensure certain files in dir2 are not preserved and are restored to their (/dir1
) defaults. This ensures future boots always use the as-shipped files. Without loosing user and logging data.
e.g. Changed files in /etc
, /bin
, /boot
, /usr
should not survive a reboot.
The AUFS web page (ref 2) has very few examples.
So to the question: What is the correct way to do this using AuFS?
I can think of the following:
- Modify the first mount command in some way
- Add more mount commands using the aufs add/del before second mount
- Simply delete the trees that should not be preserved from
/dir2
at boot time - Partial tree (
etc, bin, boot, lib, etc
) intmpfs
Ref 1: https://help.ubuntu.com/community/aufsRootFileSystemOnUsbFlash
Ref 2: http://aufs.sourceforge.net/aufs.html