share/mk/: Fix includes
[man-pages.git] / man2 / mount.2
blobd8a691e13524aa675d7146478f3a459ce0449ee6
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 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .\" Modified 1996-11-04 by Eric S. Raymond <esr@thyrsus.com>
8 .\" Modified 2001-10-13 by Michael Kerrisk <mtk.manpages@gmail.com>
9 .\"     Added note on historical behavior of MS_NOSUID
10 .\" Modified 2002-05-16 by Michael Kerrisk <mtk.manpages@gmail.com>
11 .\"     Extensive changes and additions
12 .\" Modified 2002-05-27 by aeb
13 .\" Modified 2002-06-11 by Michael Kerrisk <mtk.manpages@gmail.com>
14 .\"     Enhanced descriptions of MS_MOVE, MS_BIND, and MS_REMOUNT
15 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
16 .\" 2005-05-18, mtk, Added MNT_EXPIRE, plus a few other tidy-ups.
17 .\" 2008-10-06, mtk: move umount*() material into separate umount.2 page.
18 .\" 2008-10-06, mtk: Add discussion of namespaces.
19 .\"
20 .TH mount 2 (date) "Linux man-pages (unreleased)"
21 .SH NAME
22 mount \- mount filesystem
23 .SH LIBRARY
24 Standard C library
25 .RI ( libc ", " \-lc )
26 .SH SYNOPSIS
27 .nf
28 .B "#include <sys/mount.h>"
30 .BI "int mount(const char *" source ", const char *" target ,
31 .BI "          const char *" filesystemtype ", unsigned long " mountflags ,
32 .BI "          const void *_Nullable " data );
33 .fi
34 .SH DESCRIPTION
35 .BR mount ()
36 attaches the filesystem specified by
37 .I source
38 (which is often a pathname referring to a device,
39 but can also be the pathname of a directory or file,
40 or a dummy string) to the location (a directory or file)
41 specified by the pathname in
42 .IR target .
44 Appropriate privilege (Linux: the
45 .B CAP_SYS_ADMIN
46 capability) is required to mount filesystems.
48 Values for the
49 .I filesystemtype
50 argument supported by the kernel are listed in
51 .I /proc/filesystems
52 (e.g., "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse",
53 "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660").
54 Further types may become available when the appropriate modules
55 are loaded.
57 The
58 .I data
59 argument is interpreted by the different filesystems.
60 Typically it is a string of comma-separated options
61 understood by this filesystem.
62 See
63 .BR mount (8)
64 for details of the options available for each filesystem type.
65 This argument may be specified as NULL, if there are no options.
67 A call to
68 .BR mount ()
69 performs one of a number of general types of operation,
70 depending on the bits specified in
71 .IR mountflags .
72 The choice of which operation to perform is determined by
73 testing the bits set in
74 .IR mountflags ,
75 with the tests being conducted in the order listed here:
76 .IP \[bu] 3
77 Remount an existing mount:
78 .I mountflags
79 includes
80 .BR MS_REMOUNT .
81 .IP \[bu]
82 Create a bind mount:
83 .I mountflags
84 includes
85 .BR MS_BIND .
86 .IP \[bu]
87 Change the propagation type of an existing mount:
88 .I mountflags
89 includes one of
90 .BR MS_SHARED ,
91 .BR MS_PRIVATE ,
92 .BR MS_SLAVE ,
94 .BR MS_UNBINDABLE .
95 .IP \[bu]
96 Move an existing mount to a new location:
97 .I mountflags
98 includes
99 .BR MS_MOVE .
100 .IP \[bu]
101 Create a new mount:
102 .I mountflags
103 includes none of the above flags.
105 Each of these operations is detailed later in this page.
106 Further flags may be specified in
107 .I mountflags
108 to modify the behavior of
109 .BR mount (),
110 as described below.
112 .SS Additional mount flags
113 The list below describes the additional flags that can be specified in
114 .IR mountflags .
115 Note that some operation types ignore some or all of these flags,
116 as described later in this page.
118 .\" FIXME 2.6.25 Added MS_I_VERSION, which needs to be documented.
119 .\" commit 7a224228ed79d587ece2304869000aad1b8e97dd
120 .\" (This is a per-superblock flag)
123 .BR MS_DIRSYNC " (since Linux 2.5.19)"
124 Make directory changes on this filesystem synchronous.
125 (This property can be obtained for individual directories
126 or subtrees using
127 .BR chattr (1).)
129 .BR MS_LAZYTIME " (since Linux 4.0)"
130 .\" commit 0ae45f63d4ef8d8eeec49c7d8b44a1775fff13e8
131 .\" commit fe032c422c5ba562ba9c2d316f55e258e03259c6
132 .\" commit a26f49926da938f47561f386be56a83dd37a496d
133 Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
134 by maintaining these changes only in memory.
135 The on-disk timestamps are updated only when:
137 .IP \[bu] 3
138 the inode needs to be updated for some change unrelated to file timestamps;
139 .IP \[bu]
140 the application employs
141 .BR fsync (2),
142 .BR syncfs (2),
144 .BR sync (2);
145 .IP \[bu]
146 an undeleted inode is evicted from memory; or
147 .IP \[bu]
148 more than 24 hours have passed since the inode was written to disk.
151 This mount option significantly reduces writes
152 needed to update the inode's timestamps, especially mtime and atime.
153 However, in the event of a system crash, the atime and mtime fields
154 on disk might be out of date by up to 24 hours.
156 Examples of workloads where this option could be of significant benefit
157 include frequent random writes to preallocated files,
158 as well as cases where the
159 .B MS_STRICTATIME
160 mount option is also enabled.
161 (The advantage of combining
162 .B MS_STRICTATIME
164 .B MS_LAZYTIME
165 is that
166 .BR stat (2)
167 will return the correctly updated atime, but the atime updates
168 will be flushed to disk only in the cases listed above.)
170 .B MS_MANDLOCK
171 Permit mandatory locking on files in this filesystem.
172 (Mandatory locking must still be enabled on a per-file basis,
173 as described in
174 .BR fcntl (2).)
175 Since Linux 4.5,
176 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
177 this mount option requires the
178 .B CAP_SYS_ADMIN
179 capability and a kernel configured with the
180 .B CONFIG_MANDATORY_FILE_LOCKING
181 option.
182 Mandatory locking has been fully deprecated in Linux 5.15, so
183 this flag should be considered deprecated.
185 .B MS_NOATIME
186 Do not update access times for (all types of) files on this filesystem.
188 .B MS_NODEV
189 Do not allow access to devices (special files) on this filesystem.
191 .B MS_NODIRATIME
192 Do not update access times for directories on this filesystem.
193 This flag provides a subset of the functionality provided by
194 .BR MS_NOATIME ;
195 that is,
196 .B MS_NOATIME
197 implies
198 .BR MS_NODIRATIME .
200 .B MS_NOEXEC
201 Do not allow programs to be executed from this filesystem.
202 .\" (Possibly useful for a filesystem that contains non-Linux executables.
203 .\" Often used as a security feature, e.g., to make sure that restricted
204 .\" users cannot execute files uploaded using ftp or so.)
206 .B MS_NOSUID
207 Do not honor set-user-ID and set-group-ID bits or file capabilities
208 when executing programs from this filesystem.
209 In addition, SELinux domain
210 transitions require the permission
211 .IR nosuid_transition ,
212 which in turn needs
213 also the policy capability
214 .IR nnp_nosuid_transition .
215 .\" (This is a security feature to prevent users executing set-user-ID and
216 .\" set-group-ID programs from removable disk devices.)
218 .B MS_RDONLY
219 Mount filesystem read-only.
221 .BR MS_REC " (since Linux 2.4.11)"
222 Used in conjunction with
223 .B MS_BIND
224 to create a recursive bind mount,
225 and in conjunction with the propagation type flags to recursively change
226 the propagation type of all of the mounts in a subtree.
227 See below for further details.
229 .BR MS_RELATIME " (since Linux 2.6.20)"
230 When a file on this filesystem is accessed,
231 update the file's last access time (atime) only if the current value
232 of atime is less than or equal to the file's last modification time (mtime)
233 or last status change time (ctime).
234 This option is useful for programs, such as
235 .BR mutt (1),
236 that need to know when a file has been read since it was last modified.
237 Since Linux 2.6.30, the kernel defaults to the behavior provided
238 by this flag (unless
239 .B MS_NOATIME
240 was specified), and the
241 .B MS_STRICTATIME
242 flag is required to obtain traditional semantics.
243 In addition, since Linux 2.6.30,
244 the file's last access time is always updated if it
245 is more than 1 day old.
246 .\" Matthew Garrett notes in the patch that added this behavior
247 .\" that this lets utilities such as tmpreaper (which deletes
248 .\" files based on last access time) work correctly.
250 .BR MS_SILENT " (since Linux 2.6.17)"
251 Suppress the display of certain
252 .RI ( printk ())
253 warning messages in the kernel log.
254 This flag supersedes the misnamed and obsolete
255 .B MS_VERBOSE
256 flag (available since Linux 2.4.12), which has the same meaning.
258 .BR MS_STRICTATIME " (since Linux 2.6.30)"
259 Always update the last access time (atime) when files on this
260 filesystem are accessed.
261 (This was the default behavior before Linux 2.6.30.)
262 Specifying this flag overrides the effect of setting the
263 .B MS_NOATIME
265 .B MS_RELATIME
266 flags.
268 .B MS_SYNCHRONOUS
269 Make writes on this filesystem synchronous (as though
271 .B O_SYNC
272 flag to
273 .BR open (2)
274 was specified for all file opens to this filesystem).
276 .BR MS_NOSYMFOLLOW " (since Linux 5.10)"
277 .\" dab741e0e02bd3c4f5e2e97be74b39df2523fc6e
278 Do not follow symbolic links when resolving paths.
279 Symbolic links can still be created,
281 .BR readlink (1),
282 .BR readlink (2),
283 .BR realpath (1),
285 .BR realpath (3)
286 all still work properly.
288 From Linux 2.4 onward, some of the above flags are
289 settable on a per-mount basis,
290 while others apply to the superblock of the mounted filesystem,
291 meaning that all mounts of the same filesystem share those flags.
292 (Previously, all of the flags were per-superblock.)
294 The per-mount-point flags are as follows:
295 .IP \[bu] 3
296 Since Linux 2.4:
297 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
298 flags are settable on a per-mount-point basis.
299 .IP \[bu]
300 Additionally, since Linux 2.6.16:
301 .B MS_NOATIME
303 .BR MS_NODIRATIME .
304 .IP \[bu]
305 Additionally, since Linux 2.6.20:
306 .BR MS_RELATIME .
308 The following flags are per-superblock:
309 .BR MS_DIRSYNC ,
310 .BR MS_LAZYTIME ,
311 .BR MS_MANDLOCK ,
312 .BR MS_SILENT ,
314 .BR MS_SYNCHRONOUS .
315 .\" And MS_I_VERSION?
316 The initial settings of these flags are determined on the first
317 mount of the filesystem, and will be shared by all subsequent mounts
318 of the same filesystem.
319 Subsequently, the settings of the flags can be changed
320 via a remount operation (see below).
321 Such changes will be visible via all mounts associated
322 with the filesystem.
324 Since Linux 2.6.16,
325 .B MS_RDONLY
326 can be set or cleared on a per-mount-point basis as well as on
327 the underlying filesystem superblock.
328 The mounted filesystem will be writable only if neither the filesystem
329 nor the mountpoint are flagged as read-only.
331 .SS Remounting an existing mount
332 An existing mount may be remounted by specifying
333 .B MS_REMOUNT
335 .IR mountflags .
336 This allows you to change the
337 .I mountflags
339 .I data
340 of an existing mount without having to unmount and remount the filesystem.
341 .I target
342 should be the same value specified in the initial
343 .BR mount ()
344 call.
347 .I source
349 .I filesystemtype
350 arguments are ignored.
353 .I mountflags
355 .I data
356 arguments should match the values used in the original
357 .BR mount ()
358 call, except for those parameters that are being deliberately changed.
360 The following
361 .I mountflags
362 can be changed:
363 .BR MS_LAZYTIME ,
364 .\" FIXME
365 .\" MS_LAZYTIME seems to be available only on a few filesystems,
366 .\" and on ext4, it seems (from experiment that this flag
367 .\" can only be enabled (but not disabled) on a remount.
368 .\" The following code in ext4_remount() (kernel 4.17) seems to
369 .\" confirm this:
371 .\"        if (*flags & SB_LAZYTIME)
372 .\"                sb->s_flags |= SB_LAZYTIME;
373 .BR MS_MANDLOCK ,
374 .BR MS_NOATIME ,
375 .BR MS_NODEV ,
376 .BR MS_NODIRATIME ,
377 .BR MS_NOEXEC ,
378 .BR MS_NOSUID ,
379 .BR MS_RELATIME ,
380 .BR MS_RDONLY ,
381 .B MS_STRICTATIME
382 (whose effect is to clear the
383 .B MS_NOATIME
385 .B MS_RELATIME
386 flags),
388 .BR MS_SYNCHRONOUS .
389 Attempts to change the setting of the
390 .\" See the definition of MS_RMT_MASK in include/uapi/linux/fs.h,
391 .\" which excludes MS_DIRSYNC and MS_SILENT, although SB_DIRSYNC
392 .\" and SB_SILENT are split out as per-superblock flags in do_mount()
393 .\" (Linux 4.17 source code)
394 .B MS_DIRSYNC
396 .B MS_SILENT
397 flags during a remount are silently ignored.
398 Note that changes to per-superblock flags are visible via
399 all mounts of the associated filesystem
400 (because the per-superblock flags are shared by all mounts).
402 Since Linux 3.17,
403 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
404 if none of
405 .BR MS_NOATIME ,
406 .BR MS_NODIRATIME ,
407 .BR MS_RELATIME ,
409 .B MS_STRICTATIME
410 is specified in
411 .IR mountflags ,
412 then the remount operation preserves the existing values of these flags
413 (rather than defaulting to
414 .BR MS_RELATIME ).
416 Since Linux 2.6.26, the
417 .B MS_REMOUNT
418 flag can be used with
419 .B MS_BIND
420 to modify only the per-mount-point flags.
421 .\" See https://lwn.net/Articles/281157/
422 This is particularly useful for setting or clearing the "read-only"
423 flag on a mount without changing the underlying filesystem.
424 Specifying
425 .I mountflags
428 .in +4n
430 MS_REMOUNT | MS_BIND | MS_RDONLY
434 will make access through this mountpoint read-only, without affecting
435 other mounts.
437 .SS Creating a bind mount
439 .I mountflags
440 includes
441 .B MS_BIND
442 (available since Linux 2.4),
443 .\" since Linux 2.4.0-test9
444 then perform a bind mount.
445 A bind mount makes a file or a directory subtree visible at
446 another point within the single directory hierarchy.
447 Bind mounts may cross filesystem boundaries and span
448 .BR chroot (2)
449 jails.
452 .I filesystemtype
454 .I data
455 arguments are ignored.
457 The remaining bits (other than
458 .BR MS_REC ,
459 described below) in the
460 .I mountflags
461 argument are also ignored.
462 (The bind mount has the same mount options as
463 the underlying mount.)
464 However, see the discussion of remounting above,
465 for a method of making an existing bind mount read-only.
467 By default, when a directory is bind mounted,
468 only that directory is mounted;
469 if there are any submounts under the directory tree,
470 they are not bind mounted.
471 If the
472 .B MS_REC
473 flag is also specified, then a recursive bind mount operation is performed:
474 all submounts under the
475 .I source
476 subtree (other than unbindable mounts)
477 are also bind mounted at the corresponding location in the
478 .I target
479 subtree.
481 .SS Changing the propagation type of an existing mount
483 .I mountflags
484 includes one of
485 .BR MS_SHARED ,
486 .BR MS_PRIVATE ,
487 .BR MS_SLAVE ,
489 .B MS_UNBINDABLE
490 (all available since Linux 2.6.15),
491 then the propagation type of an existing mount is changed.
492 If more than one of these flags is specified, an error results.
494 The only other flags that can be specified while changing
495 the propagation type are
496 .B MS_REC
497 (described below) and
498 .B MS_SILENT
499 (which is ignored).
502 .IR source ,
503 .IR filesystemtype ,
505 .I data
506 arguments are ignored.
508 The meanings of the propagation type flags are as follows:
510 .B MS_SHARED
511 Make this mount shared.
512 Mount and unmount events immediately under this mount will propagate
513 to the other mounts that are members of this mount's peer group.
514 Propagation here means that the same mount or unmount will automatically
515 occur under all of the other mounts in the peer group.
516 Conversely, mount and unmount events that take place under
517 peer mounts will propagate to this mount.
519 .B MS_PRIVATE
520 Make this mount private.
521 Mount and unmount events do not propagate into or out of this mount.
523 .B MS_SLAVE
524 If this is a shared mount that is a member of a peer group
525 that contains other members, convert it to a slave mount.
526 If this is a shared mount that is a member of a peer group
527 that contains no other members, convert it to a private mount.
528 Otherwise, the propagation type of the mount is left unchanged.
530 When a mount is a slave,
531 mount and unmount events propagate into this mount from
532 the (master) shared peer group of which it was formerly a member.
533 Mount and unmount events under this mount do not propagate to any peer.
535 A mount can be the slave of another peer group
536 while at the same time sharing mount and unmount events
537 with a peer group of which it is a member.
539 .B MS_UNBINDABLE
540 Make this mount unbindable.
541 This is like a private mount,
542 and in addition this mount can't be bind mounted.
543 When a recursive bind mount
544 .RB ( mount ()
545 with the
546 .B MS_BIND
548 .B MS_REC
549 flags) is performed on a directory subtree,
550 any unbindable mounts within the subtree are automatically pruned
551 (i.e., not replicated)
552 when replicating that subtree to produce the target subtree.
554 By default, changing the propagation type affects only the
555 .I target
556 mount.
557 If the
558 .B MS_REC
559 flag is also specified in
560 .IR mountflags ,
561 then the propagation type of all mounts under
562 .I target
563 is also changed.
565 For further details regarding mount propagation types
566 (including the default propagation type assigned to new mounts), see
567 .BR mount_namespaces (7).
569 .SS Moving a mount
571 .I mountflags
572 contains the flag
573 .B MS_MOVE
574 (available since Linux 2.4.18),
575 then move a subtree:
576 .I source
577 specifies an existing mount and
578 .I target
579 specifies the new location to which that mount is to be relocated.
580 The move is atomic: at no point is the subtree unmounted.
582 The remaining bits in the
583 .I mountflags
584 argument are ignored, as are the
585 .I filesystemtype
587 .I data
588 arguments.
590 .SS Creating a new mount
591 If none of
592 .BR MS_REMOUNT ,
593 .BR MS_BIND ,
594 .BR MS_MOVE ,
595 .BR MS_SHARED ,
596 .BR MS_PRIVATE ,
597 .BR MS_SLAVE ,
599 .B MS_UNBINDABLE
600 is specified in
601 .IR mountflags ,
602 then
603 .BR mount ()
604 performs its default action: creating a new mount.
605 .I source
606 specifies the source for the new mount, and
607 .I target
608 specifies the directory at which to create the mount point.
611 .I filesystemtype
613 .I data
614 arguments are employed, and further bits may be specified in
615 .I mountflags
616 to modify the behavior of the call.
618 .SH RETURN VALUE
619 On success, zero is returned.
620 On error, \-1 is returned, and
621 .I errno
622 is set to indicate the error.
623 .SH ERRORS
624 The error values given below result from filesystem type independent
625 errors.
626 Each filesystem type may have its own special errors and its
627 own special behavior.
628 See the Linux kernel source code for details.
630 .B EACCES
631 A component of a path was not searchable.
632 (See also
633 .BR path_resolution (7).)
635 .B EACCES
636 Mounting a read-only filesystem was attempted without giving the
637 .B MS_RDONLY
638 flag.
640 The filesystem may be read-only for various reasons, including:
641 it resides on a read-only optical disk;
642 it is resides on a device with a physical switch that has been set to
643 mark the device read-only;
644 the filesystem implementation was compiled with read-only support;
645 or errors were detected when initially mounting the filesystem,
646 so that it was marked read-only
647 and can't be remounted as read-write (until the errors are fixed).
649 Some filesystems instead return the error
650 .B EROFS
651 on an attempt to mount a read-only filesystem.
653 .B EACCES
654 The block device
655 .I source
656 is located on a filesystem mounted with the
657 .B MS_NODEV
658 option.
659 .\" mtk: Probably: write permission is required for MS_BIND, with
660 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
662 .B EBUSY
663 An attempt was made to stack a new mount directly on
664 top of an existing mount point that was created in this
665 mount namespace with the same
666 .I source
668 .IR target .
670 .B EBUSY
671 .I source
672 cannot be remounted read-only,
673 because it still holds files open for writing.
675 .B EFAULT
676 One of the pointer arguments points outside the user address space.
678 .B EINVAL
679 .I source
680 had an invalid superblock.
682 .B EINVAL
683 A remount operation
684 .RB ( MS_REMOUNT )
685 was attempted, but
686 .I source
687 was not already mounted on
688 .IR target .
690 .B EINVAL
691 A move operation
692 .RB ( MS_MOVE )
693 was attempted, but the mount tree under
694 .I source
695 includes unbindable mounts and
696 .I target
697 is a mount that has propagation type
698 .BR MS_SHARED .
700 .B EINVAL
701 A move operation
702 .RB ( MS_MOVE )
703 was attempted, but the parent mount of
704 .I source
705 mount has propagation type
706 .BR MS_SHARED .
708 .B EINVAL
709 A move operation
710 .RB ( MS_MOVE )
711 was attempted, but
712 .I source
713 was not a mount, or was \[aq]/\[aq].
715 .B EINVAL
716 A bind operation
717 .RB ( MS_BIND )
718 was requested where
719 .I source
720 referred a mount namespace magic link (i.e., a
721 .IR /proc/ pid /ns/mnt
722 magic link or a bind mount to such a link)
723 and the propagation type of the parent mount of
724 .I target
726 .BR MS_SHARED ,
727 .\" See commit 8823c079ba7136dc1948d6f6dcb5f8022bde438e
728 but propagation of the requested bind mount could lead to a circular
729 dependency that might prevent the mount namespace from ever being freed.
731 .B EINVAL
732 .I mountflags
733 includes more than one of
734 .BR MS_SHARED ,
735 .BR MS_PRIVATE ,
736 .BR MS_SLAVE ,
738 .BR MS_UNBINDABLE .
740 .B EINVAL
741 .I mountflags
742 includes
743 .BR MS_SHARED ,
744 .BR MS_PRIVATE ,
745 .BR MS_SLAVE ,
747 .B MS_UNBINDABLE
748 and also includes a flag other than
749 .B MS_REC
751 .BR MS_SILENT .
753 .B EINVAL
754 An attempt was made to bind mount an unbindable mount.
756 .B EINVAL
757 In an unprivileged mount namespace
758 (i.e., a mount namespace owned by a user namespace
759 that was created by an unprivileged user),
760 a bind mount operation
761 .RB ( MS_BIND )
762 was attempted without specifying
763 .RB ( MS_REC ),
764 which would have revealed the filesystem tree underneath one of
765 the submounts of the directory being bound.
767 .B ELOOP
768 Too many links encountered during pathname resolution.
770 .B ELOOP
771 A move operation was attempted, and
772 .I target
773 is a descendant of
774 .IR source .
776 .B EMFILE
777 (In case no block device is required:)
778 Table of dummy devices is full.
780 .B ENAMETOOLONG
781 A pathname was longer than
782 .BR MAXPATHLEN .
784 .B ENODEV
785 .I filesystemtype
786 not configured in the kernel.
788 .B ENOENT
789 A pathname was empty or had a nonexistent component.
791 .B ENOMEM
792 The kernel could not allocate a free page to copy filenames or data into.
794 .B ENOTBLK
795 .I source
796 is not a block device (and a device was required).
798 .B ENOTDIR
799 .IR target ,
800 or a prefix of
801 .IR source ,
802 is not a directory.
804 .B ENXIO
805 The major number of the block device
806 .I source
807 is out of range.
809 .B EPERM
810 The caller does not have the required privileges.
812 .B EPERM
813 An attempt was made to modify
814 .RB ( MS_REMOUNT )
816 .BR MS_RDONLY ,
817 .BR MS_NOSUID ,
819 .B MS_NOEXEC
820 flag, or one of the "atime" flags
821 .RB ( MS_NOATIME ,
822 .BR MS_NODIRATIME ,
823 .BR MS_RELATIME )
824 of an existing mount, but the mount is locked; see
825 .BR mount_namespaces (7).
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.
835 .SH STANDARDS
836 Linux.
837 .SH HISTORY
838 The definitions of
839 .BR MS_DIRSYNC ,
840 .BR MS_MOVE ,
841 .BR MS_PRIVATE ,
842 .BR MS_REC ,
843 .BR MS_RELATIME ,
844 .BR MS_SHARED ,
845 .BR MS_SLAVE ,
846 .BR MS_STRICTATIME ,
848 .B MS_UNBINDABLE
849 were added to glibc headers in glibc 2.12.
851 Since Linux 2.4 a single filesystem can be mounted at
852 multiple mount points, and multiple mounts can be stacked
853 on the same mount point.
854 .\" Multiple mounts on same mount point: since Linux 2.3.99pre7.
857 .I mountflags
858 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
859 in the top 16 bits.
860 (All of the other flags discussed in DESCRIPTION
861 occupy the low order 16 bits of
862 .IR mountflags .)
863 Specifying
864 .B MS_MGC_VAL
865 was required before Linux 2.4,
866 but since Linux 2.4 is no longer required and is ignored if specified.
868 The original
869 .B MS_SYNC
870 flag was renamed
871 .B MS_SYNCHRONOUS
872 in 1.1.69
873 when a different
874 .B MS_SYNC
875 was added to \fI<mman.h>\fP.
877 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
878 on a filesystem mounted with
879 .B MS_NOSUID
880 would fail with
881 .BR EPERM .
882 Since Linux 2.4 the set-user-ID and set-group-ID bits are
883 just silently ignored in this case.
884 .\" The change is in patch-2.4.0-prerelease.
886 .SH NOTES
887 .SS Mount namespaces
888 Starting with Linux 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 .B 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 .B 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 mounts
928 Each mount has a parent mount.
929 The overall parental relationship of all mounts defines
930 the single directory hierarchy seen by the processes within a mount namespace.
932 The parent of a new mount is defined when the mount is created.
933 In the usual case,
934 the parent of a new mount is the mount 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 mounts can be discovered via the
941 .IR /proc/ pid /mountinfo
942 file (see below).
944 .SS \fI/proc/\fPpid\fI/mounts\fP and \fI/proc/\fPpid\fI/mountinfo\fP
945 The Linux-specific
946 .IR /proc/ pid /mounts
947 file exposes the list of mounts in the mount
948 namespace of the process with the specified ID.
950 .IR /proc/ pid /mountinfo
951 file exposes even more information about mounts,
952 including the propagation type and mount ID information that makes it
953 possible to discover the parental relationship between mounts.
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 mount_setattr (2),
964 .BR pivot_root (2),
965 .BR umount (2),
966 .BR mount_namespaces (7),
967 .BR path_resolution (7),
968 .BR findmnt (8),
969 .BR lsblk (8),
970 .BR mount (8),
971 .BR umount (8)