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