Blame man7/mount_namespaces.7

Packit 7cfc04
.\" Copyright (c) 2016 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.TH MOUNT_NAMESPACES 7 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
mount_namespaces \- overview of Linux mount namespaces
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
For an overview of namespaces, see
Packit 7cfc04
.BR namespaces (7).
Packit 7cfc04
.PP
Packit 7cfc04
Mount namespaces provide isolation of the list of mount points seen
Packit 7cfc04
by the processes in each namespace instance.
Packit 7cfc04
Thus, the processes in each of the mount namespace instances
Packit 7cfc04
will see distinct single-directory hierarchies.
Packit 7cfc04
.PP
Packit 7cfc04
The views provided by the
Packit 7cfc04
.IR /proc/[pid]/mounts ,
Packit 7cfc04
.IR /proc/[pid]/mountinfo ,
Packit 7cfc04
and
Packit 7cfc04
.IR /proc/[pid]/mountstats
Packit 7cfc04
files (all described in
Packit 7cfc04
.BR proc (5))
Packit 7cfc04
correspond to the mount namespace in which the process with the PID
Packit 7cfc04
.IR [pid]
Packit 7cfc04
resides.
Packit 7cfc04
(All of the processes that reside in the same mount namespace
Packit 7cfc04
will see the same view in these files.)
Packit 7cfc04
.PP
Packit 7cfc04
When a process creates a new mount namespace using
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
or
Packit 7cfc04
.BR unshare (2)
Packit 7cfc04
with the
Packit 7cfc04
.BR CLONE_NEWNS
Packit 7cfc04
flag, the mount point list for the new namespace is a
Packit 7cfc04
.I copy
Packit 7cfc04
of the caller's mount point list.
Packit 7cfc04
Subsequent modifications to the mount point list
Packit 7cfc04
.RB ( mount (2)
Packit 7cfc04
and
Packit 7cfc04
.BR umount (2))
Packit 7cfc04
in either mount namespace will not (by default) affect the
Packit 7cfc04
mount point list seen in the other namespace
Packit 7cfc04
(but see the following discussion of shared subtrees).
Packit 7cfc04
.\"
Packit 7cfc04
.\" ============================================================
Packit 7cfc04
.\"
Packit 7cfc04
.SS Restrictions on mount namespaces
Packit 7cfc04
Note the following points with respect to mount namespaces:
Packit 7cfc04
.IP * 3
Packit 7cfc04
A mount namespace has an owner user namespace.
Packit 7cfc04
A mount namespace whose owner user namespace is different from
Packit 7cfc04
the owner user namespace of its parent mount namespace is
Packit 7cfc04
considered a less privileged mount namespace.
Packit 7cfc04
.IP *
Packit 7cfc04
When creating a less privileged mount namespace,
Packit 7cfc04
shared mounts are reduced to slave mounts.
Packit 7cfc04
(Shared and slave mounts are discussed below.)
Packit 7cfc04
This ensures that mappings performed in less
Packit 7cfc04
privileged mount namespaces will not propagate to more privileged
Packit 7cfc04
mount namespaces.
Packit 7cfc04
.IP *
Packit 7cfc04
.\" FIXME .
Packit 7cfc04
.\"	What does "come as a single unit from more privileged mount" mean?
Packit 7cfc04
Mounts that come as a single unit from more privileged mount are
Packit 7cfc04
locked together and may not be separated in a less privileged mount
Packit 7cfc04
namespace.
Packit 7cfc04
(The
Packit 7cfc04
.BR unshare (2)
Packit 7cfc04
.B CLONE_NEWNS
Packit 7cfc04
operation brings across all of the mounts from the original
Packit 7cfc04
mount namespace as a single unit,
Packit 7cfc04
and recursive mounts that propagate between
Packit 7cfc04
mount namespaces propagate as a single unit.)
Packit 7cfc04
.IP *
Packit 7cfc04
The
Packit 7cfc04
.BR mount (2)
Packit 7cfc04
flags
Packit 7cfc04
.BR MS_RDONLY ,
Packit 7cfc04
.BR MS_NOSUID ,
Packit 7cfc04
.BR MS_NOEXEC ,
Packit 7cfc04
and the "atime" flags
Packit 7cfc04
.RB ( MS_NOATIME ,
Packit 7cfc04
.BR MS_NODIRATIME ,
Packit 7cfc04
.BR MS_RELATIME )
Packit 7cfc04
settings become locked
Packit 7cfc04
.\" commit 9566d6742852c527bf5af38af5cbb878dad75705
Packit 7cfc04
.\" Author: Eric W. Biederman <ebiederm@xmission.com>
Packit 7cfc04
.\" Date:   Mon Jul 28 17:26:07 2014 -0700
Packit 7cfc04
.\"
Packit 7cfc04
.\"      mnt: Correct permission checks in do_remount
Packit 7cfc04
.\"
Packit 7cfc04
when propagated from a more privileged to
Packit 7cfc04
a less privileged mount namespace,
Packit 7cfc04
and may not be changed in the less privileged mount namespace.
Packit 7cfc04
.IP *
Packit 7cfc04
.\" (As of 3.18-rc1 (in Al Viro's 2014-08-30 vfs.git#for-next tree))
Packit 7cfc04
A file or directory that is a mount point in one namespace that is not
Packit 7cfc04
a mount point in another namespace, may be renamed, unlinked, or removed
Packit 7cfc04
.RB ( rmdir (2))
Packit 7cfc04
in the mount namespace in which it is not a mount point
Packit 7cfc04
(subject to the usual permission checks).
Packit 7cfc04
.IP
Packit 7cfc04
Previously, attempting to unlink, rename, or remove a file or directory
Packit 7cfc04
that was a mount point in another mount namespace would result in the error
Packit 7cfc04
.BR EBUSY .
Packit 7cfc04
That behavior had technical problems of enforcement (e.g., for NFS)
Packit 7cfc04
and permitted denial-of-service attacks against more privileged users.
Packit 7cfc04
(i.e., preventing individual files from being updated
Packit 7cfc04
by bind mounting on top of them).
Packit 7cfc04
.\"
Packit 7cfc04
.SH SHARED SUBTREES
Packit 7cfc04
After the implementation of mount namespaces was completed,
Packit 7cfc04
experience showed that the isolation that they provided was,
Packit 7cfc04
in some cases, too great.
Packit 7cfc04
For example, in order to make a newly loaded optical disk
Packit 7cfc04
available in all mount namespaces,
Packit 7cfc04
a mount operation was required in each namespace.
Packit 7cfc04
For this use case, and others,
Packit 7cfc04
the shared subtree feature was introduced in Linux 2.6.15.
Packit 7cfc04
This feature allows for automatic, controlled propagation of mount and unmount
Packit 7cfc04
.I events
Packit 7cfc04
between namespaces
Packit 7cfc04
(or, more precisely, between the members of a
Packit 7cfc04
.IR "peer group"
Packit 7cfc04
that are propagating events to one another).
Packit 7cfc04
.PP
Packit 7cfc04
Each mount point is marked (via
Packit 7cfc04
.BR mount (2))
Packit 7cfc04
as having one of the following
Packit 7cfc04
.IR "propagation types" :
Packit 7cfc04
.TP
Packit 7cfc04
.BR MS_SHARED
Packit 7cfc04
This mount point shares events with members of a peer group.
Packit 7cfc04
Mount and unmount events immediately under this mount point will propagate
Packit 7cfc04
to the other mount points that are members of the peer group.
Packit 7cfc04
.I Propagation
Packit 7cfc04
here means that the same mount or unmount will automatically occur
Packit 7cfc04
under all of the other mount points in the peer group.
Packit 7cfc04
Conversely, mount and unmount events that take place under
Packit 7cfc04
peer mount points will propagate to this mount point.
Packit 7cfc04
.TP
Packit 7cfc04
.BR MS_PRIVATE
Packit 7cfc04
This mount point is private; it does not have a peer group.
Packit 7cfc04
Mount and unmount events do not propagate into or out of this mount point.
Packit 7cfc04
.TP
Packit 7cfc04
.BR MS_SLAVE
Packit 7cfc04
Mount and unmount events propagate into this mount point from
Packit 7cfc04
a (master) shared peer group.
Packit 7cfc04
Mount and unmount events under this mount point do not propagate to any peer.
Packit 7cfc04
.IP
Packit 7cfc04
Note that a mount point can be the slave of another peer group
Packit 7cfc04
while at the same time sharing mount and unmount events
Packit 7cfc04
with a peer group of which it is a member.
Packit 7cfc04
(More precisely, one peer group can be the slave of another peer group.)
Packit 7cfc04
.TP
Packit 7cfc04
.BR MS_UNBINDABLE
Packit 7cfc04
This is like a private mount,
Packit 7cfc04
and in addition this mount can't be bind mounted.
Packit 7cfc04
Attempts to bind mount this mount
Packit 7cfc04
.RB ( mount (2)
Packit 7cfc04
with the
Packit 7cfc04
.BR MS_BIND
Packit 7cfc04
flag) will fail.
Packit 7cfc04
.IP
Packit 7cfc04
When a recursive bind mount
Packit 7cfc04
.RB ( mount (2)
Packit 7cfc04
with the
Packit 7cfc04
.BR MS_BIND
Packit 7cfc04
and
Packit 7cfc04
.BR MS_REC
Packit 7cfc04
flags) is performed on a directory subtree,
Packit 7cfc04
any bind mounts within the subtree are automatically pruned
Packit 7cfc04
(i.e., not replicated)
Packit 7cfc04
when replicating that subtree to produce the target subtree.
Packit 7cfc04
.PP
Packit 7cfc04
For a discussion of the propagation type assigned to a new mount,
Packit 7cfc04
see NOTES.
Packit 7cfc04
.PP
Packit 7cfc04
The propagation type is a per-mount-point setting;
Packit 7cfc04
some mount points may be marked as shared
Packit 7cfc04
(with each shared mount point being a member of a distinct peer group),
Packit 7cfc04
while others are private
Packit 7cfc04
(or slaved or unbindable).
Packit 7cfc04
.PP
Packit 7cfc04
Note that a mount's propagation type determines whether
Packit 7cfc04
mounts and unmounts of mount points
Packit 7cfc04
.I "immediately under"
Packit 7cfc04
the mount point are propagated.
Packit 7cfc04
Thus, the propagation type does not affect propagation of events for
Packit 7cfc04
grandchildren and further removed descendant mount points.
Packit 7cfc04
What happens if the mount point itself is unmounted is determined by
Packit 7cfc04
the propagation type that is in effect for the
Packit 7cfc04
.I parent
Packit 7cfc04
of the mount point.
Packit 7cfc04
.PP
Packit 7cfc04
Members are added to a
Packit 7cfc04
.IR "peer group"
Packit 7cfc04
when a mount point is marked as shared and either:
Packit 7cfc04
.IP * 3
Packit 7cfc04
the mount point is replicated during the creation of a new mount namespace; or
Packit 7cfc04
.IP *
Packit 7cfc04
a new bind mount is created from the mount point.
Packit 7cfc04
.PP
Packit 7cfc04
In both of these cases, the new mount point joins the peer group
Packit 7cfc04
of which the existing mount point is a member.
Packit 7cfc04
A mount ceases to be a member of a peer group when either
Packit 7cfc04
the mount is explicitly unmounted,
Packit 7cfc04
or when the mount is implicitly unmounted because a mount namespace is removed
Packit 7cfc04
(because it has no more member processes).
Packit 7cfc04
.PP
Packit 7cfc04
The propagation type of the mount points in a mount namespace
Packit 7cfc04
can be discovered via the "optional fields" exposed in
Packit 7cfc04
.IR /proc/[pid]/mountinfo .
Packit 7cfc04
(See
Packit 7cfc04
.BR proc (5)
Packit 7cfc04
for details of this file.)
Packit 7cfc04
The following tags can appear in the optional fields
Packit 7cfc04
for a record in that file:
Packit 7cfc04
.TP
Packit 7cfc04
.I shared:X
Packit 7cfc04
This mount point is shared in peer group
Packit 7cfc04
.IR X .
Packit 7cfc04
Each peer group has a unique ID that is automatically
Packit 7cfc04
generated by the kernel,
Packit 7cfc04
and all mount points in the same peer group will show the same ID.
Packit 7cfc04
(These IDs are assigned starting from the value 1,
Packit 7cfc04
and may be recycled when a peer group ceases to have any members.)
Packit 7cfc04
.TP
Packit 7cfc04
.I master:X
Packit 7cfc04
This mount is a slave to shared peer group
Packit 7cfc04
.IR X .
Packit 7cfc04
.TP
Packit 7cfc04
.IR propagate_from:X " (since Linux 2.6.26)"
Packit 7cfc04
.\" commit 97e7e0f71d6d948c25f11f0a33878d9356d9579e
Packit 7cfc04
This mount is a slave and receives propagation from shared peer group
Packit 7cfc04
.IR X .
Packit 7cfc04
This tag will always appear in conjunction with a
Packit 7cfc04
.IR master:X
Packit 7cfc04
tag.
Packit 7cfc04
Here,
Packit 7cfc04
.IR X
Packit 7cfc04
is the closest dominant peer group under the process's root directory.
Packit 7cfc04
If
Packit 7cfc04
.IR X
Packit 7cfc04
is the immediate master of the mount,
Packit 7cfc04
or if there is no dominant peer group under the same root,
Packit 7cfc04
then only the
Packit 7cfc04
.IR master:X
Packit 7cfc04
field is present and not the
Packit 7cfc04
.IR propagate_from:X
Packit 7cfc04
field.
Packit 7cfc04
For further details, see below.
Packit 7cfc04
.TP
Packit 7cfc04
.IR unbindable
Packit 7cfc04
This is an unbindable mount.
Packit 7cfc04
.PP
Packit 7cfc04
If none of the above tags is present, then this is a private mount.
Packit 7cfc04
.SS MS_SHARED and MS_PRIVATE example
Packit 7cfc04
Suppose that on a terminal in the initial mount namespace,
Packit 7cfc04
we mark one mount point as shared and another as private,
Packit 7cfc04
and then view the mounts in
Packit 7cfc04
.IR /proc/self/mountinfo :
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBmount \-\-make\-shared /mntS\fP
Packit 7cfc04
sh1# \fBmount \-\-make\-private /mntP\fP
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
77 61 8:17 / /mntS rw,relatime shared:1
Packit 7cfc04
83 61 8:15 / /mntP rw,relatime
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
From the
Packit 7cfc04
.IR /proc/self/mountinfo
Packit 7cfc04
output, we see that
Packit 7cfc04
.IR /mntS
Packit 7cfc04
is a shared mount in peer group 1, and that
Packit 7cfc04
.IR /mntP
Packit 7cfc04
has no optional tags, indicating that it is a private mount.
Packit 7cfc04
The first two fields in each record in this file are the unique
Packit 7cfc04
ID for this mount, and the mount ID of the parent mount.
Packit 7cfc04
We can further inspect this file to see that the parent mount point of
Packit 7cfc04
.IR /mntS
Packit 7cfc04
and
Packit 7cfc04
.IR /mntP
Packit 7cfc04
is the root directory,
Packit 7cfc04
.IR / ,
Packit 7cfc04
which is mounted as private:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | awk \(aq$1 == 61\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
61 0 8:2 / / rw,relatime
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
On a second terminal,
Packit 7cfc04
we create a new mount namespace where we run a second shell
Packit 7cfc04
and inspect the mounts:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
$ \fBPS1=\(aqsh2# \(aq sudo unshare \-m \-\-propagation unchanged sh\fP
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
222 145 8:17 / /mntS rw,relatime shared:1
Packit 7cfc04
225 145 8:15 / /mntP rw,relatime
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The new mount namespace received a copy of the initial mount namespace's
Packit 7cfc04
mount points.
Packit 7cfc04
These new mount points maintain the same propagation types,
Packit 7cfc04
but have unique mount IDs.
Packit 7cfc04
(The
Packit 7cfc04
.IR \-\-propagation\ unchanged
Packit 7cfc04
option prevents
Packit 7cfc04
.BR unshare (1)
Packit 7cfc04
from marking all mounts as private when creating a new mount namespace,
Packit 7cfc04
.\" Since util-linux 2.27
Packit 7cfc04
which it does by default.)
Packit 7cfc04
.PP
Packit 7cfc04
In the second terminal, we then create submounts under each of
Packit 7cfc04
.IR /mntS
Packit 7cfc04
and
Packit 7cfc04
.IR /mntP
Packit 7cfc04
and inspect the set-up:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBmkdir /mntS/a\fP
Packit 7cfc04
sh2# \fBmount /dev/sdb6 /mntS/a\fP
Packit 7cfc04
sh2# \fBmkdir /mntP/b\fP
Packit 7cfc04
sh2# \fBmount /dev/sdb7 /mntP/b\fP
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
222 145 8:17 / /mntS rw,relatime shared:1
Packit 7cfc04
225 145 8:15 / /mntP rw,relatime
Packit 7cfc04
178 222 8:22 / /mntS/a rw,relatime shared:2
Packit 7cfc04
230 225 8:23 / /mntP/b rw,relatime
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
From the above, it can be seen that
Packit 7cfc04
.IR /mntS/a
Packit 7cfc04
was created as shared (inheriting this setting from its parent mount) and
Packit 7cfc04
.IR /mntP/b
Packit 7cfc04
was created as a private mount.
Packit 7cfc04
.PP
Packit 7cfc04
Returning to the first terminal and inspecting the set-up,
Packit 7cfc04
we see that the new mount created under the shared mount point
Packit 7cfc04
.IR /mntS
Packit 7cfc04
propagated to its peer mount (in the initial mount namespace),
Packit 7cfc04
but the new mount created under the private mount point
Packit 7cfc04
.IR /mntP
Packit 7cfc04
did not propagate:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
77 61 8:17 / /mntS rw,relatime shared:1
Packit 7cfc04
83 61 8:15 / /mntP rw,relatime
Packit 7cfc04
179 77 8:22 / /mntS/a rw,relatime shared:2
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.\"
Packit 7cfc04
.SS MS_SLAVE example
Packit 7cfc04
Making a mount point a slave allows it to receive propagated
Packit 7cfc04
mount and unmount events from a master shared peer group,
Packit 7cfc04
while preventing it from propagating events to that master.
Packit 7cfc04
This is useful if we want to (say) receive a mount event when
Packit 7cfc04
an optical disk is mounted in the master shared peer group
Packit 7cfc04
(in another mount namespace),
Packit 7cfc04
but want to prevent mount and unmount events under the slave mount
Packit 7cfc04
from having side effects in other namespaces.
Packit 7cfc04
.PP
Packit 7cfc04
We can demonstrate the effect of slaving by first marking
Packit 7cfc04
two mount points as shared in the initial mount namespace:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBmount \-\-make\-shared /mntX\fP
Packit 7cfc04
sh1# \fBmount \-\-make\-shared /mntY\fP
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
132 83 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
133 83 8:22 / /mntY rw,relatime shared:2
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
On a second terminal,
Packit 7cfc04
we create a new mount namespace and inspect the mount points:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBunshare \-m \-\-propagation unchanged sh\fP
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
168 167 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
169 167 8:22 / /mntY rw,relatime shared:2
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
In the new mount namespace, we then mark one of the mount points as a slave:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBmount \-\-make\-slave /mntY\fP
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
168 167 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
169 167 8:22 / /mntY rw,relatime master:2
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
From the above output, we see that
Packit 7cfc04
.IR /mntY
Packit 7cfc04
is now a slave mount that is receiving propagation events from
Packit 7cfc04
the shared peer group with the ID 2.
Packit 7cfc04
.PP
Packit 7cfc04
Continuing in the new namespace, we create submounts under each of
Packit 7cfc04
.IR /mntX
Packit 7cfc04
and
Packit 7cfc04
.IR /mntY :
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBmkdir /mntX/a\fP
Packit 7cfc04
sh2# \fBmount /dev/sda3 /mntX/a\fP
Packit 7cfc04
sh2# \fBmkdir /mntY/b\fP
Packit 7cfc04
sh2# \fBmount /dev/sda5 /mntY/b\fP
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
When we inspect the state of the mount points in the new mount namespace,
Packit 7cfc04
we see that
Packit 7cfc04
.IR /mntX/a
Packit 7cfc04
was created as a new shared mount
Packit 7cfc04
(inheriting the "shared" setting from its parent mount) and
Packit 7cfc04
.IR /mntY/b
Packit 7cfc04
was created as a private mount:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
168 167 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
169 167 8:22 / /mntY rw,relatime master:2
Packit 7cfc04
173 168 8:3 / /mntX/a rw,relatime shared:3
Packit 7cfc04
175 169 8:5 / /mntY/b rw,relatime
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Returning to the first terminal (in the initial mount namespace),
Packit 7cfc04
we see that the mount
Packit 7cfc04
.IR /mntX/a
Packit 7cfc04
propagated to the peer (the shared
Packit 7cfc04
.IR /mntX ),
Packit 7cfc04
but the mount
Packit 7cfc04
.IR /mntY/b
Packit 7cfc04
was not propagated:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
132 83 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
133 83 8:22 / /mntY rw,relatime shared:2
Packit 7cfc04
174 132 8:3 / /mntX/a rw,relatime shared:3
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Now we create a new mount point under
Packit 7cfc04
.IR /mntY
Packit 7cfc04
in the first shell:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh1# \fBmkdir /mntY/c\fP
Packit 7cfc04
sh1# \fBmount /dev/sda1 /mntY/c\fP
Packit 7cfc04
sh1# \fBcat /proc/self/mountinfo | grep '/mnt' | sed 's/ \- .*//'\fP
Packit 7cfc04
132 83 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
133 83 8:22 / /mntY rw,relatime shared:2
Packit 7cfc04
174 132 8:3 / /mntX/a rw,relatime shared:3
Packit 7cfc04
178 133 8:1 / /mntY/c rw,relatime shared:4
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
When we examine the mount points in the second mount namespace,
Packit 7cfc04
we see that in this case the new mount has been propagated
Packit 7cfc04
to the slave mount point,
Packit 7cfc04
and that the new mount is itself a slave mount (to peer group 4):
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
168 167 8:23 / /mntX rw,relatime shared:1
Packit 7cfc04
169 167 8:22 / /mntY rw,relatime master:2
Packit 7cfc04
173 168 8:3 / /mntX/a rw,relatime shared:3
Packit 7cfc04
175 169 8:5 / /mntY/b rw,relatime
Packit 7cfc04
179 169 8:1 / /mntY/c rw,relatime master:4
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.\"
Packit 7cfc04
.SS MS_UNBINDABLE example
Packit 7cfc04
One of the primary purposes of unbindable mounts is to avoid
Packit 7cfc04
the "mount point explosion" problem when repeatedly performing bind mounts
Packit 7cfc04
of a higher-level subtree at a lower-level mount point.
Packit 7cfc04
The problem is illustrated by the following shell session.
Packit 7cfc04
.PP
Packit 7cfc04
Suppose we have a system with the following mount points:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
Packit 7cfc04
/dev/sda1 on /
Packit 7cfc04
/dev/sdb6 on /mntX
Packit 7cfc04
/dev/sdb7 on /mntY
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Suppose furthermore that we wish to recursively bind mount
Packit 7cfc04
the root directory under several users' home directories.
Packit 7cfc04
We do this for the first user, and inspect the mount points:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-rbind / /home/cecilia/\fP
Packit 7cfc04
# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
Packit 7cfc04
/dev/sda1 on /
Packit 7cfc04
/dev/sdb6 on /mntX
Packit 7cfc04
/dev/sdb7 on /mntY
Packit 7cfc04
/dev/sda1 on /home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/cecilia/mntY
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
When we repeat this operation for the second user,
Packit 7cfc04
we start to see the explosion problem:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-rbind / /home/henry\fP
Packit 7cfc04
# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
Packit 7cfc04
/dev/sda1 on /
Packit 7cfc04
/dev/sdb6 on /mntX
Packit 7cfc04
/dev/sdb7 on /mntY
Packit 7cfc04
/dev/sda1 on /home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/cecilia/mntY
Packit 7cfc04
/dev/sda1 on /home/henry
Packit 7cfc04
/dev/sdb6 on /home/henry/mntX
Packit 7cfc04
/dev/sdb7 on /home/henry/mntY
Packit 7cfc04
/dev/sda1 on /home/henry/home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/henry/home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/henry/home/cecilia/mntY
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Under
Packit 7cfc04
.IR /home/henry ,
Packit 7cfc04
we have not only recursively added the
Packit 7cfc04
.IR /mntX
Packit 7cfc04
and
Packit 7cfc04
.IR /mntY
Packit 7cfc04
mounts, but also the recursive mounts of those directories under
Packit 7cfc04
.IR /home/cecilia
Packit 7cfc04
that were created in the previous step.
Packit 7cfc04
Upon repeating the step for a third user,
Packit 7cfc04
it becomes obvious that the explosion is exponential in nature:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-rbind / /home/otto\fP
Packit 7cfc04
# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
Packit 7cfc04
/dev/sda1 on /
Packit 7cfc04
/dev/sdb6 on /mntX
Packit 7cfc04
/dev/sdb7 on /mntY
Packit 7cfc04
/dev/sda1 on /home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/cecilia/mntY
Packit 7cfc04
/dev/sda1 on /home/henry
Packit 7cfc04
/dev/sdb6 on /home/henry/mntX
Packit 7cfc04
/dev/sdb7 on /home/henry/mntY
Packit 7cfc04
/dev/sda1 on /home/henry/home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/henry/home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/henry/home/cecilia/mntY
Packit 7cfc04
/dev/sda1 on /home/otto
Packit 7cfc04
/dev/sdb6 on /home/otto/mntX
Packit 7cfc04
/dev/sdb7 on /home/otto/mntY
Packit 7cfc04
/dev/sda1 on /home/otto/home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/otto/home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/otto/home/cecilia/mntY
Packit 7cfc04
/dev/sda1 on /home/otto/home/henry
Packit 7cfc04
/dev/sdb6 on /home/otto/home/henry/mntX
Packit 7cfc04
/dev/sdb7 on /home/otto/home/henry/mntY
Packit 7cfc04
/dev/sda1 on /home/otto/home/henry/home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/otto/home/henry/home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/otto/home/henry/home/cecilia/mntY
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The mount explosion problem in the above scenario can be avoided
Packit 7cfc04
by making each of the new mounts unbindable.
Packit 7cfc04
The effect of doing this is that recursive mounts of the root
Packit 7cfc04
directory will not replicate the unbindable mounts.
Packit 7cfc04
We make such a mount for the first user:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-rbind \-\-make\-unbindable / /home/cecilia\fP
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Before going further, we show that unbindable mounts are indeed unbindable:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmkdir /mntZ\fP
Packit 7cfc04
# \fBmount \-\-bind /home/cecilia /mntZ\fP
Packit 7cfc04
mount: wrong fs type, bad option, bad superblock on /home/cecilia,
Packit 7cfc04
       missing codepage or helper program, or other error
Packit 7cfc04
Packit 7cfc04
       In some cases useful info is found in syslog \- try
Packit 7cfc04
       dmesg | tail or so.
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Now we create unbindable recursive bind mounts for the other two users:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-rbind \-\-make\-unbindable / /home/henry\fP
Packit 7cfc04
# \fBmount \-\-rbind \-\-make\-unbindable / /home/otto\fP
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Upon examining the list of mount points,
Packit 7cfc04
we see there has been no explosion of mount points,
Packit 7cfc04
because the unbindable mounts were not replicated
Packit 7cfc04
under each user's directory:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
Packit 7cfc04
/dev/sda1 on /
Packit 7cfc04
/dev/sdb6 on /mntX
Packit 7cfc04
/dev/sdb7 on /mntY
Packit 7cfc04
/dev/sda1 on /home/cecilia
Packit 7cfc04
/dev/sdb6 on /home/cecilia/mntX
Packit 7cfc04
/dev/sdb7 on /home/cecilia/mntY
Packit 7cfc04
/dev/sda1 on /home/henry
Packit 7cfc04
/dev/sdb6 on /home/henry/mntX
Packit 7cfc04
/dev/sdb7 on /home/henry/mntY
Packit 7cfc04
/dev/sda1 on /home/otto
Packit 7cfc04
/dev/sdb6 on /home/otto/mntX
Packit 7cfc04
/dev/sdb7 on /home/otto/mntY
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.\"
Packit 7cfc04
.SS Propagation type transitions
Packit 7cfc04
The following table shows the effect that applying a new propagation type
Packit 7cfc04
(i.e.,
Packit 7cfc04
.IR "mount \-\-make\-xxxx")
Packit 7cfc04
has on the existing propagation type of a mount point.
Packit 7cfc04
The rows correspond to existing propagation types,
Packit 7cfc04
and the columns are the new propagation settings.
Packit 7cfc04
For reasons of space, "private" is abbreviated as "priv" and
Packit 7cfc04
"unbindable" as "unbind".
Packit 7cfc04
.TS
Packit 7cfc04
lb2 lb2 lb2 lb2 lb1
Packit 7cfc04
lb l l l l l.
Packit 7cfc04
	make-shared	make-slave	make-priv	make-unbind
Packit 7cfc04
shared	shared	slave/priv [1]	priv	unbind
Packit 7cfc04
slave	slave+shared	slave [2]	priv	unbind
Packit 7cfc04
slave+shared	slave+shared	slave	priv	unbind
Packit 7cfc04
private	shared	priv [2]	priv	unbind
Packit 7cfc04
unbindable	shared	unbind [2]	priv	unbind
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
Note the following details to the table:
Packit 7cfc04
.IP [1] 4
Packit 7cfc04
If a shared mount is the only mount in its peer group,
Packit 7cfc04
making it a slave automatically makes it private.
Packit 7cfc04
.IP [2]
Packit 7cfc04
Slaving a nonshared mount has no effect on the mount.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Bind (MS_BIND) semantics
Packit 7cfc04
Suppose that the following command is performed:
Packit 7cfc04
.PP
Packit 7cfc04
    mount \-\-bind A/a B/b
Packit 7cfc04
.PP
Packit 7cfc04
Here,
Packit 7cfc04
.I A
Packit 7cfc04
is the source mount point,
Packit 7cfc04
.I B
Packit 7cfc04
is the destination mount point,
Packit 7cfc04
.I a
Packit 7cfc04
is a subdirectory path under the mount point
Packit 7cfc04
.IR A ,
Packit 7cfc04
and
Packit 7cfc04
.I b
Packit 7cfc04
is a subdirectory path under the mount point
Packit 7cfc04
.IR B .
Packit 7cfc04
The propagation type of the resulting mount,
Packit 7cfc04
.IR B/b ,
Packit 7cfc04
depends on the propagation types of the mount points
Packit 7cfc04
.IR A
Packit 7cfc04
and
Packit 7cfc04
.IR B ,
Packit 7cfc04
and is summarized in the following table.
Packit 7cfc04
.PP
Packit 7cfc04
.TS
Packit 7cfc04
lb2 lb1 lb2 lb2 lb2 lb0
Packit 7cfc04
lb2 lb1 lb2 lb2 lb2 lb0
Packit 7cfc04
lb lb l l l l l.
Packit 7cfc04
			source(A)
Packit 7cfc04
		shared	private	slave	unbind
Packit 7cfc04
_
Packit 7cfc04
dest(B)	shared    |	shared	shared	slave+shared	invalid
Packit 7cfc04
	nonshared |	shared	private	slave	invalid
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
Note that a recursive bind of a subtree follows the same semantics
Packit 7cfc04
as for a bind operation on each mount in the subtree.
Packit 7cfc04
(Unbindable mounts are automatically pruned at the target mount point.)
Packit 7cfc04
.PP
Packit 7cfc04
For further details, see
Packit 7cfc04
.I Documentation/filesystems/sharedsubtree.txt
Packit 7cfc04
in the kernel source tree.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Move (MS_MOVE) semantics
Packit 7cfc04
Suppose that the following command is performed:
Packit 7cfc04
.PP
Packit 7cfc04
    mount \-\-move A B/b
Packit 7cfc04
.PP
Packit 7cfc04
Here,
Packit 7cfc04
.I A
Packit 7cfc04
is the source mount point,
Packit 7cfc04
.I B
Packit 7cfc04
is the destination mount point, and
Packit 7cfc04
.I b
Packit 7cfc04
is a subdirectory path under the mount point
Packit 7cfc04
.IR B .
Packit 7cfc04
The propagation type of the resulting mount,
Packit 7cfc04
.IR B/b ,
Packit 7cfc04
depends on the propagation types of the mount points
Packit 7cfc04
.IR A
Packit 7cfc04
and
Packit 7cfc04
.IR B ,
Packit 7cfc04
and is summarized in the following table.
Packit 7cfc04
.PP
Packit 7cfc04
.TS
Packit 7cfc04
lb2 lb1 lb2 lb2 lb2 lb0
Packit 7cfc04
lb2 lb1 lb2 lb2 lb2 lb0
Packit 7cfc04
lb lb l l l l l.
Packit 7cfc04
			source(A)
Packit 7cfc04
		shared	private	slave	unbind
Packit 7cfc04
_
Packit 7cfc04
dest(B)	shared    |	shared	shared	slave+shared	invalid
Packit 7cfc04
	nonshared |	shared	private	slave	unbindable
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
Note: moving a mount that resides under a shared mount is invalid.
Packit 7cfc04
.PP
Packit 7cfc04
For further details, see
Packit 7cfc04
.I Documentation/filesystems/sharedsubtree.txt
Packit 7cfc04
in the kernel source tree.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Mount semantics
Packit 7cfc04
Suppose that we use the following command to create a mount point:
Packit 7cfc04
.PP
Packit 7cfc04
    mount device B/b
Packit 7cfc04
.PP
Packit 7cfc04
Here,
Packit 7cfc04
.I B
Packit 7cfc04
is the destination mount point, and
Packit 7cfc04
.I b
Packit 7cfc04
is a subdirectory path under the mount point
Packit 7cfc04
.IR B .
Packit 7cfc04
The propagation type of the resulting mount,
Packit 7cfc04
.IR B/b ,
Packit 7cfc04
follows the same rules as for a bind mount,
Packit 7cfc04
where the propagation type of the source mount
Packit 7cfc04
is considered always to be private.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Unmount semantics
Packit 7cfc04
Suppose that we use the following command to tear down a mount point:
Packit 7cfc04
.PP
Packit 7cfc04
    unmount A
Packit 7cfc04
.PP
Packit 7cfc04
Here,
Packit 7cfc04
.I A
Packit 7cfc04
is a mount point on
Packit 7cfc04
.IR B/b ,
Packit 7cfc04
where
Packit 7cfc04
.I B
Packit 7cfc04
is the parent mount and
Packit 7cfc04
.I b
Packit 7cfc04
is a subdirectory path under the mount point
Packit 7cfc04
.IR B .
Packit 7cfc04
If
Packit 7cfc04
.B B
Packit 7cfc04
is shared, then all most-recently-mounted mounts at
Packit 7cfc04
.I b
Packit 7cfc04
on mounts that receive propagation from mount
Packit 7cfc04
.I B
Packit 7cfc04
and do not have submounts under them are unmounted.
Packit 7cfc04
.\"
Packit 7cfc04
.SS The /proc/[pid]/mountinfo "propagate_from" tag
Packit 7cfc04
The
Packit 7cfc04
.I propagate_from:X
Packit 7cfc04
tag is shown in the optional fields of a
Packit 7cfc04
.IR /proc/[pid]/mountinfo
Packit 7cfc04
record in cases where a process can't see a slave's immediate master
Packit 7cfc04
(i.e., the pathname of the master is not reachable from
Packit 7cfc04
the filesystem root directory)
Packit 7cfc04
and so cannot determine the
Packit 7cfc04
chain of propagation between the mounts it can see.
Packit 7cfc04
.PP
Packit 7cfc04
In the following example, we first create a two-link master-slave chain
Packit 7cfc04
between the mounts
Packit 7cfc04
.IR /mnt ,
Packit 7cfc04
.IR /tmp/etc ,
Packit 7cfc04
and
Packit 7cfc04
.IR /mnt/tmp/etc .
Packit 7cfc04
Then the
Packit 7cfc04
.BR chroot (1)
Packit 7cfc04
command is used to make the
Packit 7cfc04
.IR /tmp/etc
Packit 7cfc04
mount point unreachable from the root directory,
Packit 7cfc04
creating a situation where the master of
Packit 7cfc04
.IR /mnt/tmp/etc
Packit 7cfc04
is not reachable from the (new) root directory of the process.
Packit 7cfc04
.PP
Packit 7cfc04
First, we bind mount the root directory onto
Packit 7cfc04
.IR /mnt
Packit 7cfc04
and then bind mount
Packit 7cfc04
.IR /proc
Packit 7cfc04
at
Packit 7cfc04
.IR /mnt/proc
Packit 7cfc04
so that after the later
Packit 7cfc04
.BR chroot (1)
Packit 7cfc04
the
Packit 7cfc04
.BR proc (5)
Packit 7cfc04
filesystem remains visible at the correct location
Packit 7cfc04
in the chroot-ed environment.
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmkdir \-p /mnt/proc\fP
Packit 7cfc04
# \fBmount \-\-bind / /mnt\fP
Packit 7cfc04
# \fBmount \-\-bind /proc /mnt/proc\fP
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Next, we ensure that the
Packit 7cfc04
.IR /mnt
Packit 7cfc04
mount is a shared mount in a new peer group (with no peers):
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-make\-private /mnt\fP  # Isolate from any previous peer group
Packit 7cfc04
# \fBmount \-\-make\-shared /mnt\fP
Packit 7cfc04
# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
239 61 8:2 / /mnt ... shared:102
Packit 7cfc04
248 239 0:4 / /mnt/proc ... shared:5
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Next, we bind mount
Packit 7cfc04
.IR /mnt/etc
Packit 7cfc04
onto
Packit 7cfc04
.IR /tmp/etc :
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmkdir \-p /tmp/etc\fP
Packit 7cfc04
# \fBmount \-\-bind /mnt/etc /tmp/etc\fP
Packit 7cfc04
# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
239 61 8:2 / /mnt ... shared:102
Packit 7cfc04
248 239 0:4 / /mnt/proc ... shared:5
Packit 7cfc04
267 40 8:2 /etc /tmp/etc ... shared:102
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Initially, these two mount points are in the same peer group,
Packit 7cfc04
but we then make the
Packit 7cfc04
.IR /tmp/etc
Packit 7cfc04
a slave of
Packit 7cfc04
.IR /mnt/etc ,
Packit 7cfc04
and then make
Packit 7cfc04
.IR /tmp/etc
Packit 7cfc04
shared as well,
Packit 7cfc04
so that it can propagate events to the next slave in the chain:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmount \-\-make\-slave /tmp/etc\fP
Packit 7cfc04
# \fBmount \-\-make\-shared /tmp/etc\fP
Packit 7cfc04
# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
239 61 8:2 / /mnt ... shared:102
Packit 7cfc04
248 239 0:4 / /mnt/proc ... shared:5
Packit 7cfc04
267 40 8:2 /etc /tmp/etc ... shared:105 master:102
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Then we bind mount
Packit 7cfc04
.IR /tmp/etc
Packit 7cfc04
onto
Packit 7cfc04
.IR /mnt/tmp/etc .
Packit 7cfc04
Again, the two mount points are initially in the same peer group,
Packit 7cfc04
but we then make
Packit 7cfc04
.IR /mnt/tmp/etc
Packit 7cfc04
a slave of
Packit 7cfc04
.IR /tmp/etc :
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBmkdir \-p /mnt/tmp/etc\fP
Packit 7cfc04
# \fBmount \-\-bind /tmp/etc /mnt/tmp/etc\fP
Packit 7cfc04
# \fBmount \-\-make\-slave /mnt/tmp/etc\fP
Packit 7cfc04
# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
239 61 8:2 / /mnt ... shared:102
Packit 7cfc04
248 239 0:4 / /mnt/proc ... shared:5
Packit 7cfc04
267 40 8:2 /etc /tmp/etc ... shared:105 master:102
Packit 7cfc04
273 239 8:2 /etc /mnt/tmp/etc ... master:105
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
From the above, we see that
Packit 7cfc04
.IR /mnt
Packit 7cfc04
is the master of the slave
Packit 7cfc04
.IR /tmp/etc ,
Packit 7cfc04
which in turn is the master of the slave
Packit 7cfc04
.IR /mnt/tmp/etc .
Packit 7cfc04
.PP
Packit 7cfc04
We then
Packit 7cfc04
.BR chroot (1)
Packit 7cfc04
to the
Packit 7cfc04
.IR /mnt
Packit 7cfc04
directory, which renders the mount with ID 267 unreachable
Packit 7cfc04
from the (new) root directory:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBchroot /mnt\fP
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
When we examine the state of the mounts inside the chroot-ed environment,
Packit 7cfc04
we see the following:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
# \fBcat /proc/self/mountinfo | sed \(aqs/ \- .*//\(aq\fP
Packit 7cfc04
239 61 8:2 / / ... shared:102
Packit 7cfc04
248 239 0:4 / /proc ... shared:5
Packit 7cfc04
273 239 8:2 /etc /tmp/etc ... master:105 propagate_from:102
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Above, we see that the mount with ID 273
Packit 7cfc04
is a slave whose master is the peer group 105.
Packit 7cfc04
The mount point for that master is unreachable, and so a
Packit 7cfc04
.IR propagate_from
Packit 7cfc04
tag is displayed, indicating that the closest dominant peer group
Packit 7cfc04
(i.e., the nearest reachable mount in the slave chain)
Packit 7cfc04
is the peer group with the ID 102 (corresponding to the
Packit 7cfc04
.IR /mnt
Packit 7cfc04
mount point before the
Packit 7cfc04
.BR chroot (1)
Packit 7cfc04
was performed.
Packit 7cfc04
.\"
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
Mount namespaces first appeared in Linux 2.4.19.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
Namespaces are a Linux-specific feature.
Packit 7cfc04
.\"
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The propagation type assigned to a new mount point depends
Packit 7cfc04
on the propagation type of the parent directory.
Packit 7cfc04
If the mount point has a parent (i.e., it is a non-root mount
Packit 7cfc04
point) and the propagation type of the parent is
Packit 7cfc04
.BR MS_SHARED ,
Packit 7cfc04
then the propagation type of the new mount is also
Packit 7cfc04
.BR MS_SHARED .
Packit 7cfc04
Otherwise, the propagation type of the new mount is
Packit 7cfc04
.BR MS_PRIVATE .
Packit 7cfc04
But see also NOTES.
Packit 7cfc04
.PP
Packit 7cfc04
Notwithstanding the fact that the default propagation type
Packit 7cfc04
for new mount points is in many cases
Packit 7cfc04
.BR MS_PRIVATE ,
Packit 7cfc04
.BR MS_SHARED
Packit 7cfc04
is typically more useful.
Packit 7cfc04
For this reason,
Packit 7cfc04
.BR systemd (1)
Packit 7cfc04
automatically remounts all mount points as
Packit 7cfc04
.BR MS_SHARED
Packit 7cfc04
on system startup.
Packit 7cfc04
Thus, on most modern systems, the default propagation type is in practice
Packit 7cfc04
.BR MS_SHARED .
Packit 7cfc04
.PP
Packit 7cfc04
Since, when one uses
Packit 7cfc04
.BR unshare (1)
Packit 7cfc04
to create a mount namespace,
Packit 7cfc04
the goal is commonly to provide full isolation of the mount points
Packit 7cfc04
in the new namespace,
Packit 7cfc04
.BR unshare (1)
Packit 7cfc04
(since
Packit 7cfc04
.IR util-linux
Packit 7cfc04
version 2.27) in turn reverses the step performed by
Packit 7cfc04
.BR systemd (1),
Packit 7cfc04
by making all mount points private in the new namespace.
Packit 7cfc04
That is,
Packit 7cfc04
.BR unshare (1)
Packit 7cfc04
performs the equivalent of the following in the new mount namespace:
Packit 7cfc04
.PP
Packit 7cfc04
    mount \-\-make\-rprivate /
Packit 7cfc04
.PP
Packit 7cfc04
To prevent this, one can use the
Packit 7cfc04
.IR "\-\-propagation\ unchanged"
Packit 7cfc04
option to
Packit 7cfc04
.BR unshare (1).
Packit 7cfc04
.PP
Packit 7cfc04
For a discussion of propagation types when moving mounts
Packit 7cfc04
.RB ( MS_MOVE )
Packit 7cfc04
and creating bind mounts
Packit 7cfc04
.RB ( MS_BIND ),
Packit 7cfc04
see
Packit 7cfc04
.IR Documentation/filesystems/sharedsubtree.txt .
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR unshare (1),
Packit 7cfc04
.BR clone (2),
Packit 7cfc04
.BR mount (2),
Packit 7cfc04
.BR setns (2),
Packit 7cfc04
.BR umount (2),
Packit 7cfc04
.BR unshare (2),
Packit 7cfc04
.BR proc (5),
Packit 7cfc04
.BR namespaces (7),
Packit 7cfc04
.BR user_namespaces (7)
Packit 7cfc04
.PP
Packit 7cfc04
.IR Documentation/filesystems/sharedsubtree.txt
Packit 7cfc04
in the kernel source tree.
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.