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 2019-03-06 "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.
85 performs one of a number of general types of operation,
86 depending on the bits specified in
88 The choice of which operation to perform is determined by
89 testing the bits set in
91 with the tests being conducted in the order listed here:
93 Remount an existing mount:
103 Change the propagation type of an existing mount:
112 Move an existing mount to a new location:
119 includes none of the above flags.
121 Each of these operations is detailed later in this page.
122 Further flags may be specified in
124 to modify the behavior of
128 .SS Additional mount flags
129 The list below describes the additional flags that can be specified in
131 Note that some operation types ignore some or all of these flags,
132 as described later in this page.
134 .\" FIXME 2.6.25 Added MS_I_VERSION, which needs to be documented.
135 .\" commit 7a224228ed79d587ece2304869000aad1b8e97dd
136 .\" (This is a per-superblock flag)
139 .BR MS_DIRSYNC " (since Linux 2.5.19)"
140 Make directory changes on this filesystem synchronous.
141 (This property can be obtained for individual directories
145 .BR MS_LAZYTIME " (since Linux 4.0)"
146 .\" commit 0ae45f63d4ef8d8eeec49c7d8b44a1775fff13e8
147 .\" commit fe032c422c5ba562ba9c2d316f55e258e03259c6
148 .\" commit a26f49926da938f47561f386be56a83dd37a496d
149 Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
150 by maintaining these changes only in memory.
151 The on-disk timestamps are updated only when:
154 the inode needs to be updated for some change unrelated to file timestamps;
156 the application employs
162 an undeleted inode is evicted from memory; or
164 more than 24 hours have passed since the inode was written to disk.
167 This mount option significantly reduces writes
168 needed to update the inode's timestamps, especially mtime and atime.
169 However, in the event of a system crash, the atime and mtime fields
170 on disk might be out of date by up to 24 hours.
172 Examples of workloads where this option could be of significant benefit
173 include frequent random writes to preallocated files,
174 as well as cases where the
176 mount option is also enabled.
177 (The advantage of combining
183 will return the correctly updated atime, but the atime updates
184 will be flushed to disk only in the cases listed above.)
187 Permit mandatory locking on files in this filesystem.
188 (Mandatory locking must still be enabled on a per-file basis,
192 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
193 this mount option requires the
195 capability and a kernel configured with the
196 .B CONFIG_MANDATORY_FILE_LOCKING
200 Do not update access times for (all types of) files on this filesystem.
203 Do not allow access to devices (special files) on this filesystem.
206 Do not update access times for directories on this filesystem.
207 This flag provides a subset of the functionality provided by
215 Do not allow programs to be executed from this filesystem.
216 .\" (Possibly useful for a filesystem that contains non-Linux executables.
217 .\" Often used as a security feature, e.g., to make sure that restricted
218 .\" users cannot execute files uploaded using ftp or so.)
221 Do not honor set-user-ID and set-group-ID bits or file capabilities
222 when executing programs from this filesystem.
223 .\" (This is a security feature to prevent users executing set-user-ID and
224 .\" set-group-ID programs from removable disk devices.)
227 Mount filesystem read-only.
229 .BR MS_REC " (since Linux 2.4.11)"
230 Used in conjunction with
232 to create a recursive bind mount,
233 and in conjunction with the propagation type flags to recursively change
234 the propagation type of all of the mounts in a subtree.
235 See below for further details.
237 .BR MS_RELATIME " (since Linux 2.6.20)"
238 When a file on this filesystem is accessed,
239 update the file's last access time (atime) only if the current value
240 of atime is less than or equal to the file's last modification time (mtime)
241 or last status change time (ctime).
242 This option is useful for programs, such as
244 that need to know when a file has been read since it was last modified.
245 Since Linux 2.6.30, the kernel defaults to the behavior provided
248 was specified), and the
250 flag is required to obtain traditional semantics.
251 In addition, since Linux 2.6.30,
252 the file's last access time is always updated if it
253 is more than 1 day old.
254 .\" Matthew Garrett notes in the patch that added this behavior
255 .\" that this lets utilities such as tmpreaper (which deletes
256 .\" files based on last access time) work correctly.
258 .BR MS_SILENT " (since Linux 2.6.17)"
259 Suppress the display of certain
261 warning messages in the kernel log.
262 This flag supersedes the misnamed and obsolete
264 flag (available since Linux 2.4.12), which has the same meaning.
266 .BR MS_STRICTATIME " (since Linux 2.6.30)"
267 Always update the last access time (atime) when files on this
268 filesystem are accessed.
269 (This was the default behavior before Linux 2.6.30.)
270 Specifying this flag overrides the effect of setting the
277 Make writes on this filesystem synchronous (as though
282 was specified for all file opens to this filesystem).
284 From Linux 2.4 onward, some of the above flags are
285 settable on a per-mount basis,
286 while others apply to the superblock of the mounted filesystem,
287 meaning that all mounts of the same filesystem share those flags.
288 (Previously, all of the flags were per-superblock.)
290 The per-mount-point flags are as follows:
293 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
294 flags are settable on a per-mount-point basis.
304 The following flags are per-superblock:
311 .\" And MS_I_VERSION?
312 The initial settings of these flags are determined on the first
313 mount of the filesystem, and will be shared by all subsequent mounts
314 of the same filesystem.
315 Subsequently, the settings of the flags can be changed
316 via a remount operation (see below).
317 Such changes will be visible via all mount points associated
322 can be set or cleared on a per-mount-point basis as well as on
323 the underlying filesystem superblock.
324 The mounted filesystem will be writable only if neither the filesystem
325 nor the mountpoint are flagged as read-only.
327 .SS Remounting an existing mount
328 An existing mount may be remounted by specifying
332 This allows you to change the
336 of an existing mount without having to unmount and remount the filesystem.
338 should be the same value specified in the initial
346 arguments are ignored.
352 arguments should match the values used in the original
354 call, except for those parameters that are being deliberately changed.
361 .\" MS_LAZYTIME seems to be available only on a few filesystems,
362 .\" and on ext4, it seems (from experiment that this flag
363 .\" can only be enabled (but not disabled) on a remount.
364 .\" The following code in ext4_remount() (kernel 4.17) seems to
367 .\" if (*flags & SB_LAZYTIME)
368 .\" sb->s_flags |= SB_LAZYTIME;
378 (whose effect is to clear the
385 Attempts to change the setting of the
386 .\" See the definition of MS_RMT_MASK in include/uapi/linux/fs.h,
387 .\" which excludes MS_DIRSYNC and MS_SILENT, although SB_DIRSYNC
388 .\" and SB_SILENT are split out as per-superblock flags in do_mount()
389 .\" (Linux 4.17 source code)
393 flags during a remount are silently ignored.
394 Note that changes to per-superblock flags are visible via
395 all mount points of the associated filesystem
396 (because the per-superblock flags are shared by all mount points).
399 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
408 then the remount operation preserves the existing values of these flags
409 (rather than defaulting to
412 Since Linux 2.6.26, the
414 flag can be used with
416 to modify only the per-mount-point flags.
417 .\" See https://lwn.net/Articles/281157/
418 This is particularly useful for setting or clearing the "read-only"
419 flag on a mount point without changing the underlying filesystem.
426 MS_REMOUNT | MS_BIND | MS_RDONLY
430 will make access through this mountpoint read-only, without affecting
433 .SS Creating a bind mount
438 (available since Linux 2.4),
439 .\" since 2.4.0-test9
440 then perform a bind mount.
441 A bind mount makes a file or a directory subtree visible at
442 another point within the single directory hierarchy.
443 Bind mounts may cross filesystem boundaries and span
451 arguments are ignored.
453 The remaining bits (other than
455 described below) in the
457 argument are also ignored.
458 (The bind mount has the same mount options as
459 the underlying mount point.)
460 However, see the discussion of remounting above,
461 for a method of making an existing bind mount read-only.
463 By default, when a directory is bind mounted,
464 only that directory is mounted;
465 if there are any submounts under the directory tree,
466 they are not bind mounted.
469 flag is also specified, then a recursive bind mount operation is performed:
470 all submounts under the
472 subtree (other than unbindable mounts)
473 are also bind mounted at the corresponding location in the
477 .SS Changing the propagation type of an existing mount
486 (all available since Linux 2.6.15),
487 then the propagation type of an existing mount is changed.
488 If more than one of these flags is specified, an error results.
490 The only other flags that can be specified while changing
491 the propagation type are
493 (described below) and
502 arguments are ignored.
504 The meanings of the propagation type flags are as follows:
507 Make this mount point shared.
508 Mount and unmount events immediately under this mount point will propagate
509 to the other mount points that are members of this mount's peer group.
510 Propagation here means that the same mount or unmount will automatically
511 occur under all of the other mount points in the peer group.
512 Conversely, mount and unmount events that take place under
513 peer mount points will propagate to this mount point.
516 Make this mount point private.
517 Mount and unmount events do not propagate into or out of this mount point.
520 If this is a shared mount point that is a member of a peer group
521 that contains other members, convert it to a slave mount.
522 If this is a shared mount point that is a member of a peer group
523 that contains no other members, convert it to a private mount.
524 Otherwise, the propagation type of the mount point is left unchanged.
526 When a mount point is a slave,
527 mount and unmount events propagate into this mount point from
528 the (master) shared peer group of which it was formerly a member.
529 Mount and unmount events under this mount point do not propagate to any peer.
531 A mount point can be the slave of another peer group
532 while at the same time sharing mount and unmount events
533 with a peer group of which it is a member.
536 Make this mount unbindable.
537 This is like a private mount,
538 and in addition this mount can't be bind mounted.
539 When a recursive bind mount
545 flags) is performed on a directory subtree,
546 any unbindable mounts within the subtree are automatically pruned
547 (i.e., not replicated)
548 when replicating that subtree to produce the target subtree.
550 By default, changing the propagation type affects only the
555 flag is also specified in
557 then the propagation type of all mount points under
561 For further details regarding mount propagation types
562 (including the default propagation type assigned to new mounts), see
563 .BR mount_namespaces (7).
570 (available since Linux 2.4.18),
573 specifies an existing mount point and
575 specifies the new location to which that mount point is to be relocated.
576 The move is atomic: at no point is the subtree unmounted.
578 The remaining bits in the
580 argument are ignored, as are the
586 .SS Creating a new mount point
600 performs its default action: creating a new mount point.
602 specifies the source for the new mount point, and
604 specifies the directory at which to create the mount point.
610 arguments are employed, and further bits may be specified in
612 to modify the behavior of the call.
615 On success, zero is returned.
616 On error, \-1 is returned, and
618 is set appropriately.
620 The error values given below result from filesystem type independent
622 Each filesystem type may have its own special errors and its
623 own special behavior.
624 See the Linux kernel source code for details.
627 A component of a path was not searchable.
629 .BR path_resolution (7).)
632 Mounting a read-only filesystem was attempted without giving the
636 The file system may be read-only for various reasons, including:
637 it resides on a read-only optical disk;
638 it is resides on a device with a physical switch that has been set to
639 mark the device read-only;
640 the filesystem implementation was compiled with read-only support;
641 or errors were detected when initially mounting the filesystem,
642 so that it was marked read-only
643 and can't be remounted as read-write (until the errors are fixed).
645 Some filesystems instead return the error
647 on an attempt to mount a read-only filesystem.
652 is located on a filesystem mounted with the
655 .\" mtk: Probably: write permission is required for MS_BIND, with
656 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
659 An attempt was made to stack a new mount directly on
660 top of an existing mount point that was created in this
661 mount namespace with the same
668 cannot be remounted read-only,
669 because it still holds files open for writing.
672 One of the pointer arguments points outside the user address space.
676 had an invalid superblock.
683 was not already mounted on
691 was not a mount point, or was \(aq/\(aq.
695 includes more than one of
710 and also includes a flag other than
716 An attempt was made to bind mount an unbindable mount.
719 In an unprivileged mount namespace
720 (i.e., a mount namespace owned by a user namespace
721 that was created by an unprivileged user),
722 a bind mount operation
724 was attempted without specifying
726 which would have revealed the filesystem tree underneath one of
727 the submounts of the directory being bound.
730 Too many links encountered during pathname resolution.
733 A move operation was attempted, and
739 (In case no block device is required:)
740 Table of dummy devices is full.
743 A pathname was longer than
748 not configured in the kernel.
751 A pathname was empty or had a nonexistent component.
754 The kernel could not allocate a free page to copy filenames or data into.
758 is not a block device (and a device was required).
767 The major number of the block device
772 The caller does not have the required privileges.
775 Mounting a read-only filesystem was attempted without giving the
793 were added to glibc headers in version 2.12.
796 This function is Linux-specific and should not be used in
797 programs intended to be portable.
799 Since Linux 2.4 a single filesystem can be mounted at
800 multiple mount points, and multiple mounts can be stacked
801 on the same mount point.
802 .\" Multiple mounts on same mount point: since 2.3.99pre7.
806 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
808 (All of the other flags discussed in DESCRIPTION
809 occupy the low order 16 bits of
813 was required in kernel versions prior to 2.4,
814 but since Linux 2.4 is no longer required and is ignored if specified.
823 was added to \fI<mman.h>\fP.
825 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
826 on a filesystem mounted with
830 Since Linux 2.4 the set-user-ID and set-group-ID bits are
831 just silently ignored in this case.
832 .\" The change is in patch-2.4.0-prerelease.
834 .SS Per-process namespaces
835 Starting with kernel 2.4.19, Linux provides
836 per-process mount namespaces.
837 A mount namespace is the set of filesystem mounts that
838 are visible to a process.
839 Mount-point namespaces can be (and usually are)
840 shared between multiple processes,
841 and changes to the namespace (i.e., mounts and unmounts) by one process
842 are visible to all other processes sharing the same namespace.
843 (The pre-2.4.19 Linux situation can be considered as one in which
844 a single namespace was shared by every process on the system.)
846 A child process created by
848 shares its parent's mount namespace;
849 the mount namespace is preserved across an
852 A process can obtain a private mount namespace if:
853 it was created using the
857 in which case its new namespace is initialized to be a
859 of the namespace of the process that called
866 which causes the caller's mount namespace to obtain a private copy
867 of the namespace that it was previously sharing with other processes,
868 so that future mounts and unmounts by the caller are invisible
869 to other processes (except child processes that the caller
870 subsequently creates) and vice versa.
873 .I /proc/[pid]/mounts
874 file exposes the list of mount points in the mount
875 namespace of the process with the specified ID.
877 .I /proc/[pid]/mountinfo
878 file exposes even more information about mount points,
879 including the propagation type and mount ID information that makes it
880 possible to discover the parental relationship between mount points.
884 .BR mount_namespaces (7)
885 for details of these files.
888 .BR ioctl_iflags (2),
890 .BR mount_namespaces (7),
891 .BR path_resolution (7),