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>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
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.
20 .TH mount 2 (date) "Linux man-pages (unreleased)"
22 mount \- mount filesystem
25 .RI ( libc ", " \-lc )
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 );
36 attaches the filesystem specified by
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
44 Appropriate privilege (Linux: the
46 capability) is required to mount filesystems.
50 argument supported by the kernel are listed in
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
59 argument is interpreted by the different filesystems.
60 Typically it is a string of comma-separated options
61 understood by this filesystem.
64 for details of the options available for each filesystem type.
65 This argument may be specified as NULL, if there are no options.
69 performs one of a number of general types of operation,
70 depending on the bits specified in
72 The choice of which operation to perform is determined by
73 testing the bits set in
75 with the tests being conducted in the order listed here:
77 Remount an existing mount:
87 Change the propagation type of an existing mount:
96 Move an existing mount to a new location:
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
108 to modify the behavior of
112 .SS Additional mount flags
113 The list below describes the additional flags that can be specified in
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
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:
138 the inode needs to be updated for some change unrelated to file timestamps;
140 the application employs
146 an undeleted inode is evicted from memory; or
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
160 mount option is also enabled.
161 (The advantage of combining
167 will return the correctly updated atime, but the atime updates
168 will be flushed to disk only in the cases listed above.)
171 Permit mandatory locking on files in this filesystem.
172 (Mandatory locking must still be enabled on a per-file basis,
176 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
177 this mount option requires the
179 capability and a kernel configured with the
180 .B CONFIG_MANDATORY_FILE_LOCKING
182 Mandatory locking has been fully deprecated in Linux 5.15, so
183 this flag should be considered deprecated.
186 Do not update access times for (all types of) files on this filesystem.
189 Do not allow access to devices (special files) on this filesystem.
192 Do not update access times for directories on this filesystem.
193 This flag provides a subset of the functionality provided by
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.)
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 ,
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.)
219 Mount filesystem read-only.
221 .BR MS_REC " (since Linux 2.4.11)"
222 Used in conjunction with
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
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
240 was specified), and the
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
253 warning messages in the kernel log.
254 This flag supersedes the misnamed and obsolete
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
269 Make writes on this filesystem synchronous (as though
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,
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:
297 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
298 flags are settable on a per-mount-point basis.
300 Additionally, since Linux 2.6.16:
305 Additionally, since Linux 2.6.20:
308 The following flags are per-superblock:
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
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
336 This allows you to change the
340 of an existing mount without having to unmount and remount the filesystem.
342 should be the same value specified in the initial
350 arguments are ignored.
356 arguments should match the values used in the original
358 call, except for those parameters that are being deliberately changed.
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
371 .\" if (*flags & SB_LAZYTIME)
372 .\" sb->s_flags |= SB_LAZYTIME;
382 (whose effect is to clear the
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)
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).
403 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
412 then the remount operation preserves the existing values of these flags
413 (rather than defaulting to
416 Since Linux 2.6.26, the
418 flag can be used with
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.
430 MS_REMOUNT | MS_BIND | MS_RDONLY
434 will make access through this mountpoint read-only, without affecting
437 .SS Creating a bind mount
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
455 arguments are ignored.
457 The remaining bits (other than
459 described below) in the
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.
473 flag is also specified, then a recursive bind mount operation is performed:
474 all submounts under the
476 subtree (other than unbindable mounts)
477 are also bind mounted at the corresponding location in the
481 .SS Changing the propagation type of an existing mount
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
497 (described below) and
506 arguments are ignored.
508 The meanings of the propagation type flags are as follows:
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.
520 Make this mount private.
521 Mount and unmount events do not propagate into or out of this mount.
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.
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
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
559 flag is also specified in
561 then the propagation type of all mounts under
565 For further details regarding mount propagation types
566 (including the default propagation type assigned to new mounts), see
567 .BR mount_namespaces (7).
574 (available since Linux 2.4.18),
577 specifies an existing mount and
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
584 argument are ignored, as are the
590 .SS Creating a new mount
604 performs its default action: creating a new mount.
606 specifies the source for the new mount, and
608 specifies the directory at which to create the mount point.
614 arguments are employed, and further bits may be specified in
616 to modify the behavior of the call.
619 On success, zero is returned.
620 On error, \-1 is returned, and
622 is set to indicate the error.
624 The error values given below result from filesystem type independent
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.
631 A component of a path was not searchable.
633 .BR path_resolution (7).)
636 Mounting a read-only filesystem was attempted without giving the
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
651 on an attempt to mount a read-only filesystem.
656 is located on a filesystem mounted with the
659 .\" mtk: Probably: write permission is required for MS_BIND, with
660 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
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
672 cannot be remounted read-only,
673 because it still holds files open for writing.
676 One of the pointer arguments points outside the user address space.
680 had an invalid superblock.
687 was not already mounted on
693 was attempted, but the mount tree under
695 includes unbindable mounts and
697 is a mount that has propagation type
703 was attempted, but the parent mount of
705 mount has propagation type
713 was not a mount, or was \[aq]/\[aq].
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
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.
733 includes more than one of
748 and also includes a flag other than
754 An attempt was made to bind mount an unbindable mount.
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
762 was attempted without specifying
764 which would have revealed the filesystem tree underneath one of
765 the submounts of the directory being bound.
768 Too many links encountered during pathname resolution.
771 A move operation was attempted, and
777 (In case no block device is required:)
778 Table of dummy devices is full.
781 A pathname was longer than
786 not configured in the kernel.
789 A pathname was empty or had a nonexistent component.
792 The kernel could not allocate a free page to copy filenames or data into.
796 is not a block device (and a device was required).
805 The major number of the block device
810 The caller does not have the required privileges.
813 An attempt was made to modify
820 flag, or one of the "atime" flags
824 of an existing mount, but the mount is locked; see
825 .BR mount_namespaces (7).
828 Mounting a read-only filesystem was attempted without giving the
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.
858 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
860 (All of the other flags discussed in DESCRIPTION
861 occupy the low order 16 bits of
865 was required before Linux 2.4,
866 but since Linux 2.4 is no longer required and is ignored if specified.
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
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.
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
900 shares its parent's mount namespace;
901 the mount namespace is preserved across an
904 A process can obtain a private mount namespace if:
905 it was created using the
909 in which case its new namespace is initialized to be a
911 of the namespace of the process that called
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.
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
940 The parental relationship between mounts can be discovered via the
941 .IR /proc/ pid /mountinfo
944 .SS \fI/proc/\fPpid\fI/mounts\fP and \fI/proc/\fPpid\fI/mountinfo\fP
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.
957 .BR mount_namespaces (7)
958 for details of this file.
962 .BR ioctl_iflags (2),
963 .BR mount_setattr (2),
966 .BR mount_namespaces (7),
967 .BR path_resolution (7),