xref: /freebsd/sbin/mount_unionfs/mount_unionfs.8 (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1.\" Copyright (c) 1994
2.\" The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software donated to Berkeley by
5.\" Jan-Simon Pendry.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"	@(#)mount_union.8	8.6 (Berkeley) 3/27/94
36.\"
37.Dd March 27, 1994
38.Dt MOUNT_UNION 8
39.Os BSD 4.4
40.Sh NAME
41.Nm mount_union
42.Nd mount union filesystems
43.Sh SYNOPSIS
44.Nm mount_union
45.Op Fl br
46.Op Fl o Ar options
47.Ar directory
48.Ar uniondir
49.Sh DESCRIPTION
50The
51.Nm mount_union
52command
53attaches
54.Ar directory
55above
56.Ar uniondir
57in such a way that the contents of both directory trees remain visible.
58By default,
59.Ar directory
60becomes the
61.Em upper
62layer and
63.Ar uniondir
64becomes the
65.Em lower
66layer.
67.Pp
68The options are as follows:
69.Bl -tag -width indent
70.It Fl b
71Invert the default position, so that
72.Ar directory
73becomes the lower layer and
74.Ar uniondir
75becomes the upper layer.
76However,
77.Ar uniondir
78remains the mount point.
79.It Fl o
80Options are specified with a
81.Fl o
82flag followed by a comma separated string of options.
83See the
84.Xr mount 8
85man page for possible options and their meanings.
86.It Fl r
87Hide the lower layer completely in the same way as mounting with
88.Xr mount_lofs 8
89or
90.Xr mount_null 8 .
91.El
92.Pp
93To enforce filesystem security, the user mounting the filesystem
94must be superuser or else have write permission on the mounted-on
95directory.
96.Pp
97Filenames are looked up in the upper layer and then in the
98lower layer.
99If a directory is found in the lower layer, and there is no entry
100in the upper layer, then a
101.Em shadow
102directory will be created in the upper layer.
103It will be owned by the user who originally did the union mount,
104with mode
105.Dq rwxrwxrwx
106(0777) modified by the umask in effect at that time.
107.Pp
108If a file exists in the upper layer then there is no way to access
109a file with the same name in the lower layer.
110If necessary, a combination of loopback and union mounts can be made
111which will still allow the lower files to be accessed by a different
112pathname.
113.Pp
114Except in the case of a directory,
115access to an object is granted via the normal filesystem access checks.
116For directories, the current user must have access to both the upper
117and lower directories (should they both exist).
118.Pp
119Requests to create or modify objects in
120.Ar uniondir
121are passed to the upper layer with the exception of a few special cases.
122An attempt to open for writing a file which exists in the lower layer
123causes a copy of the
124.Em entire
125file to be made to the upper layer, and then for the upper layer copy
126to be opened.
127Similarly, an attempt to truncate a lower layer file to zero length
128causes an empty file to be created in the upper layer.
129Any other operation which would ultimately require modification to
130the lower layer fails with
131.Dv EROFS .
132.Pp
133The union filesystem manipulates the namespace, rather than
134individual filesystems.
135The union operation applies recursively down the directory tree
136now rooted at
137.Ar uniondir .
138Thus any filesystems which are mounted under
139.Ar uniondir
140will take part in the union operation.
141This differs from the
142.Em union
143option to
144.Xr mount 8
145which only applies the union operation to the mount point itself,
146and then only for lookups.
147.Sh EXAMPLES
148The commands
149.Bd -literal -offset indent
150mount -t cd9660 -o ro /dev/cd0a /usr/src
151mount -t union -o /var/obj /usr/src
152.Ed
153.Pp
154mount the CD-ROM drive
155.Pa /dev/cd0a
156on
157.Pa /usr/src
158and then attaches
159.Pa /var/obj
160on top.
161For most purposes the effect of this is to make the
162source tree appear writable
163even though it is stored on a CD-ROM.
164.Pp
165The command
166.Bd -literal -offset indent
167mount -t union -o -b /sys $HOME/sys
168.Ed
169.Pp
170attaches the system source tree below the
171.Pa sys
172directory in the user's home directory.
173This allows individual users to make private changes
174to the source, and build new kernels, without those
175changes becoming visible to other users.
176Note that the files in the lower layer remain
177accessible via
178.Pa /sys .
179.Sh SEE ALSO
180.Xr intro 2 ,
181.Xr mount 2 ,
182.Xr unmount 2 ,
183.Xr fstab 5 ,
184.Xr mount 8 ,
185.Xr mount_lofs 8 ,
186.Xr mount_null 8
187.Sh BUGS
188Without whiteout support from the filesystem backing the upper layer,
189there is no way that delete and rename operations on lower layer
190objects can be done.
191.Dv EROFS
192is returned for this kind of operations along with any others
193which would make modifications to the lower layer, such as
194.Xr chmod 1 .
195.Pp
196Running
197.Xr find 1
198over a union tree has the side-effect of creating
199a tree of shadow directories in the upper layer.
200.Sh HISTORY
201The
202.Nm mount_union
203command first appeared in
204.Bx 4.4 .
205