namespaces.7: ffix
[man-pages.git] / man2 / mount.2
blob3a8eb560e459b9e8fd59c1364fe7c9b3f55e5a36
1 .\" Copyright (C) 1993 Rickard E. Faith <faith@cs.unc.edu>
2 .\" and Copyright (C) 1994 Andries E. Brouwer <aeb@cwi.nl>
3 .\" and Copyright (C) 2002, 2005, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1996-11-04 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2001-10-13 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\"     Added note on historical behavior of MS_NOSUID
30 .\" Modified 2002-05-16 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .\"     Extensive changes and additions
32 .\" Modified 2002-05-27 by aeb
33 .\" Modified 2002-06-11 by Michael Kerrisk <mtk.manpages@gmail.com>
34 .\"     Enhanced descriptions of MS_MOVE, MS_BIND, and MS_REMOUNT
35 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" 2005-05-18, mtk, Added MNT_EXPIRE, plus a few other tidy-ups.
37 .\" 2008-10-06, mtk: move umount*() material into separate umount.2 page.
38 .\" 2008-10-06, mtk: Add discussion of namespaces.
39 .\"
40 .TH MOUNT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
41 .SH NAME
42 mount \- mount filesystem
43 .SH SYNOPSIS
44 .nf
45 .B "#include <sys/mount.h>"
46 .PP
47 .BI "int mount(const char *" source ", const char *" target ,
48 .BI "          const char *" filesystemtype ", unsigned long " mountflags ,
49 .BI "          const void *" data );
50 .fi
51 .SH DESCRIPTION
52 .BR mount ()
53 attaches the filesystem specified by
54 .I source
55 (which is often a pathname referring to a device,
56 but can also be the pathname of a directory or file,
57 or a dummy string) to the location (a directory or file)
58 specified by the pathname in
59 .IR target .
60 .PP
61 Appropriate privilege (Linux: the
62 .B CAP_SYS_ADMIN
63 capability) is required to mount filesystems.
64 .PP
65 Values for the
66 .I filesystemtype
67 argument supported by the kernel are listed in
68 .I /proc/filesystems
69 (e.g., "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse",
70 "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660").
71 Further types may become available when the appropriate modules
72 are loaded.
73 .PP
74 The
75 .I data
76 argument is interpreted by the different filesystems.
77 Typically it is a string of comma-separated options
78 understood by this filesystem.
79 See
80 .BR mount (8)
81 for details of the options available for each filesystem type.
82 This argument may be specified as NULL, if there are no options.
83 .PP
84 A call to
85 .BR mount ()
86 performs one of a number of general types of operation,
87 depending on the bits specified in
88 .IR mountflags .
89 The choice of which operation to perform is determined by
90 testing the bits set in
91 .IR mountflags ,
92 with the tests being conducted in the order listed here:
93 .IP * 3
94 Remount an existing mount:
95 .IR mountflags
96 includes
97 .BR MS_REMOUNT .
98 .IP *
99 Create a bind mount:
100 .IR mountflags
101 includes
102 .BR MS_BIND .
103 .IP *
104 Change the propagation type of an existing mount:
105 .IR mountflags
106 includes one of
107 .BR MS_SHARED ,
108 .BR MS_PRIVATE ,
109 .BR MS_SLAVE ,
111 .BR MS_UNBINDABLE .
112 .IP *
113 Move an existing mount to a new location:
114 .IR mountflags
115 includes
116 .BR MS_MOVE .
117 .IP *
118 Create a new mount:
119 .IR mountflags
120 includes none of the above flags.
122 Each of these operations is detailed later in this page.
123 Further flags may be specified in
124 .IR mountflags
125 to modify the behavior of
126 .BR mount (),
127 as described below.
129 .SS Additional mount flags
130 The list below describes the additional flags that can be specified in
131 .IR mountflags .
132 Note that some operation types ignore some or all of these flags,
133 as described later in this page.
135 .\" FIXME 2.6.25 Added MS_I_VERSION, which needs to be documented.
136 .\" commit 7a224228ed79d587ece2304869000aad1b8e97dd
137 .\" (This is a per-superblock flag)
140 .BR MS_DIRSYNC " (since Linux 2.5.19)"
141 Make directory changes on this filesystem synchronous.
142 (This property can be obtained for individual directories
143 or subtrees using
144 .BR chattr (1).)
146 .BR MS_LAZYTIME " (since Linux 4.0)"
147 .\" commit 0ae45f63d4ef8d8eeec49c7d8b44a1775fff13e8
148 .\" commit fe032c422c5ba562ba9c2d316f55e258e03259c6
149 .\" commit a26f49926da938f47561f386be56a83dd37a496d
150 Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
151 by maintaining these changes only in memory.
152 The on-disk timestamps are updated only when:
154 .IP (a) 4
155 the inode needs to be updated for some change unrelated to file timestamps;
156 .IP (b)
157 the application employs
158 .BR fsync (2),
159 .BR syncfs (2),
161 .BR sync (2);
162 .IP (c)
163 an undeleted inode is evicted from memory; or
164 .IP (d)
165 more than 24 hours have passed since the inode was written to disk.
168 This mount option significantly reduces writes
169 needed to update the inode's timestamps, especially mtime and atime.
170 However, in the event of a system crash, the atime and mtime fields
171 on disk might be out of date by up to 24 hours.
173 Examples of workloads where this option could be of significant benefit
174 include frequent random writes to preallocated files,
175 as well as cases where the
176 .B MS_STRICTATIME
177 mount option is also enabled.
178 (The advantage of combining
179 .BR MS_STRICTATIME
181 .BR MS_LAZYTIME
182 is that
183 .BR stat (2)
184 will return the correctly updated atime, but the atime updates
185 will be flushed to disk only in the cases listed above.)
187 .B MS_MANDLOCK
188 Permit mandatory locking on files in this filesystem.
189 (Mandatory locking must still be enabled on a per-file basis,
190 as described in
191 .BR fcntl (2).)
192 Since Linux 4.5,
193 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
194 this mount option requires the
195 .B CAP_SYS_ADMIN
196 capability and a kernel configured with the
197 .B CONFIG_MANDATORY_FILE_LOCKING
198 option.
200 .B MS_NOATIME
201 Do not update access times for (all types of) files on this filesystem.
203 .B MS_NODEV
204 Do not allow access to devices (special files) on this filesystem.
206 .B MS_NODIRATIME
207 Do not update access times for directories on this filesystem.
208 This flag provides a subset of the functionality provided by
209 .BR MS_NOATIME ;
210 that is,
211 .BR MS_NOATIME
212 implies
213 .BR MS_NODIRATIME .
215 .B MS_NOEXEC
216 Do not allow programs to be executed from this filesystem.
217 .\" (Possibly useful for a filesystem that contains non-Linux executables.
218 .\" Often used as a security feature, e.g., to make sure that restricted
219 .\" users cannot execute files uploaded using ftp or so.)
221 .B MS_NOSUID
222 Do not honor set-user-ID and set-group-ID bits or file capabilities
223 when executing programs from this filesystem.
224 In addition, SELinux domain
225 transitions require the permission
226 .IR nosuid_transition ,
227 which in turn needs
228 also the policy capability
229 .IR nnp_nosuid_transition .
230 .\" (This is a security feature to prevent users executing set-user-ID and
231 .\" set-group-ID programs from removable disk devices.)
233 .B MS_RDONLY
234 Mount filesystem read-only.
236 .BR MS_REC " (since Linux 2.4.11)"
237 Used in conjunction with
238 .BR MS_BIND
239 to create a recursive bind mount,
240 and in conjunction with the propagation type flags to recursively change
241 the propagation type of all of the mounts in a subtree.
242 See below for further details.
244 .BR MS_RELATIME " (since Linux 2.6.20)"
245 When a file on this filesystem is accessed,
246 update the file's last access time (atime) only if the current value
247 of atime is less than or equal to the file's last modification time (mtime)
248 or last status change time (ctime).
249 This option is useful for programs, such as
250 .BR mutt (1),
251 that need to know when a file has been read since it was last modified.
252 Since Linux 2.6.30, the kernel defaults to the behavior provided
253 by this flag (unless
254 .BR MS_NOATIME
255 was specified), and the
256 .B MS_STRICTATIME
257 flag is required to obtain traditional semantics.
258 In addition, since Linux 2.6.30,
259 the file's last access time is always updated if it
260 is more than 1 day old.
261 .\" Matthew Garrett notes in the patch that added this behavior
262 .\" that this lets utilities such as tmpreaper (which deletes
263 .\" files based on last access time) work correctly.
265 .BR MS_SILENT " (since Linux 2.6.17)"
266 Suppress the display of certain
267 .RI ( printk ())
268 warning messages in the kernel log.
269 This flag supersedes the misnamed and obsolete
270 .BR MS_VERBOSE
271 flag (available since Linux 2.4.12), which has the same meaning.
273 .BR MS_STRICTATIME " (since Linux 2.6.30)"
274 Always update the last access time (atime) when files on this
275 filesystem are accessed.
276 (This was the default behavior before Linux 2.6.30.)
277 Specifying this flag overrides the effect of setting the
278 .BR MS_NOATIME
280 .BR MS_RELATIME
281 flags.
283 .B MS_SYNCHRONOUS
284 Make writes on this filesystem synchronous (as though
286 .B O_SYNC
287 flag to
288 .BR open (2)
289 was specified for all file opens to this filesystem).
291 .BR MS_NOSYMFOLLOW " (since Linux 5.10)"
292 .\" dab741e0e02bd3c4f5e2e97be74b39df2523fc6e
293 Do not follow symbolic links when resolving paths.
294 Symbolic links can still be created,
296 .BR readlink (1),
297 .BR readlink (2),
298 .BR realpath (1),
300 .BR realpath (3)
301 all still work properly.
303 From Linux 2.4 onward, some of the above flags are
304 settable on a per-mount basis,
305 while others apply to the superblock of the mounted filesystem,
306 meaning that all mounts of the same filesystem share those flags.
307 (Previously, all of the flags were per-superblock.)
309 The per-mount-point flags are as follows:
310 .IP * 3
311 Since Linux 2.4:
312 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
313 flags are settable on a per-mount-point basis.
314 .IP *
315 Additionally, since Linux 2.6.16:
316 .B MS_NOATIME
318 .BR MS_NODIRATIME .
319 .IP *
320 Additionally, since Linux 2.6.20:
321 .BR MS_RELATIME .
323 The following flags are per-superblock:
324 .BR MS_DIRSYNC ,
325 .BR MS_LAZYTIME ,
326 .BR MS_MANDLOCK ,
327 .BR MS_SILENT ,
329 .BR MS_SYNCHRONOUS .
330 .\" And MS_I_VERSION?
331 The initial settings of these flags are determined on the first
332 mount of the filesystem, and will be shared by all subsequent mounts
333 of the same filesystem.
334 Subsequently, the settings of the flags can be changed
335 via a remount operation (see below).
336 Such changes will be visible via all mount points associated
337 with the filesystem.
339 Since Linux 2.6.16,
340 .B MS_RDONLY
341 can be set or cleared on a per-mount-point basis as well as on
342 the underlying filesystem superblock.
343 The mounted filesystem will be writable only if neither the filesystem
344 nor the mountpoint are flagged as read-only.
346 .SS Remounting an existing mount
347 An existing mount may be remounted by specifying
348 .B MS_REMOUNT
350 .IR mountflags .
351 This allows you to change the
352 .I mountflags
354 .I data
355 of an existing mount without having to unmount and remount the filesystem.
356 .I target
357 should be the same value specified in the initial
358 .BR mount ()
359 call.
362 .I source
364 .I filesystemtype
365 arguments are ignored.
368 .I mountflags
370 .I data
371 arguments should match the values used in the original
372 .BR mount ()
373 call, except for those parameters that are being deliberately changed.
375 The following
376 .I mountflags
377 can be changed:
378 .BR MS_LAZYTIME ,
379 .\" FIXME
380 .\" MS_LAZYTIME seems to be available only on a few filesystems,
381 .\" and on ext4, it seems (from experiment that this flag
382 .\" can only be enabled (but not disabled) on a remount.
383 .\" The following code in ext4_remount() (kernel 4.17) seems to
384 .\" confirm this:
386 .\"        if (*flags & SB_LAZYTIME)
387 .\"                sb->s_flags |= SB_LAZYTIME;
388 .BR MS_MANDLOCK ,
389 .BR MS_NOATIME ,
390 .BR MS_NODEV ,
391 .BR MS_NODIRATIME ,
392 .BR MS_NOEXEC ,
393 .BR MS_NOSUID ,
394 .BR MS_RELATIME ,
395 .BR MS_RDONLY ,
396 .BR MS_STRICTATIME
397 (whose effect is to clear the
398 .BR MS_NOATIME
400 .BR MS_RELATIME
401 flags),
403 .BR MS_SYNCHRONOUS .
404 Attempts to change the setting of the
405 .\" See the definition of MS_RMT_MASK in include/uapi/linux/fs.h,
406 .\" which excludes MS_DIRSYNC and MS_SILENT, although SB_DIRSYNC
407 .\" and SB_SILENT are split out as per-superblock flags in do_mount()
408 .\" (Linux 4.17 source code)
409 .BR MS_DIRSYNC
411 .BR MS_SILENT
412 flags during a remount are silently ignored.
413 Note that changes to per-superblock flags are visible via
414 all mount points of the associated filesystem
415 (because the per-superblock flags are shared by all mount points).
417 Since Linux 3.17,
418 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
419 if none of
420 .BR MS_NOATIME ,
421 .BR MS_NODIRATIME ,
422 .BR MS_RELATIME ,
424 .BR MS_STRICTATIME
425 is specified in
426 .IR mountflags ,
427 then the remount operation preserves the existing values of these flags
428 (rather than defaulting to
429 .BR MS_RELATIME ).
431 Since Linux 2.6.26, the
432 .B MS_REMOUNT
433 flag can be used with
434 .B MS_BIND
435 to modify only the per-mount-point flags.
436 .\" See https://lwn.net/Articles/281157/
437 This is particularly useful for setting or clearing the "read-only"
438 flag on a mount point without changing the underlying filesystem.
439 Specifying
440 .IR mountflags
443 .in +4n
445 MS_REMOUNT | MS_BIND | MS_RDONLY
449 will make access through this mountpoint read-only, without affecting
450 other mount points.
452 .SS Creating a bind mount
454 .I mountflags
455 includes
456 .BR MS_BIND
457 (available since Linux 2.4),
458 .\" since 2.4.0-test9
459 then perform a bind mount.
460 A bind mount makes a file or a directory subtree visible at
461 another point within the single directory hierarchy.
462 Bind mounts may cross filesystem boundaries and span
463 .BR chroot (2)
464 jails.
467 .IR filesystemtype
469 .IR data
470 arguments are ignored.
472 The remaining bits (other than
473 .BR MS_REC ,
474 described below) in the
475 .I mountflags
476 argument are also ignored.
477 (The bind mount has the same mount options as
478 the underlying mount point.)
479 However, see the discussion of remounting above,
480 for a method of making an existing bind mount read-only.
482 By default, when a directory is bind mounted,
483 only that directory is mounted;
484 if there are any submounts under the directory tree,
485 they are not bind mounted.
486 If the
487 .BR MS_REC
488 flag is also specified, then a recursive bind mount operation is performed:
489 all submounts under the
490 .I source
491 subtree (other than unbindable mounts)
492 are also bind mounted at the corresponding location in the
493 .I target
494 subtree.
496 .SS Changing the propagation type of an existing mount
498 .IR mountflags
499 includes one of
500 .BR MS_SHARED ,
501 .BR MS_PRIVATE ,
502 .BR MS_SLAVE ,
504 .BR MS_UNBINDABLE
505 (all available since Linux 2.6.15),
506 then the propagation type of an existing mount is changed.
507 If more than one of these flags is specified, an error results.
509 The only other flags that can be specified while changing
510 the propagation type are
511 .BR MS_REC
512 (described below) and
513 .BR MS_SILENT
514 (which is ignored).
517 .IR source ,
518 .IR filesystemtype ,
520 .IR data
521 arguments are ignored.
523 The meanings of the propagation type flags are as follows:
525 .BR MS_SHARED
526 Make this mount point shared.
527 Mount and unmount events immediately under this mount point will propagate
528 to the other mount points that are members of this mount's peer group.
529 Propagation here means that the same mount or unmount will automatically
530 occur under all of the other mount points in the peer group.
531 Conversely, mount and unmount events that take place under
532 peer mount points will propagate to this mount point.
534 .BR MS_PRIVATE
535 Make this mount point private.
536 Mount and unmount events do not propagate into or out of this mount point.
538 .BR MS_SLAVE
539 If this is a shared mount point that is a member of a peer group
540 that contains other members, convert it to a slave mount.
541 If this is a shared mount point that is a member of a peer group
542 that contains no other members, convert it to a private mount.
543 Otherwise, the propagation type of the mount point is left unchanged.
545 When a mount point is a slave,
546 mount and unmount events propagate into this mount point from
547 the (master) shared peer group of which it was formerly a member.
548 Mount and unmount events under this mount point do not propagate to any peer.
550 A mount point can be the slave of another peer group
551 while at the same time sharing mount and unmount events
552 with a peer group of which it is a member.
554 .BR MS_UNBINDABLE
555 Make this mount unbindable.
556 This is like a private mount,
557 and in addition this mount can't be bind mounted.
558 When a recursive bind mount
559 .RB ( mount ()
560 with the
561 .BR MS_BIND
563 .BR MS_REC
564 flags) is performed on a directory subtree,
565 any unbindable mounts within the subtree are automatically pruned
566 (i.e., not replicated)
567 when replicating that subtree to produce the target subtree.
569 By default, changing the propagation type affects only the
570 .I target
571 mount point.
572 If the
573 .B MS_REC
574 flag is also specified in
575 .IR mountflags ,
576 then the propagation type of all mount points under
577 .IR target
578 is also changed.
580 For further details regarding mount propagation types
581 (including the default propagation type assigned to new mounts), see
582 .BR mount_namespaces (7).
584 .SS Moving a mount
586 .I mountflags
587 contains the flag
588 .BR MS_MOVE
589 (available since Linux 2.4.18),
590 then move a subtree:
591 .I source
592 specifies an existing mount point and
593 .I target
594 specifies the new location to which that mount point is to be relocated.
595 The move is atomic: at no point is the subtree unmounted.
597 The remaining bits in the
598 .IR mountflags
599 argument are ignored, as are the
600 .IR filesystemtype
602 .IR data
603 arguments.
605 .SS Creating a new mount point
606 If none of
607 .BR MS_REMOUNT ,
608 .BR MS_BIND ,
609 .BR MS_MOVE ,
610 .BR MS_SHARED ,
611 .BR MS_PRIVATE ,
612 .BR MS_SLAVE ,
614 .BR MS_UNBINDABLE
615 is specified in
616 .IR mountflags ,
617 then
618 .BR mount ()
619 performs its default action: creating a new mount point.
620 .IR source
621 specifies the source for the new mount point, and
622 .IR target
623 specifies the directory at which to create the mount point.
626 .I filesystemtype
628 .I data
629 arguments are employed, and further bits may be specified in
630 .IR mountflags
631 to modify the behavior of the call.
633 .SH RETURN VALUE
634 On success, zero is returned.
635 On error, \-1 is returned, and
636 .I errno
637 is set to indicate the error.
638 .SH ERRORS
639 The error values given below result from filesystem type independent
640 errors.
641 Each filesystem type may have its own special errors and its
642 own special behavior.
643 See the Linux kernel source code for details.
645 .B EACCES
646 A component of a path was not searchable.
647 (See also
648 .BR path_resolution (7).)
650 .B EACCES
651 Mounting a read-only filesystem was attempted without giving the
652 .B MS_RDONLY
653 flag.
655 The filesystem may be read-only for various reasons, including:
656 it resides on a read-only optical disk;
657 it is resides on a device with a physical switch that has been set to
658 mark the device read-only;
659 the filesystem implementation was compiled with read-only support;
660 or errors were detected when initially mounting the filesystem,
661 so that it was marked read-only
662 and can't be remounted as read-write (until the errors are fixed).
664 Some filesystems instead return the error
665 .BR EROFS
666 on an attempt to mount a read-only filesystem.
668 .B EACCES
669 The block device
670 .I source
671 is located on a filesystem mounted with the
672 .B MS_NODEV
673 option.
674 .\" mtk: Probably: write permission is required for MS_BIND, with
675 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
677 .B EBUSY
678 An attempt was made to stack a new mount directly on
679 top of an existing mount point that was created in this
680 mount namespace with the same
681 .I source
683 .IR target .
685 .B EBUSY
686 .I source
687 cannot be remounted read-only,
688 because it still holds files open for writing.
690 .B EFAULT
691 One of the pointer arguments points outside the user address space.
693 .B EINVAL
694 .I source
695 had an invalid superblock.
697 .B EINVAL
698 A remount operation
699 .RB ( MS_REMOUNT )
700 was attempted, but
701 .I source
702 was not already mounted on
703 .IR target .
705 .B EINVAL
706 A move operation
707 .RB ( MS_MOVE )
708 was attempted, but the mount tree under
709 .I source
710 includes unbindable mounts and
711 .I target
712 is a mount point that has propagation type
713 .BR MS_SHARED .
715 .B EINVAL
716 A move operation
717 .RB ( MS_MOVE )
718 was attempted, but the parent mount of
719 .I source
720 mount has propagation type
721 .BR MS_SHARED .
723 .B EINVAL
724 A move operation
725 .RB ( MS_MOVE )
726 was attempted, but
727 .I source
728 was not a mount point, or was \(aq/\(aq.
730 .B EINVAL
731 A bind operation
732 .RB ( MS_BIND )
733 was requested where
734 .I source
735 referred a mount namespace magic link (i.e., a
736 .I /proc/[pid]/ns/mnt
737 magic link or a bind mount to such a link)
738 and the propagation type of the parent mount of
739 .I target
741 .BR MS_SHARED ,
742 .\" See commit 8823c079ba7136dc1948d6f6dcb5f8022bde438e
743 but propagation of the requested bind mount could lead to a circular
744 dependency that might prevent the mount namespace from ever being freed.
746 .B EINVAL
747 .I mountflags
748 includes more than one of
749 .BR MS_SHARED ,
750 .BR MS_PRIVATE ,
751 .BR MS_SLAVE ,
753 .BR MS_UNBINDABLE .
755 .B EINVAL
756 .I mountflags
757 includes
758 .BR MS_SHARED ,
759 .BR MS_PRIVATE ,
760 .BR MS_SLAVE ,
762 .BR MS_UNBINDABLE
763 and also includes a flag other than
764 .BR MS_REC
766 .BR MS_SILENT .
768 .BR EINVAL
769 An attempt was made to bind mount an unbindable mount.
771 .BR EINVAL
772 In an unprivileged mount namespace
773 (i.e., a mount namespace owned by a user namespace
774 that was created by an unprivileged user),
775 a bind mount operation
776 .RB ( MS_BIND )
777 was attempted without specifying
778 .RB ( MS_REC ),
779 which would have revealed the filesystem tree underneath one of
780 the submounts of the directory being bound.
782 .B ELOOP
783 Too many links encountered during pathname resolution.
785 .B ELOOP
786 A move operation was attempted, and
787 .I target
788 is a descendant of
789 .IR source .
791 .B EMFILE
792 (In case no block device is required:)
793 Table of dummy devices is full.
795 .B ENAMETOOLONG
796 A pathname was longer than
797 .BR MAXPATHLEN .
799 .B ENODEV
800 .I filesystemtype
801 not configured in the kernel.
803 .B ENOENT
804 A pathname was empty or had a nonexistent component.
806 .B ENOMEM
807 The kernel could not allocate a free page to copy filenames or data into.
809 .B ENOTBLK
810 .I source
811 is not a block device (and a device was required).
813 .B ENOTDIR
814 .IR target ,
815 or a prefix of
816 .IR source ,
817 is not a directory.
819 .B ENXIO
820 The major number of the block device
821 .I source
822 is out of range.
824 .B EPERM
825 The caller does not have the required privileges.
827 .B EROFS
828 Mounting a read-only filesystem was attempted without giving the
829 .B MS_RDONLY
830 flag.
832 .BR EACCES ,
833 above.
834 .SH VERSIONS
835 The definitions of
836 .BR MS_DIRSYNC ,
837 .BR MS_MOVE ,
838 .BR MS_PRIVATE ,
839 .BR MS_REC ,
840 .BR MS_RELATIME ,
841 .BR MS_SHARED ,
842 .BR MS_SLAVE ,
843 .BR MS_STRICTATIME ,
845 .BR MS_UNBINDABLE
846 were added to glibc headers in version 2.12.
848 .SH CONFORMING TO
849 This function is Linux-specific and should not be used in
850 programs intended to be portable.
851 .SH NOTES
852 Since Linux 2.4 a single filesystem can be mounted at
853 multiple mount points, and multiple mounts can be stacked
854 on the same mount point.
855 .\" Multiple mounts on same mount point: since 2.3.99pre7.
858 .I mountflags
859 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
860 in the top 16 bits.
861 (All of the other flags discussed in DESCRIPTION
862 occupy the low order 16 bits of
863 .IR mountflags .)
864 Specifying
865 .BR MS_MGC_VAL
866 was required in kernel versions prior to 2.4,
867 but since Linux 2.4 is no longer required and is ignored if specified.
869 The original
870 .B MS_SYNC
871 flag was renamed
872 .B MS_SYNCHRONOUS
873 in 1.1.69
874 when a different
875 .B MS_SYNC
876 was added to \fI<mman.h>\fP.
878 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
879 on a filesystem mounted with
880 .B MS_NOSUID
881 would fail with
882 .BR EPERM .
883 Since Linux 2.4 the set-user-ID and set-group-ID bits are
884 just silently ignored in this case.
885 .\" The change is in patch-2.4.0-prerelease.
887 .SS Mount namespaces
888 Starting with kernel 2.4.19, Linux provides mount namespaces.
889 A mount namespace is the set of filesystem mounts that
890 are visible to a process.
891 Mount namespaces can be (and usually are)
892 shared between multiple processes,
893 and changes to the namespace (i.e., mounts and unmounts) by one process
894 are visible to all other processes sharing the same namespace.
895 (The pre-2.4.19 Linux situation can be considered as one in which
896 a single namespace was shared by every process on the system.)
898 A child process created by
899 .BR fork (2)
900 shares its parent's mount namespace;
901 the mount namespace is preserved across an
902 .BR execve (2).
904 A process can obtain a private mount namespace if:
905 it was created using the
906 .BR clone (2)
907 .BR CLONE_NEWNS
908 flag,
909 in which case its new namespace is initialized to be a
910 .I copy
911 of the namespace of the process that called
912 .BR clone (2);
913 or it calls
914 .BR unshare (2)
915 with the
916 .BR CLONE_NEWNS
917 flag,
918 which causes the caller's mount namespace to obtain a private copy
919 of the namespace that it was previously sharing with other processes,
920 so that future mounts and unmounts by the caller are invisible
921 to other processes (except child processes that the caller
922 subsequently creates) and vice versa.
924 For further details on mount namespaces, see
925 .BR mount_namespaces (7).
927 .SS Parental relationship between mount points
928 Each mount point has a parent mount point.
929 The overall parental relationship of all mount points defines
930 the single directory hierarchy seen by the processes within a mount namespace.
932 The parent of a new mount point is defined when the mount point is created.
933 In the usual case,
934 the parent of a new mount is the mount point of the filesystem
935 containing the directory or file at which the new mount is attached.
936 In the case where a new mount is stacked on top of an existing mount,
937 the parent of the new mount is the previous mount that was stacked
938 at that location.
940 The parental relationship between mount points can be discovered via the
941 .I /proc/[pid]/mountinfo
942 file (see below).
944 .SS /proc/[pid]/mounts and /proc/[pid]/mountinfo
945 The Linux-specific
946 .I /proc/[pid]/mounts
947 file exposes the list of mount points in the mount
948 namespace of the process with the specified ID.
950 .I /proc/[pid]/mountinfo
951 file exposes even more information about mount points,
952 including the propagation type and mount ID information that makes it
953 possible to discover the parental relationship between mount points.
955 .BR proc (5)
957 .BR mount_namespaces (7)
958 for details of this file.
959 .SH SEE ALSO
960 .BR mountpoint (1),
961 .BR chroot (2),
962 .BR ioctl_iflags (2),
963 .BR pivot_root (2),
964 .BR umount (2),
965 .BR mount_namespaces (7),
966 .BR path_resolution (7),
967 .BR findmnt (8),
968 .BR lsblk (8),
969 .BR mount (8),
970 .BR umount (8)