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