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.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)mount_union.8 8.7 (Berkeley) 05/01/95 10.\" 11.Dd 12.Dt MOUNT_UNION 8 13.Os BSD 4.4 14.Sh NAME 15.Nm mount_union 16.Nd mount union filesystems 17.Sh SYNOPSIS 18.Nm mount_union 19.Op Fl br 20.Op Fl o Ar options 21.Ar directory 22.Ar uniondir 23.Sh DESCRIPTION 24The 25.Nm mount_union 26command 27attaches 28.Ar directory 29above 30.Ar uniondir 31in such a way that the contents of both directory trees remain visible. 32By default, 33.Ar directory 34becomes the 35.Em upper 36layer and 37.Ar uniondir 38becomes the 39.Em lower 40layer. 41.Pp 42The options are as follows: 43.Bl -tag -width indent 44.It Fl b 45Invert the default position, so that 46.Ar directory 47becomes the lower layer and 48.Ar uniondir 49becomes the upper layer. 50However, 51.Ar uniondir 52remains the mount point. 53.It Fl o 54Options are specified with a 55.Fl o 56flag followed by a comma separated string of options. 57See the 58.Xr mount 8 59man page for possible options and their meanings. 60.It Fl r 61Hide the lower layer completely in the same way as mounting with 62.Xr mount_null 8 . 63.El 64.Pp 65To enforce filesystem security, the user mounting the filesystem 66must be superuser or else have write permission on the mounted-on 67directory. 68.Pp 69Filenames are looked up in the upper layer and then in the 70lower layer. 71If a directory is found in the lower layer, and there is no entry 72in the upper layer, then a 73.Em shadow 74directory will be created in the upper layer. 75It will be owned by the user who originally did the union mount, 76with mode 77.Dq rwxrwxrwx 78(0777) modified by the umask in effect at that time. 79.Pp 80If a file exists in the upper layer then there is no way to access 81a file with the same name in the lower layer. 82If necessary, a combination of loopback and union mounts can be made 83which will still allow the lower files to be accessed by a different 84pathname. 85.Pp 86Except in the case of a directory, 87access to an object is granted via the normal filesystem access checks. 88For directories, the current user must have access to both the upper 89and lower directories (should they both exist). 90.Pp 91Requests to create or modify objects in 92.Ar uniondir 93are passed to the upper layer with the exception of a few special cases. 94An attempt to open for writing a file which exists in the lower layer 95causes a copy of the 96.Em entire 97file to be made to the upper layer, and then for the upper layer copy 98to be opened. 99Similarly, an attempt to truncate a lower layer file to zero length 100causes an empty file to be created in the upper layer. 101Any other operation which would ultimately require modification to 102the lower layer fails with 103.Dv EROFS . 104.Pp 105The union filesystem manipulates the namespace, rather than 106individual filesystems. 107The union operation applies recursively down the directory tree 108now rooted at 109.Ar uniondir . 110Thus any filesystems which are mounted under 111.Ar uniondir 112will take part in the union operation. 113This differs from the 114.Em union 115option to 116.Xr mount 8 117which only applies the union operation to the mount point itself, 118and then only for lookups. 119.Sh EXAMPLES 120The commands 121.Bd -literal -offset indent 122mount -t cd9660 -o ro /dev/cd0a /usr/src 123mount -t union -o /var/obj /usr/src 124.Ed 125.Pp 126mount the CD-ROM drive 127.Pa /dev/cd0a 128on 129.Pa /usr/src 130and then attaches 131.Pa /var/obj 132on top. 133For most purposes the effect of this is to make the 134source tree appear writable 135even though it is stored on a CD-ROM. 136.Pp 137The command 138.Bd -literal -offset indent 139mount -t union -o -b /sys $HOME/sys 140.Ed 141.Pp 142attaches the system source tree below the 143.Pa sys 144directory in the user's home directory. 145This allows individual users to make private changes 146to the source, and build new kernels, without those 147changes becoming visible to other users. 148Note that the files in the lower layer remain 149accessible via 150.Pa /sys . 151.Sh SEE ALSO 152.Xr intro 2 , 153.Xr mount 2 , 154.Xr unmount 2 , 155.Xr fstab 5 , 156.Xr mount 8 , 157.Xr mount_null 8 158.Sh BUGS 159Without whiteout support from the filesystem backing the upper layer, 160there is no way that delete and rename operations on lower layer 161objects can be done. 162.Dv EROFS 163is returned for this kind of operations along with any others 164which would make modifications to the lower layer, such as 165.Xr chmod 1 . 166.Pp 167Running 168.Xr find 1 169over a union tree has the side-effect of creating 170a tree of shadow directories in the upper layer. 171.Sh HISTORY 172The 173.Nm mount_union 174command first appeared in 175.Bx 4.4 . 176