]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/mount_namespaces.7
fuse.4: ffix
[thirdparty/man-pages.git] / man7 / mount_namespaces.7
CommitLineData
98c28960
MK
1.\" Copyright (c) 2016 by Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
3.\" %%%LICENSE_START(VERBATIM)
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
12.\"
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\" %%%LICENSE_END
24.\"
25.\"
3df541c0 26.TH MOUNT_NAMESPACES 7 2016-07-17 "Linux" "Linux Programmer's Manual"
98c28960
MK
27.SH NAME
28mount_namespaces \- overview of Linux mount namespaces
29.SH DESCRIPTION
30For an overview of namespaces, see
31.BR namespaces (7).
32
33Mount namespaces provide isolation of the list of mount points seen
34by the processes in each namespace instance.
35Thus, the processes in each of the mount namespace instances
36will see distinct single-directory hierarchies.
37
38The views provided by the
39.IR /proc/[pid]/mounts ,
40.IR /proc/[pid]/mountinfo ,
41and
42.IR /proc/[pid]/mountstats
43files (all described in
44.BR proc (5))
45correspond to the mount namespace in which the process with the PID
46.IR [pid]
47resides.
48(All of the processes that reside in the same mount namespace
49will see the same view in these files.)
50
51When a process creates a new mount namespace using
52.BR clone (2)
53or
54.BR unshare (2)
55with the
56.BR CLONE_NEWNS
57flag, the mount point list for the new namespace is a
58.I copy
59of the caller's mount point list.
60Subsequent modifications to the mount point list
61.RB ( mount (2)
62and
63.BR umount (2))
64in either mount namespace will not (by default) affect the
65mount point list seen in the other namespace
66(but see the following discussion of shared subtrees).
67.\"
4bfc2026
MK
68.\" ============================================================
69.\"
70.SS Restrictions on mount namespaces
71Note the following points with respect to mount namespaces:
72.IP * 3
73A mount namespace has an owner user namespace.
74A mount namespace whose owner user namespace is different from
75the owner user namespace of its parent mount namespace is
76considered a less privileged mount namespace.
77.IP *
78When creating a less privileged mount namespace,
79shared mounts are reduced to slave mounts.
4f74d996 80(Shared and slave mounts are discussed below.)
4bfc2026
MK
81This ensures that mappings performed in less
82privileged mount namespaces will not propagate to more privileged
83mount namespaces.
84.IP *
85.\" FIXME .
86.\" What does "come as a single unit from more privileged mount" mean?
87Mounts that come as a single unit from more privileged mount are
88locked together and may not be separated in a less privileged mount
89namespace.
90(The
91.BR unshare (2)
92.B CLONE_NEWNS
93operation brings across all of the mounts from the original
94mount namespace as a single unit,
95and recursive mounts that propagate between
96mount namespaces propagate as a single unit.)
97.IP *
98The
99.BR mount (2)
100flags
101.BR MS_RDONLY ,
102.BR MS_NOSUID ,
103.BR MS_NOEXEC ,
104and the "atime" flags
105.RB ( MS_NOATIME ,
106.BR MS_NODIRATIME ,
107.BR MS_RELATIME )
108settings become locked
109.\" commit 9566d6742852c527bf5af38af5cbb878dad75705
110.\" Author: Eric W. Biederman <ebiederm@xmission.com>
111.\" Date: Mon Jul 28 17:26:07 2014 -0700
112.\"
113.\" mnt: Correct permission checks in do_remount
114.\"
115when propagated from a more privileged to
116a less privileged mount namespace,
117and may not be changed in the less privileged mount namespace.
118.IP *
119.\" (As of 3.18-rc1 (in Al Viro's 2014-08-30 vfs.git#for-next tree))
120A file or directory that is a mount point in one namespace that is not
121a mount point in another namespace, may be renamed, unlinked, or removed
122.RB ( rmdir (2))
123in the mount namespace in which it is not a mount point
124(subject to the usual permission checks).
125.IP
126Previously, attempting to unlink, rename, or remove a file or directory
127that was a mount point in another mount namespace would result in the error
128.BR EBUSY .
129That behavior had technical problems of enforcement (e.g., for NFS)
130and permitted denial-of-service attacks against more privileged users.
131(i.e., preventing individual files from being updated
132by bind mounting on top of them).
133.\"
98c28960
MK
134.SH SHARED SUBTREES
135After the implementation of mount namespaces was completed,
136experience showed that the isolation that they provided was,
137in some cases, too great.
138For example, in order to make a newly loaded optical disk
139available in all mount namespaces,
140a mount operation was required in each namespace.
141For this use case, and others,
142the shared subtree feature was introduced in Linux 2.6.15.
143This feature allows for automatic, controlled propagation of mount and unmount
144.I events
145between namespaces
146(or, more precisely, between the members of a
147.IR "peer group"
148that are propagating events to one another).
149
150Each mount point is marked (via
151.BR mount (2))
152as having one of the following
153.IR "propagation types" :
154.TP
155.BR MS_SHARED
156This mount point shares events with members of a peer group.
157Mount and unmount events immediately under this mount point will propagate
d9cdf357 158to the other mount points that are members of the peer group.
98c28960
MK
159.I Propagation
160here means that the same mount or unmount will automatically occur
161under all of the other mount points in the peer group.
162Conversely, mount and unmount events that take place under
d9cdf357 163peer mount points will propagate to this mount point.
98c28960
MK
164.TP
165.BR MS_PRIVATE
166This mount point is private; it does not have a peer group.
167Mount and unmount events do not propagate into or out of this mount point.
168This is the default propagation type for newly created mount points
169(but see NOTES).
170.TP
171.BR MS_SLAVE
172Mount and unmount events propagate into this mount point from
173a (master) shared peer group.
174Mount and unmount events under this mount point do not propagate to any peer.
175
176Note that a mount point can be the slave of another peer group
177while at the same time sharing mount and unmount events
178with a peer group of which it is a member.
179(More precisely, one peer group can be the slave of another peer group.)
180.TP
181.BR MS_UNBINDABLE
182This is like a private mount,
183and in addition this mount can't be bind mounted.
184Attempts to bind mount this mount
185.RB ( mount (2)
186with the
187.BR MS_BIND
188flag) will fail.
189
190When a recursive bind mount
191.RB ( mount (2)
192with the
193.BR MS_BIND
194and
195.BR MS_REC
196flags) is performed on a directory subtree,
197any bind mounts within the subtree are automatically pruned
198(i.e., not replicated)
199when replicating that subtree to produce the target subtree.
200.PP
201The propagation type is a per-mount-point setting;
202some mount points may be marked as shared
203(with each shared mount point being a member of a distinct peer group),
204while others are private
205(or slaved or unbindable).
206
207Note that a mount's propagation type determines whether
208mounts and unmounts of mount points
209.I "immediately under"
210the mount point are propagated.
211Thus, the propagation type does not affect propagation of events for
212grandchildren and further removed descendant mount points.
213What happens if the mount point itself is unmounted is determined by
214the propagation type that is in effect for the
215.I parent
216of the mount point.
217
218Members are added to a
219.IR "peer group"
220when a mount point is marked as shared and either:
221.IP * 3
222the mount point is replicated during the creation of a new mount namespace; or
223.IP *
224a new bind mount is created from the mount point.
225.PP
226In both of these cases, the new mount point joins the peer group
227of which the existing mount point is a member.
228A mount ceases to be a member of a peer group when either
229the mount is explicitly unmounted,
230or when the mount is implicitly unmounted because a mount namespace is removed
231(because it has no more member processes).
232
233The propagation type of the mount points in a mount namespace
234can be discovered via the "optional fields" exposed in
235.IR /proc/[pid]/mountinfo .
236(See
237.BR proc (5)
238for details of this file.)
239The following tags can appear in the optional fields
240for a record in that file:
241.TP
242.I shared:X
243This mount point is shared in peer group
244.IR X .
d9cdf357 245Each peer group has a unique ID that is automatically
98c28960
MK
246generated by the kernel,
247and all mount points in the same peer group will show the same ID.
d9cdf357
MK
248(These IDs are assigned starting from the value 1,
249and may be recycled when a peer group ceases to have any members.)
98c28960
MK
250.TP
251.I master:X
252This mount is a slave to shared peer group
253.IR X .
254.TP
255.IR propagate_from:X " (since Linux 2.6.26)"
256.\" commit 97e7e0f71d6d948c25f11f0a33878d9356d9579e
257This mount is a slave and receives propagation from shared peer group
258.IR X .
259This tag will always appear in conjunction with a
260.IR master:X
261tag.
262Here,
263.IR X
264is the closest dominant peer group under the process's root directory.
265If
266.IR X
267is the immediate master of the mount,
268or if there is no dominant peer group under the same root,
269then only the
270.IR master:X
271field is present and not the
272.IR propagate_from:X
273field.
e2109196 274For further details, see below.
98c28960
MK
275.TP
276.IR unbindable
277This is an unbindable mount.
278.PP
279If none of the above tags is present, then this is a private mount.
280.SS MS_SHARED and MS_PRIVATE example
281Suppose that on a terminal in the initial mount namespace,
282we mark one mount point as shared and another as private,
283and then view the mounts in
284.IR /proc/self/mountinfo :
285
286.nf
287.in +4n
d9cdf357
MK
288sh1# \fBmount \-\-make\-shared /mntS\fP
289sh1# \fBmount \-\-make\-private /mntP\fP
f481726d 290sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
d9cdf357
MK
29177 61 8:17 / /mntS rw,relatime shared:1
29283 61 8:15 / /mntP rw,relatime
98c28960
MK
293.in
294.fi
295
296From the
297.IR /proc/self/mountinfo
298output, we see that
d9cdf357 299.IR /mntS
98c28960 300is a shared mount in peer group 1, and that
d9cdf357 301.IR /mntP
98c28960
MK
302has no optional tags, indicating that it is a private mount.
303The first two fields in each record in this file are the unique
304ID for this mount, and the mount ID of the parent mount.
305We can further inspect this file to see that the parent mount point of
d9cdf357 306.IR /mntS
98c28960 307and
d9cdf357 308.IR /mntP
98c28960
MK
309is the root directory,
310.IR / ,
311which is mounted as private:
312
313.nf
314.in +4n
315sh1# \fBcat /proc/self/mountinfo | awk \(aq$1 == 61\(aq | sed \(aqs/ \- .*//\(aq\fP
31661 0 8:2 / / rw,relatime
317.in
318.fi
319
320On a second terminal,
321we create a new mount namespace where we run a second shell
322and inspect the mounts:
323
324.nf
325.in +4n
326$ \fBPS1=\(aqsh2# \(aq sudo unshare \-m \-\-propagation unchanged sh\fP
f481726d 327sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
d9cdf357
MK
328222 145 8:17 / /mntS rw,relatime shared:1
329225 145 8:15 / /mntP rw,relatime
98c28960
MK
330.in
331.fi
332
333The new mount namespace received a copy of the initial mount namespace's
334mount points.
335These new mount points maintain the same propagation types,
336but have unique mount IDs.
337(The
338.IR \-\-propagation\ unchanged
339option prevents
340.BR unshare (1)
341from marking all mounts as private when creating a new mount namespace,
342.\" Since util-linux 2.27
343which it does by default.)
344
345In the second terminal, we then create submounts under each of
d9cdf357 346.IR /mntS
98c28960 347and
d9cdf357 348.IR /mntP
98c28960
MK
349and inspect the set-up:
350
351.nf
352.in +4n
d9cdf357
MK
353sh2# \fBmkdir /mntS/a\fP
354sh2# \fBmount /dev/sdb6 /mntS/a\fP
355sh2# \fBmkdir /mntP/b\fP
356sh2# \fBmount /dev/sdb7 /mntP/b\fP
f481726d 357sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
d9cdf357
MK
358222 145 8:17 / /mntS rw,relatime shared:1
359225 145 8:15 / /mntP rw,relatime
360178 222 8:22 / /mntS/a rw,relatime shared:2
361230 225 8:23 / /mntP/b rw,relatime
98c28960
MK
362.in
363.fi
364
365From the above, it can be seen that
d9cdf357 366.IR /mntS/a
98c28960 367was created as shared (inheriting this setting from its parent mount) and
d9cdf357 368.IR /mntP/b
98c28960
MK
369was created as a private mount.
370
371Returning to the first terminal and inspecting the set-up,
372we see that the new mount created under the shared mount point
d9cdf357 373.IR /mntS
98c28960
MK
374propagated to its peer mount (in the initial mount namespace),
375but the new mount created under the private mount point
d9cdf357 376.IR /mntP
98c28960
MK
377did not propagate:
378
379.nf
380.in +4n
f481726d 381sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
d9cdf357
MK
38277 61 8:17 / /mntS rw,relatime shared:1
38383 61 8:15 / /mntP rw,relatime
384179 77 8:22 / /mntS/a rw,relatime shared:2
98c28960
MK
385.in
386.fi
387.\"
388.SS MS_SLAVE example
389Making a mount point a slave allows it to receive propagated
390mount and unmount events from a master shared peer group,
d9cdf357 391while preventing it from propagating events to that master.
98c28960
MK
392This is useful if we want to (say) receive a mount event when
393an optical disk is mounted in the master shared peer group
394(in another mount namespace),
395but want to prevent mount and unmount events under the slave mount
396from having side effects in other namespaces.
397
398We can demonstrate the effect of slaving by first marking
399two mount points as shared in the initial mount namespace:
400
401.nf
402.in +4n
403sh1# \fBmount \-\-make\-shared /mntX\fP
404sh1# \fBmount \-\-make\-shared /mntY\fP
405sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
406132 83 8:23 / /mntX rw,relatime shared:1
407133 83 8:22 / /mntY rw,relatime shared:2
408.in
409.fi
410
411On a second terminal,
412we create a new mount namespace and inspect the mount points:
413
414.nf
415.in +4n
416sh2# \fBunshare \-m \-\-propagation unchanged sh\fP
417sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
418168 167 8:23 / /mntX rw,relatime shared:1
419169 167 8:22 / /mntY rw,relatime shared:2
420.in
421.fi
422
423In the new mount namespace, we then mark one of the mount points as a slave:
424
425.nf
426.in +4n
427sh2# \fBmount \-\-make\-slave /mntY\fP
428sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
429168 167 8:23 / /mntX rw,relatime shared:1
430169 167 8:22 / /mntY rw,relatime master:2
431.in
432.fi
433
434From the above output, we see that
435.IR /mntY
436is now a slave mount that is receiving propagation events from
437the shared peer group with the ID 2.
438
439Continuing in the new namespace, we create submounts under each of
440.IR /mntX
441and
442.IR /mntY :
443
444.nf
445.in +4n
d9cdf357
MK
446sh2# \fBmkdir /mntX/a\fP
447sh2# \fBmount /dev/sda3 /mntX/a\fP
448sh2# \fBmkdir /mntY/b\fP
449sh2# \fBmount /dev/sda5 /mntY/b\fP
98c28960
MK
450.in
451.fi
452
453When we inspect the state of the mount points in the new mount namespace,
454we see that
d9cdf357 455.IR /mntX/a
98c28960
MK
456was created as a new shared mount
457(inheriting the "shared" setting from its parent mount) and
d9cdf357 458.IR /mntY/b
98c28960
MK
459was created as a private mount:
460
461.nf
462.in +4n
463sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
464168 167 8:23 / /mntX rw,relatime shared:1
465169 167 8:22 / /mntY rw,relatime master:2
d9cdf357
MK
466173 168 8:3 / /mntX/a rw,relatime shared:3
467175 169 8:5 / /mntY/b rw,relatime
98c28960
MK
468.in
469.fi
470
471Returning to the first terminal (in the initial mount namespace),
472we see that the mount
d9cdf357 473.IR /mntX/a
98c28960
MK
474propagated to the peer (the shared
475.IR /mntX ),
476but the mount
d9cdf357 477.IR /mntY/b
98c28960
MK
478was not propagated:
479
480.nf
481.in +4n
482sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
483132 83 8:23 / /mntX rw,relatime shared:1
484133 83 8:22 / /mntY rw,relatime shared:2
d9cdf357 485174 132 8:3 / /mntX/a rw,relatime shared:3
98c28960
MK
486.in
487.fi
488
489Now we create a new mount point under
490.IR /mntY
491in the first shell:
492
493.nf
494.in +4n
d9cdf357
MK
495sh1# \fBmkdir /mntY/c\fP
496sh1# \fBmount /dev/sda1 /mntY/c\fP
98c28960
MK
497sh1# \fBcat /proc/self/mountinfo | grep '/mnt' | sed 's/ \- .*//'\fP
498132 83 8:23 / /mntX rw,relatime shared:1
499133 83 8:22 / /mntY rw,relatime shared:2
d9cdf357
MK
500174 132 8:3 / /mntX/a rw,relatime shared:3
501178 133 8:1 / /mntY/c rw,relatime shared:4
98c28960
MK
502.in
503.fi
504
505When we examine the mount points in the second mount namespace,
506we see that in this case the new mount has been propagated
507to the slave mount point,
508and that the new mount is itself a slave mount (to peer group 4):
509
510.nf
511.in +4n
512sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
513168 167 8:23 / /mntX rw,relatime shared:1
514169 167 8:22 / /mntY rw,relatime master:2
d9cdf357
MK
515173 168 8:3 / /mntX/a rw,relatime shared:3
516175 169 8:5 / /mntY/b rw,relatime
517179 169 8:1 / /mntY/c rw,relatime master:4
98c28960
MK
518.in
519.fi
520.\"
521.SS MS_UNBINDABLE example
522One of the primary purposes of unbindable mounts is to avoid
523the "mount point explosion" problem when repeatedly performing bind mounts
524of a higher-level subtree at a lower-level mount point.
525The problem is illustrated by the following shell session.
526
527Suppose we have a system with the following mount points:
528
529.nf
530.in +4n
531# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
532/dev/sda1 on /
533/dev/sdb6 on /mntX
534/dev/sdb7 on /mntY
535.in
536.fi
537
538Suppose furthermore that we wish to recursively bind mount
539the root directory under several users' home directories.
540We do this for the first user, and inspect the mount points:
541
542.nf
543.in +4n
544# \fBmount \-\-rbind / /home/cecilia/\fP
545# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
546/dev/sda1 on /
547/dev/sdb6 on /mntX
548/dev/sdb7 on /mntY
549/dev/sda1 on /home/cecilia
550/dev/sdb6 on /home/cecilia/mntX
551/dev/sdb7 on /home/cecilia/mntY
552.in
553.fi
554
555When we repeat this operation for the second user,
556we start to see the explosion problem:
557
558.nf
559.in +4n
560# \fBmount \-\-rbind / /home/henry\fP
561# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
562/dev/sda1 on /
563/dev/sdb6 on /mntX
564/dev/sdb7 on /mntY
565/dev/sda1 on /home/cecilia
566/dev/sdb6 on /home/cecilia/mntX
567/dev/sdb7 on /home/cecilia/mntY
568/dev/sda1 on /home/henry
569/dev/sdb6 on /home/henry/mntX
570/dev/sdb7 on /home/henry/mntY
571/dev/sda1 on /home/henry/home/cecilia
572/dev/sdb6 on /home/henry/home/cecilia/mntX
573/dev/sdb7 on /home/henry/home/cecilia/mntY
574.in
575.fi
576
577Under
578.IR /home/henry ,
579we have not only recursively added the
580.IR /mntX
581and
582.IR /mntY
583mounts, but also the recursive mounts of those directories under
584.IR /home/cecilia
585that were created in the previous step.
586Upon repeating the step for a third user,
587it becomes obvious that the explosion is exponential in nature:
588
589.nf
590.in +4n
591# \fBmount \-\-rbind / /home/otto\fP
592# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
593/dev/sda1 on /
594/dev/sdb6 on /mntX
595/dev/sdb7 on /mntY
596/dev/sda1 on /home/cecilia
597/dev/sdb6 on /home/cecilia/mntX
598/dev/sdb7 on /home/cecilia/mntY
599/dev/sda1 on /home/henry
600/dev/sdb6 on /home/henry/mntX
601/dev/sdb7 on /home/henry/mntY
602/dev/sda1 on /home/henry/home/cecilia
603/dev/sdb6 on /home/henry/home/cecilia/mntX
604/dev/sdb7 on /home/henry/home/cecilia/mntY
605/dev/sda1 on /home/otto
606/dev/sdb6 on /home/otto/mntX
607/dev/sdb7 on /home/otto/mntY
608/dev/sda1 on /home/otto/home/cecilia
609/dev/sdb6 on /home/otto/home/cecilia/mntX
610/dev/sdb7 on /home/otto/home/cecilia/mntY
611/dev/sda1 on /home/otto/home/henry
612/dev/sdb6 on /home/otto/home/henry/mntX
613/dev/sdb7 on /home/otto/home/henry/mntY
614/dev/sda1 on /home/otto/home/henry/home/cecilia
615/dev/sdb6 on /home/otto/home/henry/home/cecilia/mntX
616/dev/sdb7 on /home/otto/home/henry/home/cecilia/mntY
617.in
618.fi
619
620The mount explosion problem in the above scenario can be avoided
621by making each of the new mounts unbindable.
622The effect of doing this is that recursive mounts of the root
623directory will not replicate the unbindable mounts.
624We make such a mount for the first user:
625
626.nf
627.in +4n
628# \fBmount \-\-rbind \-\-make\-unbindable / /home/cecilia\fP
629.in
630.fi
631
632Before going further, we show that unbindable mounts are indeed unbindable:
633
634.nf
635.in +4n
636# \fBmkdir /mntZ\fP
637# \fBmount \-\-bind /home/cecilia /mntZ\fP
638mount: wrong fs type, bad option, bad superblock on /home/cecilia,
639 missing codepage or helper program, or other error
640
641 In some cases useful info is found in syslog \- try
642 dmesg | tail or so.
643.in
644.fi
645
646Now we create unbindable recursive bind mounts for the other two users:
647
648.nf
649.in +4n
650# \fBmount \-\-rbind \-\-make\-unbindable / /home/henry\fP
651# \fBmount \-\-rbind \-\-make\-unbindable / /home/otto\fP
652.in
653.fi
654
655Upon examining the list of mount points,
656we see there has been no explosion of mount points,
657because the unbindable mounts were not replicated
658under each user's directory:
659
660.nf
661.in +4n
662# \fBmount | awk \(aq{print $1, $2, $3}\(aq\fP
663/dev/sda1 on /
664/dev/sdb6 on /mntX
665/dev/sdb7 on /mntY
666/dev/sda1 on /home/cecilia
667/dev/sdb6 on /home/cecilia/mntX
668/dev/sdb7 on /home/cecilia/mntY
669/dev/sda1 on /home/henry
670/dev/sdb6 on /home/henry/mntX
671/dev/sdb7 on /home/henry/mntY
672/dev/sda1 on /home/otto
673/dev/sdb6 on /home/otto/mntX
674/dev/sdb7 on /home/otto/mntY
675.in
676.fi
677.\"
678.SS Propagation type transitions
679The following table shows the effect that applying a new propagation type
680(i.e.,
681.IR "mount \-\-make\-xxxx")
682has on the existing propagation type of a mount point.
683The rows correspond to existing propagation types,
684and the columns are the new propagation settings.
685For reasons of space, "private" is abbreviated as "priv" and
686"unbindable" as "unbind".
687.TS
688lb2 lb2 lb2 lb2 lb1
689lb l l l l l.
690 make-shared make-slave make-priv make-unbind
691shared shared slave/priv [1] priv unbind
692slave slave+shared slave [2] priv unbind
693slave+shared slave+shared slave priv unbind
694private shared priv [2] priv unbind
695unbindable shared unbind [2] priv unbind
696.TE
697
698Note the following details to the table:
699.IP [1] 4
700If a shared mount is the only mount in its peer group,
701making it a slave automatically makes it private.
702.IP [2]
703Slaving a nonshared mount has no effect on the mount.
704.\"
705.SS Bind (MS_BIND) semantics
706Suppose that the following command is performed:
707
708 mount \-\-bind A/a B/b
709
710Here,
711.I A
712is the source mount point,
713.I B
714is the destination mount point,
715.I a
716is a subdirectory path under the mount point
717.IR A ,
718and
719.I b
720is a subdirectory path under the mount point
721.IR B .
722The propagation type of the resulting mount,
723.IR B/b ,
724depends on the propagation types of the mount points
725.IR A
726and
727.IR B ,
728and is summarized in the following table.
729
730.TS
731lb2 lb1 lb2 lb2 lb2 lb0
732lb2 lb1 lb2 lb2 lb2 lb0
733lb lb l l l l l.
734 source(A)
735 shared private slave unbind
736_
737dest(B) shared | shared shared slave+shared invalid
738 nonshared | shared private slave invalid
739.TE
740
741Note that a recursive bind of a subtree follows the same semantics
742as for a bind operation on each mount in the subtree.
743(Unbindable mounts are automatically pruned at the target mount point.)
744
745For further details, see
1481407a 746.I Documentation/filesystems/sharedsubtree.txt
98c28960
MK
747in the kernel source tree.
748.\"
749.SS Move (MS_MOVE) semantics
750Suppose that the following command is performed:
751
752 mount \-\-move A B/b
753
754Here,
755.I A
756is the source mount point,
757.I B
758is the destination mount point, and
759.I b
760is a subdirectory path under the mount point
761.IR B .
762The propagation type of the resulting mount,
763.IR B/b ,
764depends on the propagation types of the mount points
765.IR A
766and
767.IR B ,
768and is summarized in the following table.
769
770.TS
771lb2 lb1 lb2 lb2 lb2 lb0
772lb2 lb1 lb2 lb2 lb2 lb0
773lb lb l l l l l.
774 source(A)
775 shared private slave unbind
776_
777dest(B) shared | shared shared slave+shared invalid
778 nonshared | shared private slave unbindable
779.TE
780
781Note: moving a mount that resides under a shared mount is invalid.
782
783For further details, see
1481407a 784.I Documentation/filesystems/sharedsubtree.txt
98c28960
MK
785in the kernel source tree.
786.\"
787.SS Mount semantics
788Suppose that we use the following command to create a mount point:
789
790 mount device B/b
791
792Here,
793.I B
794is the destination mount point, and
795.I b
796is a subdirectory path under the mount point
797.IR B .
798The propagation type of the resulting mount,
799.IR B/b ,
800follows the same rules as for a bind mount,
801where the propagation type of the source mount
802is considered always to be private.
803.\"
804.SS Unmount semantics
805Suppose that we use the following command to tear down a mount point:
806
807 unmount A
808
809Here,
810.I A
811is a mount point on
812.IR B/b ,
813where
814.I B
815is the parent mount and
816.I b
817is a subdirectory path under the mount point
818.IR B .
819If
820.B B
821is shared, then all most-recently-mounted mounts at
822.I b
823on mounts that receive propagation from mount
824.I B
825and do not have submounts under them are unmounted.
826.\"
e2109196
MK
827.SS The /proc/[pid]/mountinfo "propagate_from" tag
828The
829.I propagate_from:X
830tag is shown in the optional fields of a
831.IR /proc/[pid]/mountinfo
832record in cases where a process can't see a slave's immediate master
833(i.e., the pathname of the master is not reachable from
834the filesystem root directory)
835and so cannot determine the
836chain of propagation between the mounts it can see.
837
838In the following example, we first create a two-link master-slave chain
839between the mounts
840.IR /mnt ,
841.IR /tmp/etc ,
842and
843.IR /mnt/tmp/etc .
844Then the
845.BR chroot (1)
846command is used to make the
847.IR /tmp/etc
848mount point unreachable from the root directory,
849creating a situation where the master of
850.IR /mnt/tmp/etc
851is not reachable from the (new) root directory of the process.
852
853First, we bind mount the root directory onto
854.IR /mnt
855and then bind mount
856.IR /proc
857at
858.IR /mnt/proc
859so that after the later
860.BR chroot (1)
861the
862.BR proc (5)
863filesystem remains visible at the correct location
864in the chroot-ed environment.
865
866.nf
867.in +4n
868# \fBmkdir \-p /mnt/proc\fP
869# \fBmount \-\-bind / /mnt\fP
870# \fBmount \-\-bind /proc /mnt/proc\fP
871.in
872.fi
873
874Next, we ensure that the
875.IR /mnt
876mount is a shared mount in a new peer group (with no peers):
877
878.nf
879.in +4n
880# \fBmount \-\-make\-private /mnt\fP # Isolate from any previous peer group
881# \fBmount \-\-make\-shared /mnt\fP
882# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP
883239 61 8:2 / /mnt ... shared:102
884248 239 0:4 / /mnt/proc ... shared:5
885.in
886.fi
887
888Next, we bind mount
889.IR /mnt/etc
890onto
891.IR /tmp/etc :
892
893.nf
894.in +4n
895# \fBmkdir \-p /tmp/etc\fP
896# \fBmount \-\-bind /mnt/etc /tmp/etc\fP
897# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
898239 61 8:2 / /mnt ... shared:102
899248 239 0:4 / /mnt/proc ... shared:5
900267 40 8:2 /etc /tmp/etc ... shared:102
901.in
902.fi
903
904Initially, these two mount points are in the same peer group,
905but we then make the
906.IR /tmp/etc
907a slave of
908.IR /mnt/etc ,
909and then make
910.IR /tmp/etc
911shared as well,
912so that it can propagate events to the next slave in the chain:
913
914.nf
915.in +4n
916# \fBmount \-\-make\-slave /tmp/etc\fP
917# \fBmount \-\-make\-shared /tmp/etc\fP
918# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
919239 61 8:2 / /mnt ... shared:102
920248 239 0:4 / /mnt/proc ... shared:5
921267 40 8:2 /etc /tmp/etc ... shared:105 master:102
922.in
923.fi
924
925Then we bind mount
926.IR /tmp/etc
927onto
928.IR /mnt/tmp/etc .
929Again, the two mount points are initially in the same peer group,
930but we then make
931.IR /mnt/tmp/etc
932a slave of
933.IR /tmp/etc :
934
935.nf
936.in +4n
937# \fBmkdir \-p /mnt/tmp/etc\fP
938# \fBmount \-\-bind /tmp/etc /mnt/tmp/etc\fP
939# \fBmount \-\-make\-slave /mnt/tmp/etc\fP
940# \fBcat /proc/self/mountinfo | egrep \(aq/mnt|/tmp/\(aq | sed \(aqs/ \- .*//\(aq\fP
941239 61 8:2 / /mnt ... shared:102
942248 239 0:4 / /mnt/proc ... shared:5
943267 40 8:2 /etc /tmp/etc ... shared:105 master:102
944273 239 8:2 /etc /mnt/tmp/etc ... master:105
945
946.in
947.fi
948From the above, we see that
949.IR /mnt
950is the master of the slave
951.IR /tmp/etc ,
952which in turn is the master of the slave
953.IR /mnt/tmp/etc .
954
955We then
956.BR chroot (1)
957to the
958.IR /mnt
959directory, which renders the mount with ID 267 unreachable
960from the (new) root directory:
961
962.nf
963.in +4n
964# \fBchroot /mnt\fP
965.in
966.fi
967
968When we examine the state of the mounts inside the chroot-ed environment,
969we see the following:
970
971.nf
972.in +4n
973# \fBcat /proc/self/mountinfo | sed \(aqs/ \- .*//\(aq\fP
974239 61 8:2 / / ... shared:102
975248 239 0:4 / /proc ... shared:5
976273 239 8:2 /etc /tmp/etc ... master:105 propagate_from:102
977.in
978.fi
979
980Above, we see that the mount with ID 273
981is a slave whose master is the peer group 105.
982The mount point for that master is unreachable, and so a
983.IR propagate_from
984tag is displayed, indicating that the closest dominant peer group
985(i.e., the nearest reachable mount in the slave chain)
986is the peer group with the ID 102 (corresponding to the
987.IR /mnt
988mount point before the
989.BR chroot (1)
990was performed.
991.\"
c307aecd
MK
992.SH VERSIONS
993Mount namespaces first appeared in Linux 2.4.19.
994.SH CONFORMING TO
995Namespaces are a Linux-specific feature.
996.\"
98c28960
MK
997.SH NOTES
998The kernel default propagation type for mount points is
999.BR MS_PRIVATE .
1000However,
1001.BR MS_SHARED
1002is typically more commonly required, and for this reason,
1003.BR systemd (1)
1004automatically remounts all mount points as
1005.BR MS_SHARED
1006on system startup.
1007
1008Since, when one uses
1009.BR unshare (1)
1010to create a mount namespace,
1011the goal is commonly to provide full isolation of the mount points
1012in the new namespace,
1013.BR unshare (1)
1014(since
1015.IR util-linux
1016version 2.27) in turn reverses the step performed by
1017.BR systemd (1),
1018by making all mount points private in the new namespace.
1019That is,
1020.BR unshare (1)
1021performs the equivalent of the following in the new mount namespace:
1022
1023 mount \-\-make\-rprivate /
1024
1025To prevent this, one can use the
1026.IR "\-\-propagation\ unchanged"
1027option to
1028.BR unshare (1).
98c28960
MK
1029.SH SEE ALSO
1030.BR unshare (1),
1031.BR clone (2),
1032.BR mount (2),
1033.BR setns (2),
1034.BR umount (2),
1035.BR unshare (2),
1036.BR proc (5),
466247eb
MK
1037.BR namespaces (7),
1038.BR user_namespaces (7)
98c28960
MK
1039
1040.IR Documentation/filesystems/sharedsubtree.txt
1041in the kernel source tree.