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.\" $FreeBSD$ 37.\" 38.Dd March 27, 1994 39.Dt MOUNT_UNIONFS 8 40.Os 41.Sh NAME 42.Nm mount_unionfs 43.Nd mount union filesystems 44.Sh SYNOPSIS 45.Nm 46.Op Fl br 47.Op Fl o Ar options 48.Ar directory 49.Ar uniondir 50.Sh DESCRIPTION 51The 52.Nm 53utility attaches 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_nullfs 8 . 89.El 90.Pp 91To enforce filesystem security, the user mounting the filesystem 92must be superuser or else have write permission on the mounted-on 93directory. 94.Pp 95Filenames are looked up in the upper layer and then in the 96lower layer. 97If a directory is found in the lower layer, and there is no entry 98in the upper layer, then a 99.Em shadow 100directory will be created in the upper layer. 101It will be owned by the user who originally did the union mount, 102with mode 103.Dq rwxrwxrwx 104(0777) modified by the umask in effect at that time. 105.Pp 106If a file exists in the upper layer then there is no way to access 107a file with the same name in the lower layer. 108If necessary, a combination of loopback and union mounts can be made 109which will still allow the lower files to be accessed by a different 110pathname. 111.Pp 112Except in the case of a directory, 113access to an object is granted via the normal filesystem access checks. 114For directories, the current user must have access to both the upper 115and lower directories (should they both exist). 116.Pp 117Requests to create or modify objects in 118.Ar uniondir 119are passed to the upper layer with the exception of a few special cases. 120An attempt to open for writing a file which exists in the lower layer 121causes a copy of the 122.Em entire 123file to be made to the upper layer, and then for the upper layer copy 124to be opened. 125Similarly, an attempt to truncate a lower layer file to zero length 126causes an empty file to be created in the upper layer. 127Any other operation which would ultimately require modification to 128the lower layer fails with 129.Er EROFS . 130.Pp 131The union filesystem manipulates the namespace, rather than 132individual filesystems. 133The union operation applies recursively down the directory tree 134now rooted at 135.Ar uniondir . 136Thus any filesystems which are mounted under 137.Ar uniondir 138will take part in the union operation. 139This differs from the 140.Em union 141option to 142.Xr mount 8 143which only applies the union operation to the mount point itself, 144and then only for lookups. 145.Sh EXAMPLES 146The commands 147.Bd -literal -offset indent 148mount -t cd9660 -o ro /dev/cd0a /usr/src 149mount -t unionfs /var/obj /usr/src 150.Ed 151.Pp 152mount the CD-ROM drive 153.Pa /dev/cd0a 154on 155.Pa /usr/src 156and then attaches 157.Pa /var/obj 158on top. 159For most purposes the effect of this is to make the 160source tree appear writable 161even though it is stored on a CD-ROM. 162.Pp 163The command 164.Bd -literal -offset indent 165mount -t unionfs -o -b /sys $HOME/sys 166.Ed 167.Pp 168attaches the system source tree below the 169.Pa sys 170directory in the user's home directory. 171This allows individual users to make private changes 172to the source, and build new kernels, without those 173changes becoming visible to other users. 174Note that the files in the lower layer remain 175accessible via 176.Pa /sys . 177.Sh SEE ALSO 178.Xr intro 2 , 179.Xr mount 2 , 180.Xr unmount 2 , 181.Xr fstab 5 , 182.Xr mount 8 , 183.Xr mount_nullfs 8 184.Sh BUGS 185THIS FILESYSTEM TYPE IS NOT YET FULLY SUPPORTED (READ: IT DOESN'T WORK) 186AND USING IT MAY, IN FACT, DESTROY DATA ON YOUR SYSTEM. USE AT YOUR 187OWN RISK. BEWARE OF DOG. SLIPPERY WHEN WET. 188.Pp 189This code also needs an owner in order to be less dangerous - serious 190hackers can apply by sending mail to 191.Aq hackers@FreeBSD.org 192and announcing 193their intent to take it over. 194.Pp 195Without whiteout support from the filesystem backing the upper layer, 196there is no way that delete and rename operations on lower layer 197objects can be done. 198.Er EROFS 199is returned for this kind of operations along with any others 200which would make modifications to the lower layer, such as 201.Xr chmod 1 . 202.Pp 203Running 204.Xr find 1 205over a union tree has the side-effect of creating 206a tree of shadow directories in the upper layer. 207.Sh HISTORY 208The 209.Nm 210utility first appeared in 211.Bx 4.4 . 212It first worked in 213.Fx Ns -(fill this in) . 214