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 .\" %%%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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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.
40 .TH MOUNT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
42 mount \- mount filesystem
45 .B "#include <sys/mount.h>"
47 .BI "int mount(const char *" source ", const char *" target ,
48 .BI " const char *" filesystemtype ", unsigned long " mountflags ,
49 .BI " const void *" data );
53 attaches the filesystem specified by
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
61 Appropriate privilege (Linux: the
63 capability) is required to mount filesystems.
67 argument supported by the kernel are listed in
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
76 argument is interpreted by the different filesystems.
77 Typically it is a string of comma-separated options
78 understood by this filesystem.
81 for details of the options available for each filesystem type.
82 This argument may be specified as NULL, if there are no options.
86 performs one of a number of general types of operation,
87 depending on the bits specified in
89 The choice of which operation to perform is determined by
90 testing the bits set in
92 with the tests being conducted in the order listed here:
94 Remount an existing mount:
104 Change the propagation type of an existing mount:
113 Move an existing mount to a new location:
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
125 to modify the behavior of
129 .SS Additional mount flags
130 The list below describes the additional flags that can be specified in
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
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:
155 the inode needs to be updated for some change unrelated to file timestamps;
157 the application employs
163 an undeleted inode is evicted from memory; or
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
177 mount option is also enabled.
178 (The advantage of combining
184 will return the correctly updated atime, but the atime updates
185 will be flushed to disk only in the cases listed above.)
188 Permit mandatory locking on files in this filesystem.
189 (Mandatory locking must still be enabled on a per-file basis,
193 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
194 this mount option requires the
196 capability and a kernel configured with the
197 .B CONFIG_MANDATORY_FILE_LOCKING
201 Do not update access times for (all types of) files on this filesystem.
204 Do not allow access to devices (special files) on this filesystem.
207 Do not update access times for directories on this filesystem.
208 This flag provides a subset of the functionality provided by
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.)
222 Do not honor set-user-ID and set-group-ID bits or file capabilities
223 when executing programs from this filesystem.
224 .\" (This is a security feature to prevent users executing set-user-ID and
225 .\" set-group-ID programs from removable disk devices.)
228 Mount filesystem read-only.
230 .BR MS_REC " (since Linux 2.4.11)"
231 Used in conjunction with
233 to create a recursive bind mount,
234 and in conjunction with the propagation type flags to recursively change
235 the propagation type of all of the mounts in a subtree.
236 See below for further details.
238 .BR MS_RELATIME " (since Linux 2.6.20)"
239 When a file on this filesystem is accessed,
240 update the file's last access time (atime) only if the current value
241 of atime is less than or equal to the file's last modification time (mtime)
242 or last status change time (ctime).
243 This option is useful for programs, such as
245 that need to know when a file has been read since it was last modified.
246 Since Linux 2.6.30, the kernel defaults to the behavior provided
249 was specified), and the
251 flag is required to obtain traditional semantics.
252 In addition, since Linux 2.6.30,
253 the file's last access time is always updated if it
254 is more than 1 day old.
255 .\" Matthew Garrett notes in the patch that added this behavior
256 .\" that this lets utilities such as tmpreaper (which deletes
257 .\" files based on last access time) work correctly.
259 .BR MS_SILENT " (since Linux 2.6.17)"
260 Suppress the display of certain
262 warning messages in the kernel log.
263 This flag supersedes the misnamed and obsolete
265 flag (available since Linux 2.4.12), which has the same meaning.
267 .BR MS_STRICTATIME " (since Linux 2.6.30)"
268 Always update the last access time (atime) when files on this
269 filesystem are accessed.
270 (This was the default behavior before Linux 2.6.30.)
271 Specifying this flag overrides the effect of setting the
278 Make writes on this filesystem synchronous (as though
283 was specified for all file opens to this filesystem).
285 .BR MS_NOSYMFOLLOW " (since Linux 5.10)"
286 .\" dab741e0e02bd3c4f5e2e97be74b39df2523fc6e
287 Do not follow symbolic links when resolving paths.
288 Symbolic links can still be created,
295 all still work properly.
297 From Linux 2.4 onward, some of the above flags are
298 settable on a per-mount basis,
299 while others apply to the superblock of the mounted filesystem,
300 meaning that all mounts of the same filesystem share those flags.
301 (Previously, all of the flags were per-superblock.)
303 The per-mount-point flags are as follows:
306 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
307 flags are settable on a per-mount-point basis.
309 Additionally, since Linux 2.6.16:
314 Additionally, since Linux 2.6.20:
317 The following flags are per-superblock:
324 .\" And MS_I_VERSION?
325 The initial settings of these flags are determined on the first
326 mount of the filesystem, and will be shared by all subsequent mounts
327 of the same filesystem.
328 Subsequently, the settings of the flags can be changed
329 via a remount operation (see below).
330 Such changes will be visible via all mount points associated
335 can be set or cleared on a per-mount-point basis as well as on
336 the underlying filesystem superblock.
337 The mounted filesystem will be writable only if neither the filesystem
338 nor the mountpoint are flagged as read-only.
340 .SS Remounting an existing mount
341 An existing mount may be remounted by specifying
345 This allows you to change the
349 of an existing mount without having to unmount and remount the filesystem.
351 should be the same value specified in the initial
359 arguments are ignored.
365 arguments should match the values used in the original
367 call, except for those parameters that are being deliberately changed.
374 .\" MS_LAZYTIME seems to be available only on a few filesystems,
375 .\" and on ext4, it seems (from experiment that this flag
376 .\" can only be enabled (but not disabled) on a remount.
377 .\" The following code in ext4_remount() (kernel 4.17) seems to
380 .\" if (*flags & SB_LAZYTIME)
381 .\" sb->s_flags |= SB_LAZYTIME;
391 (whose effect is to clear the
398 Attempts to change the setting of the
399 .\" See the definition of MS_RMT_MASK in include/uapi/linux/fs.h,
400 .\" which excludes MS_DIRSYNC and MS_SILENT, although SB_DIRSYNC
401 .\" and SB_SILENT are split out as per-superblock flags in do_mount()
402 .\" (Linux 4.17 source code)
406 flags during a remount are silently ignored.
407 Note that changes to per-superblock flags are visible via
408 all mount points of the associated filesystem
409 (because the per-superblock flags are shared by all mount points).
412 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
421 then the remount operation preserves the existing values of these flags
422 (rather than defaulting to
425 Since Linux 2.6.26, the
427 flag can be used with
429 to modify only the per-mount-point flags.
430 .\" See https://lwn.net/Articles/281157/
431 This is particularly useful for setting or clearing the "read-only"
432 flag on a mount point without changing the underlying filesystem.
439 MS_REMOUNT | MS_BIND | MS_RDONLY
443 will make access through this mountpoint read-only, without affecting
446 .SS Creating a bind mount
451 (available since Linux 2.4),
452 .\" since 2.4.0-test9
453 then perform a bind mount.
454 A bind mount makes a file or a directory subtree visible at
455 another point within the single directory hierarchy.
456 Bind mounts may cross filesystem boundaries and span
464 arguments are ignored.
466 The remaining bits (other than
468 described below) in the
470 argument are also ignored.
471 (The bind mount has the same mount options as
472 the underlying mount point.)
473 However, see the discussion of remounting above,
474 for a method of making an existing bind mount read-only.
476 By default, when a directory is bind mounted,
477 only that directory is mounted;
478 if there are any submounts under the directory tree,
479 they are not bind mounted.
482 flag is also specified, then a recursive bind mount operation is performed:
483 all submounts under the
485 subtree (other than unbindable mounts)
486 are also bind mounted at the corresponding location in the
490 .SS Changing the propagation type of an existing mount
499 (all available since Linux 2.6.15),
500 then the propagation type of an existing mount is changed.
501 If more than one of these flags is specified, an error results.
503 The only other flags that can be specified while changing
504 the propagation type are
506 (described below) and
515 arguments are ignored.
517 The meanings of the propagation type flags are as follows:
520 Make this mount point shared.
521 Mount and unmount events immediately under this mount point will propagate
522 to the other mount points that are members of this mount's peer group.
523 Propagation here means that the same mount or unmount will automatically
524 occur under all of the other mount points in the peer group.
525 Conversely, mount and unmount events that take place under
526 peer mount points will propagate to this mount point.
529 Make this mount point private.
530 Mount and unmount events do not propagate into or out of this mount point.
533 If this is a shared mount point that is a member of a peer group
534 that contains other members, convert it to a slave mount.
535 If this is a shared mount point that is a member of a peer group
536 that contains no other members, convert it to a private mount.
537 Otherwise, the propagation type of the mount point is left unchanged.
539 When a mount point is a slave,
540 mount and unmount events propagate into this mount point from
541 the (master) shared peer group of which it was formerly a member.
542 Mount and unmount events under this mount point do not propagate to any peer.
544 A mount point can be the slave of another peer group
545 while at the same time sharing mount and unmount events
546 with a peer group of which it is a member.
549 Make this mount unbindable.
550 This is like a private mount,
551 and in addition this mount can't be bind mounted.
552 When a recursive bind mount
558 flags) is performed on a directory subtree,
559 any unbindable mounts within the subtree are automatically pruned
560 (i.e., not replicated)
561 when replicating that subtree to produce the target subtree.
563 By default, changing the propagation type affects only the
568 flag is also specified in
570 then the propagation type of all mount points under
574 For further details regarding mount propagation types
575 (including the default propagation type assigned to new mounts), see
576 .BR mount_namespaces (7).
583 (available since Linux 2.4.18),
586 specifies an existing mount point and
588 specifies the new location to which that mount point is to be relocated.
589 The move is atomic: at no point is the subtree unmounted.
591 The remaining bits in the
593 argument are ignored, as are the
599 .SS Creating a new mount point
613 performs its default action: creating a new mount point.
615 specifies the source for the new mount point, and
617 specifies the directory at which to create the mount point.
623 arguments are employed, and further bits may be specified in
625 to modify the behavior of the call.
628 On success, zero is returned.
629 On error, \-1 is returned, and
631 is set to indicate the error.
633 The error values given below result from filesystem type independent
635 Each filesystem type may have its own special errors and its
636 own special behavior.
637 See the Linux kernel source code for details.
640 A component of a path was not searchable.
642 .BR path_resolution (7).)
645 Mounting a read-only filesystem was attempted without giving the
649 The filesystem may be read-only for various reasons, including:
650 it resides on a read-only optical disk;
651 it is resides on a device with a physical switch that has been set to
652 mark the device read-only;
653 the filesystem implementation was compiled with read-only support;
654 or errors were detected when initially mounting the filesystem,
655 so that it was marked read-only
656 and can't be remounted as read-write (until the errors are fixed).
658 Some filesystems instead return the error
660 on an attempt to mount a read-only filesystem.
665 is located on a filesystem mounted with the
668 .\" mtk: Probably: write permission is required for MS_BIND, with
669 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
672 An attempt was made to stack a new mount directly on
673 top of an existing mount point that was created in this
674 mount namespace with the same
681 cannot be remounted read-only,
682 because it still holds files open for writing.
685 One of the pointer arguments points outside the user address space.
689 had an invalid superblock.
696 was not already mounted on
702 was attempted, but the mount tree under
704 includes unbindable mounts and
706 is a mount point that has propagation type
712 was attempted, but the parent mount of
714 mount has propagation type
722 was not a mount point, or was \(aq/\(aq.
729 referred a mount namespace magic link (i.e., a
730 .I /proc/[pid]/ns/mnt
731 magic link or a bind mount to such a link)
732 and the propagation type of the parent mount of
736 .\" See commit 8823c079ba7136dc1948d6f6dcb5f8022bde438e
737 but propagation of the requested bind mount could lead to a circular
738 dependency that might prevent the mount namespace from ever being freed.
742 includes more than one of
757 and also includes a flag other than
763 An attempt was made to bind mount an unbindable mount.
766 In an unprivileged mount namespace
767 (i.e., a mount namespace owned by a user namespace
768 that was created by an unprivileged user),
769 a bind mount operation
771 was attempted without specifying
773 which would have revealed the filesystem tree underneath one of
774 the submounts of the directory being bound.
777 Too many links encountered during pathname resolution.
780 A move operation was attempted, and
786 (In case no block device is required:)
787 Table of dummy devices is full.
790 A pathname was longer than
795 not configured in the kernel.
798 A pathname was empty or had a nonexistent component.
801 The kernel could not allocate a free page to copy filenames or data into.
805 is not a block device (and a device was required).
814 The major number of the block device
819 The caller does not have the required privileges.
822 Mounting a read-only filesystem was attempted without giving the
840 were added to glibc headers in version 2.12.
843 This function is Linux-specific and should not be used in
844 programs intended to be portable.
846 Since Linux 2.4 a single filesystem can be mounted at
847 multiple mount points, and multiple mounts can be stacked
848 on the same mount point.
849 .\" Multiple mounts on same mount point: since 2.3.99pre7.
853 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
855 (All of the other flags discussed in DESCRIPTION
856 occupy the low order 16 bits of
860 was required in kernel versions prior to 2.4,
861 but since Linux 2.4 is no longer required and is ignored if specified.
870 was added to \fI<mman.h>\fP.
872 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
873 on a filesystem mounted with
877 Since Linux 2.4 the set-user-ID and set-group-ID bits are
878 just silently ignored in this case.
879 .\" The change is in patch-2.4.0-prerelease.
882 Starting with kernel 2.4.19, Linux provides mount namespaces.
883 A mount namespace is the set of filesystem mounts that
884 are visible to a process.
885 Mount namespaces can be (and usually are)
886 shared between multiple processes,
887 and changes to the namespace (i.e., mounts and unmounts) by one process
888 are visible to all other processes sharing the same namespace.
889 (The pre-2.4.19 Linux situation can be considered as one in which
890 a single namespace was shared by every process on the system.)
892 A child process created by
894 shares its parent's mount namespace;
895 the mount namespace is preserved across an
898 A process can obtain a private mount namespace if:
899 it was created using the
903 in which case its new namespace is initialized to be a
905 of the namespace of the process that called
912 which causes the caller's mount namespace to obtain a private copy
913 of the namespace that it was previously sharing with other processes,
914 so that future mounts and unmounts by the caller are invisible
915 to other processes (except child processes that the caller
916 subsequently creates) and vice versa.
918 For further details on mount namespaces, see
919 .BR mount_namespaces (7).
921 .SS Parental relationship between mount points
922 Each mount point has a parent mount point.
923 The overall parental relationship of all mount points defines
924 the single directory hierarchy seen by the processes within a mount namespace.
926 The parent of a new mount point is defined when the mount point is created.
928 the parent of a new mount is the mount point of the filesystem
929 containing the directory or file at which the new mount is attached.
930 In the case where a new mount is stacked on top of an existing mount,
931 the parent of the new mount is the previous mount that was stacked
934 The parental relationship between mount points can be discovered via the
935 .I /proc/[pid]/mountinfo
938 .SS /proc/[pid]/mounts and /proc/[pid]/mountinfo
940 .I /proc/[pid]/mounts
941 file exposes the list of mount points in the mount
942 namespace of the process with the specified ID.
944 .I /proc/[pid]/mountinfo
945 file exposes even more information about mount points,
946 including the propagation type and mount ID information that makes it
947 possible to discover the parental relationship between mount points.
951 .BR mount_namespaces (7)
952 for details of this file.
956 .BR ioctl_iflags (2),
959 .BR mount_namespaces (7),
960 .BR path_resolution (7),