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