xref: /netbsd-src/sbin/mount_union/mount_union.8 (revision 27578b9aac214cc7796ead81dcc5427e79d5f2a0)
1.\"	$NetBSD: mount_union.8,v 1.10 2001/06/05 11:22:51 wiz Exp $
2.\"
3.\" Copyright (c) 1994
4.\" The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software donated to Berkeley by
7.\" Jan-Simon Pendry.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the University of
20.\"	California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\"    may be used to endorse or promote products derived from this software
23.\"    without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\"	@(#)mount_union.8	8.7 (Berkeley) 5/1/95
38.\"
39.Dd May 1, 1995
40.Dt MOUNT_UNION 8
41.Os
42.Sh NAME
43.Nm mount_union
44.Nd mount union filesystems
45.Sh SYNOPSIS
46.Nm ""
47.Op Fl br
48.Op Fl o Ar options
49.Ar directory
50.Ar uniondir
51.Sh DESCRIPTION
52The
53.Nm
54command
55attaches
56.Ar directory
57above
58.Ar uniondir
59in such a way that the contents of both directory trees remain visible.
60By default,
61.Ar directory
62becomes the
63.Em upper
64layer and
65.Ar uniondir
66becomes the
67.Em lower
68layer.
69.Pp
70The options are as follows:
71.Bl -tag -width indent
72.It Fl b
73Invert the default position, so that
74.Ar directory
75becomes the lower layer and
76.Ar uniondir
77becomes the upper layer.
78However,
79.Ar uniondir
80remains the mount point.
81.It Fl o
82Options are specified with a
83.Fl o
84flag followed by a comma separated string of options.
85See the
86.Xr mount 8
87man page for possible options and their meanings.
88.It Fl r
89Hide the lower layer completely in the same way as mounting with
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 /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_null 8 ,
186.Xr fsck_ffs 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.
191An attempt to mount a union directory under one which does not
192have whiteout support will return
193.Dv EOPNOTSUPP
194(``Operation not supported'').
195Whiteout support can be added to an existing FFS filesystem
196by using the
197.Fl c
198option of
199.Xr fsck_ffs 8 .
200.Pp
201Running
202.Xr find 1
203over a union tree has the side-effect of creating
204a tree of shadow directories in the upper layer.
205.Sh HISTORY
206The
207.Nm
208command first appeared in
209.Bx 4.4 .
210