|
楼主 |
发表于 2006-12-16 14:48:19
|
显示全部楼层
或者看官方文档
Using unionfs
In the following example, we will merge contents of two directories into a single directory /mnt/union. We assume that all directories already exist.
$ modprobe unionfs
$ mount -t unionfs -o dirs=/mnt/cdrom1=ro:/mnt/cdrom2=ro unionfs /mnt/union
From now, the directory /mnt/union will contain all files and directories from /mnt/cdrom1 and /mnt/cdrom2, merged together and both read only. If the same filename is used in both cdrom directories, the one from cdrom1 has precedence (because it was specified leftmost in the list).
Using unionctl
Unionctl is a tool which is created (together with uniondbg) during unionfs compilation and is installed to /usr/local/sbin. Unionctl is intended to manage the existing union, to list, add, modify or delete existing branches. Some simple example follows, use unionctl command without any argument to see all available options.
To list branches in existing union, use
$ unionctl /mnt/union --list
which will produce the following output
/mnt/cdrom1 (r-)
/mnt/cdrom2 (r-)
To add another directory (/mnt/cdrom3) into existing union, use
$ unionctl /mnt/union --add --after /mnt/cdrom2 --mode ro /mnt/cdrom3
and unionctl --list will now produce
/mnt/cdrom1 (r-)
/mnt/cdrom2 (r-)
/mnt/cdrom3 (r-)
In the case when you change the content of branches themselves, execute the following command to force revalidation of the union:
uniondbg -g /mnt/union
Writing to union
Merging read-only directories is useful in many cases, but the union itself remains read-only too, until a read-write branch is added to it. In that case, all changes are stored in leftmost branch (using copy-up method, see below) and file deletions are done by using one of the two methods available:
*
WHITEOUT mode, inserts a .wh (whiteout) file to mask out a real file
*
DELETE_ALL mode, tries to delete all instances of a file from all branches
WHITEOUT mode is used as default. Copy-up is a special method used to handle file modifications in union. A file from ro branch can't be modified, so it is copied to upper (left) read-write branch at the time when the modification should begin. Then the modification is possible and modified file remains in rw branch.
To add a rw branch at the top of union in our example, type
$ unionctl /mnt/union --add --before /mnt/cdrom1 --mode rw /mnt/changes
All the changes will be stored in /mnt/changes and the union will look like this:
/mnt/changes (rw)
/mnt/cdrom1 (r-)
/mnt/cdrom2 (r-)
/mnt/cdrom3 (r-) |
|