]>
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 | .\" | |
3df541c0 | 26 | .TH MOUNT_NAMESPACES 7 2016-07-17 "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). | |
32 | ||
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. | |
37 | ||
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.) | |
50 | ||
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). | |
149 | ||
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. | |
168 | This is the default propagation type for newly created mount points | |
169 | (but see NOTES). | |
170 | .TP | |
171 | .BR MS_SLAVE | |
172 | Mount and unmount events propagate into this mount point from | |
173 | a (master) shared peer group. | |
174 | Mount and unmount events under this mount point do not propagate to any peer. | |
175 | ||
176 | Note that a mount point can be the slave of another peer group | |
177 | while at the same time sharing mount and unmount events | |
178 | with 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 | |
182 | This is like a private mount, | |
183 | and in addition this mount can't be bind mounted. | |
184 | Attempts to bind mount this mount | |
185 | .RB ( mount (2) | |
186 | with the | |
187 | .BR MS_BIND | |
188 | flag) will fail. | |
189 | ||
190 | When a recursive bind mount | |
191 | .RB ( mount (2) | |
192 | with the | |
193 | .BR MS_BIND | |
194 | and | |
195 | .BR MS_REC | |
196 | flags) is performed on a directory subtree, | |
197 | any bind mounts within the subtree are automatically pruned | |
198 | (i.e., not replicated) | |
199 | when replicating that subtree to produce the target subtree. | |
200 | .PP | |
201 | The propagation type is a per-mount-point setting; | |
202 | some mount points may be marked as shared | |
203 | (with each shared mount point being a member of a distinct peer group), | |
204 | while others are private | |
205 | (or slaved or unbindable). | |
206 | ||
207 | Note that a mount's propagation type determines whether | |
208 | mounts and unmounts of mount points | |
209 | .I "immediately under" | |
210 | the mount point are propagated. | |
211 | Thus, the propagation type does not affect propagation of events for | |
212 | grandchildren and further removed descendant mount points. | |
213 | What happens if the mount point itself is unmounted is determined by | |
214 | the propagation type that is in effect for the | |
215 | .I parent | |
216 | of the mount point. | |
217 | ||
218 | Members are added to a | |
219 | .IR "peer group" | |
220 | when a mount point is marked as shared and either: | |
221 | .IP * 3 | |
222 | the mount point is replicated during the creation of a new mount namespace; or | |
223 | .IP * | |
224 | a new bind mount is created from the mount point. | |
225 | .PP | |
226 | In both of these cases, the new mount point joins the peer group | |
227 | of which the existing mount point is a member. | |
228 | A mount ceases to be a member of a peer group when either | |
229 | the mount is explicitly unmounted, | |
230 | or when the mount is implicitly unmounted because a mount namespace is removed | |
231 | (because it has no more member processes). | |
232 | ||
233 | The propagation type of the mount points in a mount namespace | |
234 | can be discovered via the "optional fields" exposed in | |
235 | .IR /proc/[pid]/mountinfo . | |
236 | (See | |
237 | .BR proc (5) | |
238 | for details of this file.) | |
239 | The following tags can appear in the optional fields | |
240 | for a record in that file: | |
241 | .TP | |
242 | .I shared:X | |
243 | This mount point is shared in peer group | |
244 | .IR X . | |
d9cdf357 | 245 | Each peer group has a unique ID that is automatically |
98c28960 MK |
246 | generated by the kernel, |
247 | and 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, |
249 | and may be recycled when a peer group ceases to have any members.) | |
98c28960 MK |
250 | .TP |
251 | .I master:X | |
252 | This 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 | |
257 | This mount is a slave and receives propagation from shared peer group | |
258 | .IR X . | |
259 | This tag will always appear in conjunction with a | |
260 | .IR master:X | |
261 | tag. | |
262 | Here, | |
263 | .IR X | |
264 | is the closest dominant peer group under the process's root directory. | |
265 | If | |
266 | .IR X | |
267 | is the immediate master of the mount, | |
268 | or if there is no dominant peer group under the same root, | |
269 | then only the | |
270 | .IR master:X | |
271 | field is present and not the | |
272 | .IR propagate_from:X | |
273 | field. | |
e2109196 | 274 | For further details, see below. |
98c28960 MK |
275 | .TP |
276 | .IR unbindable | |
277 | This is an unbindable mount. | |
278 | .PP | |
279 | If none of the above tags is present, then this is a private mount. | |
280 | .SS MS_SHARED and MS_PRIVATE example | |
281 | Suppose that on a terminal in the initial mount namespace, | |
282 | we mark one mount point as shared and another as private, | |
283 | and then view the mounts in | |
284 | .IR /proc/self/mountinfo : | |
285 | ||
286 | .nf | |
287 | .in +4n | |
d9cdf357 MK |
288 | sh1# \fBmount \-\-make\-shared /mntS\fP |
289 | sh1# \fBmount \-\-make\-private /mntP\fP | |
f481726d | 290 | sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP |
d9cdf357 MK |
291 | 77 61 8:17 / /mntS rw,relatime shared:1 |
292 | 83 61 8:15 / /mntP rw,relatime | |
98c28960 MK |
293 | .in |
294 | .fi | |
295 | ||
296 | From the | |
297 | .IR /proc/self/mountinfo | |
298 | output, we see that | |
d9cdf357 | 299 | .IR /mntS |
98c28960 | 300 | is a shared mount in peer group 1, and that |
d9cdf357 | 301 | .IR /mntP |
98c28960 MK |
302 | has no optional tags, indicating that it is a private mount. |
303 | The first two fields in each record in this file are the unique | |
304 | ID for this mount, and the mount ID of the parent mount. | |
305 | We can further inspect this file to see that the parent mount point of | |
d9cdf357 | 306 | .IR /mntS |
98c28960 | 307 | and |
d9cdf357 | 308 | .IR /mntP |
98c28960 MK |
309 | is the root directory, |
310 | .IR / , | |
311 | which is mounted as private: | |
312 | ||
313 | .nf | |
314 | .in +4n | |
315 | sh1# \fBcat /proc/self/mountinfo | awk \(aq$1 == 61\(aq | sed \(aqs/ \- .*//\(aq\fP | |
316 | 61 0 8:2 / / rw,relatime | |
317 | .in | |
318 | .fi | |
319 | ||
320 | On a second terminal, | |
321 | we create a new mount namespace where we run a second shell | |
322 | and inspect the mounts: | |
323 | ||
324 | .nf | |
325 | .in +4n | |
326 | $ \fBPS1=\(aqsh2# \(aq sudo unshare \-m \-\-propagation unchanged sh\fP | |
f481726d | 327 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP |
d9cdf357 MK |
328 | 222 145 8:17 / /mntS rw,relatime shared:1 |
329 | 225 145 8:15 / /mntP rw,relatime | |
98c28960 MK |
330 | .in |
331 | .fi | |
332 | ||
333 | The new mount namespace received a copy of the initial mount namespace's | |
334 | mount points. | |
335 | These new mount points maintain the same propagation types, | |
336 | but have unique mount IDs. | |
337 | (The | |
338 | .IR \-\-propagation\ unchanged | |
339 | option prevents | |
340 | .BR unshare (1) | |
341 | from marking all mounts as private when creating a new mount namespace, | |
342 | .\" Since util-linux 2.27 | |
343 | which it does by default.) | |
344 | ||
345 | In the second terminal, we then create submounts under each of | |
d9cdf357 | 346 | .IR /mntS |
98c28960 | 347 | and |
d9cdf357 | 348 | .IR /mntP |
98c28960 MK |
349 | and inspect the set-up: |
350 | ||
351 | .nf | |
352 | .in +4n | |
d9cdf357 MK |
353 | sh2# \fBmkdir /mntS/a\fP |
354 | sh2# \fBmount /dev/sdb6 /mntS/a\fP | |
355 | sh2# \fBmkdir /mntP/b\fP | |
356 | sh2# \fBmount /dev/sdb7 /mntP/b\fP | |
f481726d | 357 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP |
d9cdf357 MK |
358 | 222 145 8:17 / /mntS rw,relatime shared:1 |
359 | 225 145 8:15 / /mntP rw,relatime | |
360 | 178 222 8:22 / /mntS/a rw,relatime shared:2 | |
361 | 230 225 8:23 / /mntP/b rw,relatime | |
98c28960 MK |
362 | .in |
363 | .fi | |
364 | ||
365 | From the above, it can be seen that | |
d9cdf357 | 366 | .IR /mntS/a |
98c28960 | 367 | was created as shared (inheriting this setting from its parent mount) and |
d9cdf357 | 368 | .IR /mntP/b |
98c28960 MK |
369 | was created as a private mount. |
370 | ||
371 | Returning to the first terminal and inspecting the set-up, | |
372 | we see that the new mount created under the shared mount point | |
d9cdf357 | 373 | .IR /mntS |
98c28960 MK |
374 | propagated to its peer mount (in the initial mount namespace), |
375 | but the new mount created under the private mount point | |
d9cdf357 | 376 | .IR /mntP |
98c28960 MK |
377 | did not propagate: |
378 | ||
379 | .nf | |
380 | .in +4n | |
f481726d | 381 | sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP |
d9cdf357 MK |
382 | 77 61 8:17 / /mntS rw,relatime shared:1 |
383 | 83 61 8:15 / /mntP rw,relatime | |
384 | 179 77 8:22 / /mntS/a rw,relatime shared:2 | |
98c28960 MK |
385 | .in |
386 | .fi | |
387 | .\" | |
388 | .SS MS_SLAVE example | |
389 | Making a mount point a slave allows it to receive propagated | |
390 | mount and unmount events from a master shared peer group, | |
d9cdf357 | 391 | while preventing it from propagating events to that master. |
98c28960 MK |
392 | This is useful if we want to (say) receive a mount event when |
393 | an optical disk is mounted in the master shared peer group | |
394 | (in another mount namespace), | |
395 | but want to prevent mount and unmount events under the slave mount | |
396 | from having side effects in other namespaces. | |
397 | ||
398 | We can demonstrate the effect of slaving by first marking | |
399 | two mount points as shared in the initial mount namespace: | |
400 | ||
401 | .nf | |
402 | .in +4n | |
403 | sh1# \fBmount \-\-make\-shared /mntX\fP | |
404 | sh1# \fBmount \-\-make\-shared /mntY\fP | |
405 | sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
406 | 132 83 8:23 / /mntX rw,relatime shared:1 | |
407 | 133 83 8:22 / /mntY rw,relatime shared:2 | |
408 | .in | |
409 | .fi | |
410 | ||
411 | On a second terminal, | |
412 | we create a new mount namespace and inspect the mount points: | |
413 | ||
414 | .nf | |
415 | .in +4n | |
416 | sh2# \fBunshare \-m \-\-propagation unchanged sh\fP | |
417 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
418 | 168 167 8:23 / /mntX rw,relatime shared:1 | |
419 | 169 167 8:22 / /mntY rw,relatime shared:2 | |
420 | .in | |
421 | .fi | |
422 | ||
423 | In the new mount namespace, we then mark one of the mount points as a slave: | |
424 | ||
425 | .nf | |
426 | .in +4n | |
427 | sh2# \fBmount \-\-make\-slave /mntY\fP | |
428 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
429 | 168 167 8:23 / /mntX rw,relatime shared:1 | |
430 | 169 167 8:22 / /mntY rw,relatime master:2 | |
431 | .in | |
432 | .fi | |
433 | ||
434 | From the above output, we see that | |
435 | .IR /mntY | |
436 | is now a slave mount that is receiving propagation events from | |
437 | the shared peer group with the ID 2. | |
438 | ||
439 | Continuing in the new namespace, we create submounts under each of | |
440 | .IR /mntX | |
441 | and | |
442 | .IR /mntY : | |
443 | ||
444 | .nf | |
445 | .in +4n | |
d9cdf357 MK |
446 | sh2# \fBmkdir /mntX/a\fP |
447 | sh2# \fBmount /dev/sda3 /mntX/a\fP | |
448 | sh2# \fBmkdir /mntY/b\fP | |
449 | sh2# \fBmount /dev/sda5 /mntY/b\fP | |
98c28960 MK |
450 | .in |
451 | .fi | |
452 | ||
453 | When we inspect the state of the mount points in the new mount namespace, | |
454 | we see that | |
d9cdf357 | 455 | .IR /mntX/a |
98c28960 MK |
456 | was created as a new shared mount |
457 | (inheriting the "shared" setting from its parent mount) and | |
d9cdf357 | 458 | .IR /mntY/b |
98c28960 MK |
459 | was created as a private mount: |
460 | ||
461 | .nf | |
462 | .in +4n | |
463 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
464 | 168 167 8:23 / /mntX rw,relatime shared:1 | |
465 | 169 167 8:22 / /mntY rw,relatime master:2 | |
d9cdf357 MK |
466 | 173 168 8:3 / /mntX/a rw,relatime shared:3 |
467 | 175 169 8:5 / /mntY/b rw,relatime | |
98c28960 MK |
468 | .in |
469 | .fi | |
470 | ||
471 | Returning to the first terminal (in the initial mount namespace), | |
472 | we see that the mount | |
d9cdf357 | 473 | .IR /mntX/a |
98c28960 MK |
474 | propagated to the peer (the shared |
475 | .IR /mntX ), | |
476 | but the mount | |
d9cdf357 | 477 | .IR /mntY/b |
98c28960 MK |
478 | was not propagated: |
479 | ||
480 | .nf | |
481 | .in +4n | |
482 | sh1# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
483 | 132 83 8:23 / /mntX rw,relatime shared:1 | |
484 | 133 83 8:22 / /mntY rw,relatime shared:2 | |
d9cdf357 | 485 | 174 132 8:3 / /mntX/a rw,relatime shared:3 |
98c28960 MK |
486 | .in |
487 | .fi | |
488 | ||
489 | Now we create a new mount point under | |
490 | .IR /mntY | |
491 | in the first shell: | |
492 | ||
493 | .nf | |
494 | .in +4n | |
d9cdf357 MK |
495 | sh1# \fBmkdir /mntY/c\fP |
496 | sh1# \fBmount /dev/sda1 /mntY/c\fP | |
98c28960 MK |
497 | sh1# \fBcat /proc/self/mountinfo | grep '/mnt' | sed 's/ \- .*//'\fP |
498 | 132 83 8:23 / /mntX rw,relatime shared:1 | |
499 | 133 83 8:22 / /mntY rw,relatime shared:2 | |
d9cdf357 MK |
500 | 174 132 8:3 / /mntX/a rw,relatime shared:3 |
501 | 178 133 8:1 / /mntY/c rw,relatime shared:4 | |
98c28960 MK |
502 | .in |
503 | .fi | |
504 | ||
505 | When we examine the mount points in the second mount namespace, | |
506 | we see that in this case the new mount has been propagated | |
507 | to the slave mount point, | |
508 | and that the new mount is itself a slave mount (to peer group 4): | |
509 | ||
510 | .nf | |
511 | .in +4n | |
512 | sh2# \fBcat /proc/self/mountinfo | grep \(aq/mnt\(aq | sed \(aqs/ \- .*//\(aq\fP | |
513 | 168 167 8:23 / /mntX rw,relatime shared:1 | |
514 | 169 167 8:22 / /mntY rw,relatime master:2 | |
d9cdf357 MK |
515 | 173 168 8:3 / /mntX/a rw,relatime shared:3 |
516 | 175 169 8:5 / /mntY/b rw,relatime | |
517 | 179 169 8:1 / /mntY/c rw,relatime master:4 | |
98c28960 MK |
518 | .in |
519 | .fi | |
520 | .\" | |
521 | .SS MS_UNBINDABLE example | |
522 | One of the primary purposes of unbindable mounts is to avoid | |
523 | the "mount point explosion" problem when repeatedly performing bind mounts | |
524 | of a higher-level subtree at a lower-level mount point. | |
525 | The problem is illustrated by the following shell session. | |
526 | ||
527 | Suppose 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 | ||
538 | Suppose furthermore that we wish to recursively bind mount | |
539 | the root directory under several users' home directories. | |
540 | We 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 | ||
555 | When we repeat this operation for the second user, | |
556 | we 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 | ||
577 | Under | |
578 | .IR /home/henry , | |
579 | we have not only recursively added the | |
580 | .IR /mntX | |
581 | and | |
582 | .IR /mntY | |
583 | mounts, but also the recursive mounts of those directories under | |
584 | .IR /home/cecilia | |
585 | that were created in the previous step. | |
586 | Upon repeating the step for a third user, | |
587 | it 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 | ||
620 | The mount explosion problem in the above scenario can be avoided | |
621 | by making each of the new mounts unbindable. | |
622 | The effect of doing this is that recursive mounts of the root | |
623 | directory will not replicate the unbindable mounts. | |
624 | We 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 | ||
632 | Before 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 | |
638 | mount: 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 | ||
646 | Now 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 | ||
655 | Upon examining the list of mount points, | |
656 | we see there has been no explosion of mount points, | |
657 | because the unbindable mounts were not replicated | |
658 | under 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 | |
679 | The following table shows the effect that applying a new propagation type | |
680 | (i.e., | |
681 | .IR "mount \-\-make\-xxxx") | |
682 | has on the existing propagation type of a mount point. | |
683 | The rows correspond to existing propagation types, | |
684 | and the columns are the new propagation settings. | |
685 | For reasons of space, "private" is abbreviated as "priv" and | |
686 | "unbindable" as "unbind". | |
687 | .TS | |
688 | lb2 lb2 lb2 lb2 lb1 | |
689 | lb l l l l l. | |
690 | make-shared make-slave make-priv make-unbind | |
691 | shared shared slave/priv [1] priv unbind | |
692 | slave slave+shared slave [2] priv unbind | |
693 | slave+shared slave+shared slave priv unbind | |
694 | private shared priv [2] priv unbind | |
695 | unbindable shared unbind [2] priv unbind | |
696 | .TE | |
697 | ||
698 | Note the following details to the table: | |
699 | .IP [1] 4 | |
700 | If a shared mount is the only mount in its peer group, | |
701 | making it a slave automatically makes it private. | |
702 | .IP [2] | |
703 | Slaving a nonshared mount has no effect on the mount. | |
704 | .\" | |
705 | .SS Bind (MS_BIND) semantics | |
706 | Suppose that the following command is performed: | |
707 | ||
708 | mount \-\-bind A/a B/b | |
709 | ||
710 | Here, | |
711 | .I A | |
712 | is the source mount point, | |
713 | .I B | |
714 | is the destination mount point, | |
715 | .I a | |
716 | is a subdirectory path under the mount point | |
717 | .IR A , | |
718 | and | |
719 | .I b | |
720 | is a subdirectory path under the mount point | |
721 | .IR B . | |
722 | The propagation type of the resulting mount, | |
723 | .IR B/b , | |
724 | depends on the propagation types of the mount points | |
725 | .IR A | |
726 | and | |
727 | .IR B , | |
728 | and is summarized in the following table. | |
729 | ||
730 | .TS | |
731 | lb2 lb1 lb2 lb2 lb2 lb0 | |
732 | lb2 lb1 lb2 lb2 lb2 lb0 | |
733 | lb lb l l l l l. | |
734 | source(A) | |
735 | shared private slave unbind | |
736 | _ | |
737 | dest(B) shared | shared shared slave+shared invalid | |
738 | nonshared | shared private slave invalid | |
739 | .TE | |
740 | ||
741 | Note that a recursive bind of a subtree follows the same semantics | |
742 | as for a bind operation on each mount in the subtree. | |
743 | (Unbindable mounts are automatically pruned at the target mount point.) | |
744 | ||
745 | For further details, see | |
1481407a | 746 | .I Documentation/filesystems/sharedsubtree.txt |
98c28960 MK |
747 | in the kernel source tree. |
748 | .\" | |
749 | .SS Move (MS_MOVE) semantics | |
750 | Suppose that the following command is performed: | |
751 | ||
752 | mount \-\-move A B/b | |
753 | ||
754 | Here, | |
755 | .I A | |
756 | is the source mount point, | |
757 | .I B | |
758 | is the destination mount point, and | |
759 | .I b | |
760 | is a subdirectory path under the mount point | |
761 | .IR B . | |
762 | The propagation type of the resulting mount, | |
763 | .IR B/b , | |
764 | depends on the propagation types of the mount points | |
765 | .IR A | |
766 | and | |
767 | .IR B , | |
768 | and is summarized in the following table. | |
769 | ||
770 | .TS | |
771 | lb2 lb1 lb2 lb2 lb2 lb0 | |
772 | lb2 lb1 lb2 lb2 lb2 lb0 | |
773 | lb lb l l l l l. | |
774 | source(A) | |
775 | shared private slave unbind | |
776 | _ | |
777 | dest(B) shared | shared shared slave+shared invalid | |
778 | nonshared | shared private slave unbindable | |
779 | .TE | |
780 | ||
781 | Note: moving a mount that resides under a shared mount is invalid. | |
782 | ||
783 | For further details, see | |
1481407a | 784 | .I Documentation/filesystems/sharedsubtree.txt |
98c28960 MK |
785 | in the kernel source tree. |
786 | .\" | |
787 | .SS Mount semantics | |
788 | Suppose that we use the following command to create a mount point: | |
789 | ||
790 | mount device B/b | |
791 | ||
792 | Here, | |
793 | .I B | |
794 | is the destination mount point, and | |
795 | .I b | |
796 | is a subdirectory path under the mount point | |
797 | .IR B . | |
798 | The propagation type of the resulting mount, | |
799 | .IR B/b , | |
800 | follows the same rules as for a bind mount, | |
801 | where the propagation type of the source mount | |
802 | is considered always to be private. | |
803 | .\" | |
804 | .SS Unmount semantics | |
805 | Suppose that we use the following command to tear down a mount point: | |
806 | ||
807 | unmount A | |
808 | ||
809 | Here, | |
810 | .I A | |
811 | is a mount point on | |
812 | .IR B/b , | |
813 | where | |
814 | .I B | |
815 | is the parent mount and | |
816 | .I b | |
817 | is a subdirectory path under the mount point | |
818 | .IR B . | |
819 | If | |
820 | .B B | |
821 | is shared, then all most-recently-mounted mounts at | |
822 | .I b | |
823 | on mounts that receive propagation from mount | |
824 | .I B | |
825 | and do not have submounts under them are unmounted. | |
826 | .\" | |
e2109196 MK |
827 | .SS The /proc/[pid]/mountinfo "propagate_from" tag |
828 | The | |
829 | .I propagate_from:X | |
830 | tag is shown in the optional fields of a | |
831 | .IR /proc/[pid]/mountinfo | |
832 | record 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 | |
834 | the filesystem root directory) | |
835 | and so cannot determine the | |
836 | chain of propagation between the mounts it can see. | |
837 | ||
838 | In the following example, we first create a two-link master-slave chain | |
839 | between the mounts | |
840 | .IR /mnt , | |
841 | .IR /tmp/etc , | |
842 | and | |
843 | .IR /mnt/tmp/etc . | |
844 | Then the | |
845 | .BR chroot (1) | |
846 | command is used to make the | |
847 | .IR /tmp/etc | |
848 | mount point unreachable from the root directory, | |
849 | creating a situation where the master of | |
850 | .IR /mnt/tmp/etc | |
851 | is not reachable from the (new) root directory of the process. | |
852 | ||
853 | First, we bind mount the root directory onto | |
854 | .IR /mnt | |
855 | and then bind mount | |
856 | .IR /proc | |
857 | at | |
858 | .IR /mnt/proc | |
859 | so that after the later | |
860 | .BR chroot (1) | |
861 | the | |
862 | .BR proc (5) | |
863 | filesystem remains visible at the correct location | |
864 | in 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 | ||
874 | Next, we ensure that the | |
875 | .IR /mnt | |
876 | mount 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 | |
883 | 239 61 8:2 / /mnt ... shared:102 | |
884 | 248 239 0:4 / /mnt/proc ... shared:5 | |
885 | .in | |
886 | .fi | |
887 | ||
888 | Next, we bind mount | |
889 | .IR /mnt/etc | |
890 | onto | |
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 | |
898 | 239 61 8:2 / /mnt ... shared:102 | |
899 | 248 239 0:4 / /mnt/proc ... shared:5 | |
900 | 267 40 8:2 /etc /tmp/etc ... shared:102 | |
901 | .in | |
902 | .fi | |
903 | ||
904 | Initially, these two mount points are in the same peer group, | |
905 | but we then make the | |
906 | .IR /tmp/etc | |
907 | a slave of | |
908 | .IR /mnt/etc , | |
909 | and then make | |
910 | .IR /tmp/etc | |
911 | shared as well, | |
912 | so 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 | |
919 | 239 61 8:2 / /mnt ... shared:102 | |
920 | 248 239 0:4 / /mnt/proc ... shared:5 | |
921 | 267 40 8:2 /etc /tmp/etc ... shared:105 master:102 | |
922 | .in | |
923 | .fi | |
924 | ||
925 | Then we bind mount | |
926 | .IR /tmp/etc | |
927 | onto | |
928 | .IR /mnt/tmp/etc . | |
929 | Again, the two mount points are initially in the same peer group, | |
930 | but we then make | |
931 | .IR /mnt/tmp/etc | |
932 | a 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 | |
941 | 239 61 8:2 / /mnt ... shared:102 | |
942 | 248 239 0:4 / /mnt/proc ... shared:5 | |
943 | 267 40 8:2 /etc /tmp/etc ... shared:105 master:102 | |
944 | 273 239 8:2 /etc /mnt/tmp/etc ... master:105 | |
945 | ||
946 | .in | |
947 | .fi | |
948 | From the above, we see that | |
949 | .IR /mnt | |
950 | is the master of the slave | |
951 | .IR /tmp/etc , | |
952 | which in turn is the master of the slave | |
953 | .IR /mnt/tmp/etc . | |
954 | ||
955 | We then | |
956 | .BR chroot (1) | |
957 | to the | |
958 | .IR /mnt | |
959 | directory, which renders the mount with ID 267 unreachable | |
960 | from the (new) root directory: | |
961 | ||
962 | .nf | |
963 | .in +4n | |
964 | # \fBchroot /mnt\fP | |
965 | .in | |
966 | .fi | |
967 | ||
968 | When we examine the state of the mounts inside the chroot-ed environment, | |
969 | we see the following: | |
970 | ||
971 | .nf | |
972 | .in +4n | |
973 | # \fBcat /proc/self/mountinfo | sed \(aqs/ \- .*//\(aq\fP | |
974 | 239 61 8:2 / / ... shared:102 | |
975 | 248 239 0:4 / /proc ... shared:5 | |
976 | 273 239 8:2 /etc /tmp/etc ... master:105 propagate_from:102 | |
977 | .in | |
978 | .fi | |
979 | ||
980 | Above, we see that the mount with ID 273 | |
981 | is a slave whose master is the peer group 105. | |
982 | The mount point for that master is unreachable, and so a | |
983 | .IR propagate_from | |
984 | tag is displayed, indicating that the closest dominant peer group | |
985 | (i.e., the nearest reachable mount in the slave chain) | |
986 | is the peer group with the ID 102 (corresponding to the | |
987 | .IR /mnt | |
988 | mount point before the | |
989 | .BR chroot (1) | |
990 | was performed. | |
991 | .\" | |
c307aecd MK |
992 | .SH VERSIONS |
993 | Mount namespaces first appeared in Linux 2.4.19. | |
994 | .SH CONFORMING TO | |
995 | Namespaces are a Linux-specific feature. | |
996 | .\" | |
98c28960 MK |
997 | .SH NOTES |
998 | The kernel default propagation type for mount points is | |
999 | .BR MS_PRIVATE . | |
1000 | However, | |
1001 | .BR MS_SHARED | |
1002 | is typically more commonly required, and for this reason, | |
1003 | .BR systemd (1) | |
1004 | automatically remounts all mount points as | |
1005 | .BR MS_SHARED | |
1006 | on system startup. | |
1007 | ||
1008 | Since, when one uses | |
1009 | .BR unshare (1) | |
1010 | to create a mount namespace, | |
1011 | the goal is commonly to provide full isolation of the mount points | |
1012 | in the new namespace, | |
1013 | .BR unshare (1) | |
1014 | (since | |
1015 | .IR util-linux | |
1016 | version 2.27) in turn reverses the step performed by | |
1017 | .BR systemd (1), | |
1018 | by making all mount points private in the new namespace. | |
1019 | That is, | |
1020 | .BR unshare (1) | |
1021 | performs the equivalent of the following in the new mount namespace: | |
1022 | ||
1023 | mount \-\-make\-rprivate / | |
1024 | ||
1025 | To prevent this, one can use the | |
1026 | .IR "\-\-propagation\ unchanged" | |
1027 | option 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 | |
1041 | in the kernel source tree. |