.\" The Regents of the University of California. All rights reserved.
.\" This code is derived from software donated to Berkeley by
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" @(#)mount_union.8 8.7 (Berkeley) 5/1/95
.Nd mount union filesystems
in such a way that the contents of both directory trees remain visible.
The options are as follows:
Invert the default position, so that
becomes the lower layer and
Options are specified with a
flag followed by a comma separated string of options.
man page for possible options and their meanings.
Hide the lower layer completely in the same way as mounting with
To enforce filesystem security, the user mounting the filesystem
must be superuser or else have write permission on the mounted-on
Filenames are looked up in the upper layer and then in the
If a directory is found in the lower layer, and there is no entry
in the upper layer, then a
directory will be created in the upper layer.
It will be owned by the user who originally did the union mount,
(0777) modified by the umask in effect at that time.
If a file exists in the upper layer then there is no way to access
a file with the same name in the lower layer.
If necessary, a combination of loopback and union mounts can be made
which will still allow the lower files to be accessed by a different
Except in the case of a directory,
access to an object is granted via the normal filesystem access checks.
For directories, the current user must have access to both the upper
and lower directories (should they both exist).
Requests to create or modify objects in
are passed to the upper layer with the exception of a few special cases.
An attempt to open for writing a file which exists in the lower layer
file to be made to the upper layer, and then for the upper layer copy
Similarly, an attempt to truncate a lower layer file to zero length
causes an empty file to be created in the upper layer.
Any other operation which would ultimately require modification to
the lower layer fails with
The union filesystem manipulates the namespace, rather than
The union operation applies recursively down the directory tree
Thus any filesystems which are mounted under
will take part in the union operation.
which only applies the union operation to the mount point itself,
and then only for lookups.
.Bd -literal -offset indent
mount -t cd9660 -o ro /dev/cd0a /usr/src
mount -t union -o /var/obj /usr/src
For most purposes the effect of this is to make the
source tree appear writable
even though it is stored on a CD-ROM.
.Bd -literal -offset indent
mount -t union -o -b /sys $HOME/sys
attaches the system source tree below the
directory in the user's home directory.
This allows individual users to make private changes
to the source, and build new kernels, without those
changes becoming visible to other users.
Note that the files in the lower layer remain
Without whiteout support from the filesystem backing the upper layer,
there is no way that delete and rename operations on lower layer
is returned for this kind of operations along with any others
which would make modifications to the lower layer, such as
over a union tree has the side-effect of creating
a tree of shadow directories in the upper layer.
command first appeared in