]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/mount.2
mount.2: Restructure discussion of 'mountflags' into functional groups
[thirdparty/man-pages.git] / man2 / mount.2
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 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1996-11-04 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2001-10-13 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added note on historical behavior of MS_NOSUID
30 .\" Modified 2002-05-16 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Extensive changes and additions
32 .\" Modified 2002-05-27 by aeb
33 .\" Modified 2002-06-11 by Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Enhanced descriptions of MS_MOVE, MS_BIND, and MS_REMOUNT
35 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" 2005-05-18, mtk, Added MNT_EXPIRE, plus a few other tidy-ups.
37 .\" 2008-10-06, mtk: move umount*() material into separate umount.2 page.
38 .\" 2008-10-06, mtk: Add discussion of namespaces.
39 .\"
40 .TH MOUNT 2 2016-03-15 "Linux" "Linux Programmer's Manual"
41 .SH NAME
42 mount \- mount filesystem
43 .SH SYNOPSIS
44 .nf
45 .B "#include <sys/mount.h>"
46 .sp
47 .BI "int mount(const char *" source ", const char *" target ,
48 .BI " const char *" filesystemtype ", unsigned long " mountflags ,
49 .BI " const void *" data );
50 .fi
51 .SH DESCRIPTION
52 .BR mount ()
53 attaches the filesystem specified by
54 .I source
55 (which is often a pathname referring to a device,
56 but can also be the pathname of a directory or file,
57 or a dummy string) to the location (a directory or file)
58 specified by the pathname in
59 .IR target .
60
61 Appropriate privilege (Linux: the
62 .B CAP_SYS_ADMIN
63 capability) is required to mount filesystems.
64
65 Values for the
66 .I filesystemtype
67 argument supported by the kernel are listed in
68 .I /proc/filesystems
69 (e.g., "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse",
70 "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660").
71 Further types may become available when the appropriate modules
72 are loaded.
73
74 The
75 .I data
76 argument is interpreted by the different filesystems.
77 Typically it is a string of comma-separated options
78 understood by this filesystem.
79 See
80 .BR mount (8)
81 for details of the options available for each filesystem type.
82
83 A call to
84 .BR mount ()
85 performs one of a number of general types of operation.
86 depending on the bits specified in
87 .IR mountflags .
88 The choice of operation is determined by testing the bits set in
89 .IR mountflags ,
90 with the tests being conducted in the order listed here:
91 .IP * 3
92 Remount an existing mount:
93 .IR mountflags
94 includes
95 .BR MS_REMOUNT .
96 .IP *
97 Create a bind mount:
98 .IR mountflags
99 includes
100 .BR MS_BIND .
101 .IP *
102 Change the propagation type of an existing mount:
103 .IR mountflags
104 includes one of
105 .BR MS_SHARED ,
106 .BR MS_PRIVATE ,
107 .BR MS_SLAVE ,
108 or
109 .BR MS_UNBINDABLE .
110 .IP *
111 Move an existing mount to a new location:
112 .IR mountflags
113 includes
114 .BR MS_MOVE .
115 .IP *
116 Create a new mount:
117 .IR mountflags
118 includes none of the above flags.
119 .PP
120 Each of these operations is detailed later in this page.
121 Further flags may be specified in
122 .IR mountflags
123 to modify the behavior of
124 .BR mount (),
125 as described below.
126 .\"
127 .SS Additional mount flags
128 The list below describes the additional flags that can be specified in
129 .IR mountflags .
130 Note that some operation types ignore some or all of these flags,
131 as described later in this page.
132 .\"
133 .\" FIXME 2.6.25 Added MS_I_VERSION, which needs to be documented.
134 .\"
135 .TP
136 .BR MS_DIRSYNC " (since Linux 2.5.19)"
137 Make directory changes on this filesystem synchronous.
138 (This property can be obtained for individual directories
139 or subtrees using
140 .BR chattr (1).)
141 .TP
142 .BR MS_LAZYTIME " (since Linux 4.0)"
143 .\" commit 0ae45f63d4ef8d8eeec49c7d8b44a1775fff13e8
144 .\" commit fe032c422c5ba562ba9c2d316f55e258e03259c6
145 .\" commit a26f49926da938f47561f386be56a83dd37a496d
146 Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
147 by maintaining these changes only in memory.
148 The on-disk timestamps are updated only when:
149 .RS
150 .IP (a) 5
151 the inode needs to be updated for some change unrelated to file timestamps;
152 .IP (b)
153 the application employs
154 .BR fsync (2),
155 .BR syncfs (2),
156 or
157 .BR sync (2);
158 .IP (c)
159 an undeleted inode is evicted from memory; or
160 .IP (d)
161 more than 24 hours have passed since the inode was written to disk.
162 .RE
163 .IP
164 This mount option significantly reduces writes
165 needed to update the inode's timestamps, especially mtime and atime.
166 However, in the event of a system crash, the atime and mtime fields
167 on disk might be out of date by up to 24 hours.
168
169 Examples of workloads where this option could be of significant benefit
170 include frequent random writes to preallocated files,
171 as well as cases where the
172 .B MS_STRICTATIME
173 mount option is also enabled.
174 (The advantage of combining
175 .BR MS_STRICTATIME
176 and
177 .BR MS_LAZYTIME
178 is that
179 .BR stat (2)
180 will return the correctly updated atime, but the atime updates
181 will be flushed to disk only in the cases listed above.)
182 .TP
183 .B MS_MANDLOCK
184 Permit mandatory locking on files in this filesystem.
185 (Mandatory locking must still be enabled on a per-file basis,
186 as described in
187 .BR fcntl (2).)
188 Since Linux 4.5,
189 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
190 this mount option requires the
191 .B CAP_SYS_ADMIN
192 capability.
193 .\" FIXME Describe the MS_MOVE flag in more detail
194 .TP
195 .B MS_NOATIME
196 Do not update access times for (all types of) files on this filesystem.
197 .TP
198 .B MS_NODEV
199 Do not allow access to devices (special files) on this filesystem.
200 .TP
201 .B MS_NODIRATIME
202 Do not update access times for directories on this filesystem.
203 This flag provides a subset of the functionality provided by
204 .BR MS_NOATIME ;
205 that is,
206 .BR MS_NOATIME
207 implies
208 .BR MS_NODIRATIME .
209 .TP
210 .B MS_NOEXEC
211 Do not allow programs to be executed from this filesystem.
212 .\" (Possibly useful for a filesystem that contains non-Linux executables.
213 .\" Often used as a security feature, e.g., to make sure that restricted
214 .\" users cannot execute files uploaded using ftp or so.)
215 .TP
216 .B MS_NOSUID
217 Do not honor set-user-ID and set-group-ID bits or file capabilities
218 when executing programs from this filesystem.
219 .\" (This is a security feature to prevent users executing set-user-ID and
220 .\" set-group-ID programs from removable disk devices.)
221 .TP
222 .B MS_RDONLY
223 Mount filesystem read-only.
224 .\"
225 .\" FIXME Document MS_REC, available since 2.4.11.
226 .\" This flag has meaning in conjunction with MS_BIND and
227 .\" also with the shared subtree flags.
228 .TP
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 .BR 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.
249 .TP
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 .BR MS_VERBOSE
256 flag (available since Linux 2.4.12), which has the same meaning.
257 .TP
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 .BR MS_NOATIME
264 and
265 .BR MS_RELATIME
266 flags.
267 .TP
268 .B MS_SYNCHRONOUS
269 Make writes on this filesystem synchronous (as though
270 the
271 .B O_SYNC
272 flag to
273 .BR open (2)
274 was specified for all file opens to this filesystem).
275 .PP
276 From Linux 2.4 onward, the
277 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
278 flags are settable on a per-mount-point basis.
279 From kernel 2.6.16 onward,
280 .B MS_NOATIME
281 and
282 .B MS_NODIRATIME
283 are also settable on a per-mount-point basis.
284 The
285 .B MS_RELATIME
286 flag is also settable on a per-mount-point basis.
287 .\"
288 .SS Remounting an existing mount
289 An existing mount may be remounted by specifying
290 .B MS_REMOUNT
291 in
292 .IR mountflags .
293 This allows you to change the
294 .I mountflags
295 and
296 .I data
297 of an existing mount without having to unmount and remount the filesystem.
298 .I target
299 should be the same value specified in the initial
300 .BR mount ()
301 call;
302 .I source
303 and
304 .I filesystemtype
305 are ignored.
306
307 The
308 .I mountflags
309 and
310 .I data
311 arguments should match the values used in the original
312 .BR mount ()
313 call, except for those parameters that are being deliberately changed.
314
315 The following
316 .I mountflags
317 can be changed:
318 .BR MS_RDONLY ,
319 .BR MS_SYNCHRONOUS ,
320 and
321 .BR MS_MANDLOCK ;
322 before kernel 2.6.16, the following could also be changed:
323 .B MS_NOATIME
324 and
325 .BR MS_NODIRATIME ;
326 and, additionally, before kernel 2.4.10, the following could also be changed:
327 .BR MS_NOSUID ,
328 .BR MS_NODEV ,
329 and
330 .BR MS_NOEXEC .
331
332 Since Linux 3.17,
333 .\" commit ffbc6f0ead47fa5a1dc9642b0331cb75c20a640e
334 if none of
335 .BR MS_NOATIME ,
336 .BR MS_NODIRATIME ,
337 .BR MS_RELATIME ,
338 or
339 .BR MS_STRICTATIME
340 is specified in
341 .IR mountflags ,
342 then the remount operation preserves the existing values of these flags
343 (rather than defaulting to
344 .BR MS_RELATIME ).
345
346 Since Linux 2.6.26, this flag can also be used to make
347 .\" See https://lwn.net/Articles/281157/
348 an existing bind mount read-only by specifying
349 .IR mountflags
350 as:
351
352 MS_REMOUNT | MS_BIND | MS_RDONLY
353
354 Note that only the
355 .BR MS_RDONLY
356 setting of the bind mount can be changed in this manner.
357 .\"
358 .SS Creating a bind mount
359 If
360 .I mountflags
361 includes
362 .BR MS_BIND
363 (available since Linux 2.4),
364 .\" since 2.4.0-test9
365 then perform a bind mount.
366 A bind mount makes a file or a directory subtree visible at
367 another point within the single directory hierarchy.
368 Bind mounts may cross filesystem boundaries and span
369 .BR chroot (2)
370 jails.
371
372 The
373 .IR filesystemtype
374 and
375 .IR data
376 arguments are ignored.
377
378 The remaining bits in the
379 .I mountflags
380 argument are also ignored, with the exception of
381 .BR MS_REC .
382 (The bind mount has the same mount options as
383 the underlying mount point.)
384 However, see the discussion of remounting above,
385 for a method of making an existing bind mount read-only.
386 .\"
387 .SS Changing the propagation type of an existing mount
388 [TBC]
389 .\"
390 .\" FIXME 2.6.15 added flags for "shared subtree" functionality:
391 .\"
392 .\" MS_PRIVATE
393 .\" All mounts are private by default. Previously shared mounts
394 .\" can be re-marked PRIVATE.
395 .\" MS_SHARED
396 .\" Mount points that are marked SHARED propagate mount events
397 .\" to one another after being cloned.
398 .\" mount --make-rshared ==> MS_SHARED | MS_REC
399 .\" MS_SLAVE
400 .\" A previously shared mount point can be marked SLAVE, meaning
401 .\" it receives propagated events, but does not propagate events.
402 .\" MS_UNBINDABLE
403 .\" mounts cannot be bound into other places, and will not be
404 .\" propagated into new subtrees
405 .\"
406 .\" These settings are visible in /proc/$$/mountinfo
407 .\"
408 .\" These need to be documented on this page.
409 .\" See:
410 .\"
411 .\" * Documentation/filesystems/sharedsubtree.txt
412 .\"
413 .\" * http://lwn.net/Articles/159077/
414 .\"
415 .\" * https://www.kernel.org/doc/ols/2006/ols2006v2-pages-209-222.pdf
416 .\" Shared-Subtree Concept, Implementation, and Applications in Linux
417 .\" Al Viro viro@ftp.linux.org.uk
418 .\" Ram Pai linuxram@us.ibm.com
419 .\"
420 .\" * http://www.ibm.com/developerworks/linux/library/l-mount-namespaces/index.html
421 .\" Applying mount namespaces
422 .\"
423 .\" Uncover practical applications for advanced Linux mounts features
424 .\" Serge E. Hallyn (sergeh@us.ibm.com), Software Engineer, IBM
425 .\" Ram Pai (linuxram@us.ibm.com), Software Engineer, IBM
426 .\" Date: 17 Sep 2007
427 .\"
428 .SS Moving a mount
429 If
430 .I mountflags
431 contains the flag
432 .BR MS_MOVE ,
433 then move a subtree:
434 .I source
435 specifies an existing mount point and
436 .I target
437 specifies the new location to which that mount point is to be relocated.
438 The move is atomic: at no point is the subtree unmounted.
439 The remaining bits in the
440 .IR mountflags
441 argument are ignored, as are the
442 .IR filesystemtype
443 and
444 .IR data
445 arguments.
446 .\"
447 .SS Creating a new mount point
448 If none of
449 .BR MS_REMOUNT ,
450 .BR MS_BIND ,
451 .BR MS_MOVE ,
452 .BR MS_SHARED ,
453 .BR MS_PRIVATE ,
454 .BR MS_SLAVE ,
455 or
456 .BR MS_UNBINDABLE
457 is specified in
458 .IR mountflags ,
459 then
460 .BR mount ()
461 performs its default action: creating a new mount point.
462 .IR source
463 specifies the source for the new mount point, and
464 .IR target
465 specifies the directory at which to create the mount point.
466
467 The
468 .I filesystemtype
469 and
470 .I data
471 arguments are employed, and further bits may be specified in
472 .IR mountflags
473 to modify the behavior of the call.
474 .\"
475 .SH RETURN VALUE
476 On success, zero is returned.
477 On error, \-1 is returned, and
478 .I errno
479 is set appropriately.
480 .SH ERRORS
481 The error values given below result from filesystem type independent
482 errors.
483 Each filesystem type may have its own special errors and its
484 own special behavior.
485 See the Linux kernel source code for details.
486 .TP
487 .B EACCES
488 A component of a path was not searchable.
489 (See also
490 .BR path_resolution (7).)
491 Or, mounting a read-only filesystem was attempted without giving the
492 .B MS_RDONLY
493 flag.
494 Or, the block device
495 .I source
496 is located on a filesystem mounted with the
497 .B MS_NODEV
498 option.
499 .\" mtk: Probably: write permission is required for MS_BIND, with
500 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
501 .TP
502 .B EBUSY
503 .I source
504 is already mounted.
505 Or, it cannot be remounted read-only,
506 because it still holds files open for writing.
507 Or, it cannot be mounted on
508 .I target
509 because
510 .I target
511 is still busy (it is the working directory of some thread,
512 the mount point of another device, has open files, etc.).
513 .TP
514 .B EFAULT
515 One of the pointer arguments points outside the user address space.
516 .TP
517 .B EINVAL
518 .I source
519 had an invalid superblock.
520 Or, a remount
521 .RB ( MS_REMOUNT )
522 was attempted, but
523 .I source
524 was not already mounted on
525 .IR target .
526 Or, a move
527 .RB ( MS_MOVE )
528 was attempted, but
529 .I source
530 was not a mount point, or was \(aq/\(aq.
531 .TP
532 .B ELOOP
533 Too many links encountered during pathname resolution.
534 Or, a move was attempted, while
535 .I target
536 is a descendant of
537 .IR source .
538 .TP
539 .B EMFILE
540 (In case no block device is required:)
541 Table of dummy devices is full.
542 .TP
543 .B ENAMETOOLONG
544 A pathname was longer than
545 .BR MAXPATHLEN .
546 .TP
547 .B ENODEV
548 .I filesystemtype
549 not configured in the kernel.
550 .TP
551 .B ENOENT
552 A pathname was empty or had a nonexistent component.
553 .TP
554 .B ENOMEM
555 The kernel could not allocate a free page to copy filenames or data into.
556 .TP
557 .B ENOTBLK
558 .I source
559 is not a block device (and a device was required).
560 .TP
561 .B ENOTDIR
562 .IR target ,
563 or a prefix of
564 .IR source ,
565 is not a directory.
566 .TP
567 .B ENXIO
568 The major number of the block device
569 .I source
570 is out of range.
571 .TP
572 .B EPERM
573 The caller does not have the required privileges.
574 .SH VERSIONS
575 The definitions of
576 .BR MS_DIRSYNC ,
577 .BR MS_MOVE ,
578 .BR MS_PRIVATE ,
579 .BR MS_REC ,
580 .BR MS_RELATIME ,
581 .BR MS_SHARED ,
582 .BR MS_SLAVED ,
583 .BR MS_STRICTATIME
584 and
585 .BR MS_UNBINDABLE
586 were added to glibc headers in version 2.12.
587 .\"
588 .SH CONFORMING TO
589 This function is Linux-specific and should not be used in
590 programs intended to be portable.
591 .SH NOTES
592 Since Linux 2.4 a single filesystem can be mounted at
593 multiple mount points, and multiple mounts can be stacked
594 on the same mount point.
595 .\" Multiple mounts on same mount point: since 2.3.99pre7.
596
597 The
598 .I mountflags
599 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
600 in the top 16 bits.
601 (All of the other flags discussed in DESCRIPTION
602 occupy the low order 16 bits of
603 .IR mountflags .)
604 Specifying
605 .BR MS_MGC_VAL
606 was required in kernel versions prior to 2.4,
607 but since Linux 2.4 is no longer required and is ignored if specified.
608
609 The original
610 .B MS_SYNC
611 flag was renamed
612 .B MS_SYNCHRONOUS
613 in 1.1.69
614 when a different
615 .B MS_SYNC
616 was added to \fI<mman.h>\fP.
617 .LP
618 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
619 on a filesystem mounted with
620 .B MS_NOSUID
621 would fail with
622 .BR EPERM .
623 Since Linux 2.4 the set-user-ID and set-group-ID bits are
624 just silently ignored in this case.
625 .\" The change is in patch-2.4.0-prerelease.
626 .\"
627
628 .SS Per-process namespaces
629 Starting with kernel 2.4.19, Linux provides
630 per-process mount namespaces.
631 A mount namespace is the set of filesystem mounts that
632 are visible to a process.
633 Mount-point namespaces can be (and usually are)
634 shared between multiple processes,
635 and changes to the namespace (i.e., mounts and unmounts) by one process
636 are visible to all other processes sharing the same namespace.
637 (The pre-2.4.19 Linux situation can be considered as one in which
638 a single namespace was shared by every process on the system.)
639
640 A child process created by
641 .BR fork (2)
642 shares its parent's mount namespace;
643 the mount namespace is preserved across an
644 .BR execve (2).
645
646 A process can obtain a private mount namespace if:
647 it was created using the
648 .BR clone (2)
649 .BR CLONE_NEWNS
650 flag,
651 in which case its new namespace is initialized to be a
652 .I copy
653 of the namespace of the process that called
654 .BR clone (2);
655 or it calls
656 .BR unshare (2)
657 with the
658 .BR CLONE_NEWNS
659 flag,
660 which causes the caller's mount namespace to obtain a private copy
661 of the namespace that it was previously sharing with other processes,
662 so that future mounts and unmounts by the caller are invisible
663 to other processes (except child processes that the caller
664 subsequently creates) and vice versa.
665
666 The Linux-specific
667 .I /proc/PID/mounts
668 file exposes the list of mount points in the mount
669 namespace of the process with the specified ID; see
670 .BR proc (5)
671 for details.
672 .SH SEE ALSO
673 .BR umount (2),
674 .BR namespaces (7),
675 .BR path_resolution (7),
676 .BR lsblk (8),
677 .BR findmnt (8),
678 .BR mount (8),
679 .BR umount (8)