]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/mount.2
mount.2: MS_MANDLOCK requires CAP_SYS_ADMIN (since Linux 4.5)
[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 device name, but can also be a directory name
56 or a dummy) to the directory specified by
57 .IR target .
58
59 Appropriate privilege (Linux: the
60 .B CAP_SYS_ADMIN
61 capability) is required to mount filesystems.
62
63 Since Linux 2.4 a single filesystem can be visible at
64 multiple mount points, and multiple mounts can be stacked
65 on the same mount point.
66 .\" Multiple mounts on same mount point: since 2.3.99pre7.
67
68 Values for the
69 .I filesystemtype
70 argument supported by the kernel are listed in
71 .I /proc/filesystems
72 (e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs",
73 "msdos", "proc", "nfs", "iso9660").
74 Further types may become available when the appropriate modules
75 are loaded.
76
77 The
78 .I mountflags
79 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
80 in the top 16 bits (this was required in kernel versions prior to 2.4, but
81 is no longer required and ignored if specified),
82 and various mount flags
83 .\" (as defined in \fI<linux/fs.h>\fP for libc4 and libc5
84 .\" and in \fI<sys/mount.h>\fP for glibc2)
85 in the low order 16 bits:
86 .\" FIXME 2.6.15 added flags for "shared subtree" functionality:
87 .\"
88 .\" MS_PRIVATE
89 .\" All mounts are private by default. Previously shared mounts
90 .\" can be re-marked PRIVATE.
91 .\" MS_SHARED
92 .\" Mount points that are marked SHARED propagate mount events
93 .\" to one another after being cloned.
94 .\" mount --make-rshared ==> MS_SHARED | MS_REC
95 .\" MS_SLAVE
96 .\" A previously shared mount point can be marked SLAVE, meaning
97 .\" it receives propagated events, but does not propagate events.
98 .\" MS_UNBINDABLE
99 .\" mounts cannot be bound into other places, and will not be
100 .\" propagated into new subtrees
101 .\"
102 .\" These settings are visible in /proc/$$/mountinfo
103 .\"
104 .\" These need to be documented on this page.
105 .\" See:
106 .\"
107 .\" * Documentation/filesystems/sharedsubtree.txt
108 .\"
109 .\" * http://lwn.net/Articles/159077/
110 .\"
111 .\" * https://www.kernel.org/doc/ols/2006/ols2006v2-pages-209-222.pdf
112 .\" Shared-Subtree Concept, Implementation, and Applications in Linux
113 .\" Al Viro viro@ftp.linux.org.uk
114 .\" Ram Pai linuxram@us.ibm.com
115 .\"
116 .\" * http://www.ibm.com/developerworks/linux/library/l-mount-namespaces/index.html
117 .\" Applying mount namespaces
118 .\"
119 .\" Uncover practical applications for advanced Linux mounts features
120 .\" Serge E. Hallyn (sergeh@us.ibm.com), Software Engineer, IBM
121 .\" Ram Pai (linuxram@us.ibm.com), Software Engineer, IBM
122 .\" Date: 17 Sep 2007
123 .\"
124 .\" FIXME 2.6.25 Added MS_I_VERSION, which needs to be documented.
125 .\"
126 .TP
127 .BR MS_BIND " (Linux 2.4 onward)"
128 .\" since 2.4.0-test9
129 Perform a bind mount, making a file or a directory subtree visible at
130 another point within a filesystem.
131 Bind mounts may cross filesystem boundaries and span
132 .BR chroot (2)
133 jails.
134 The
135 .IR filesystemtype
136 and
137 .IR data
138 arguments are ignored.
139 Up until Linux 2.6.26,
140 .I mountflags
141 was also ignored
142 .\" with the exception of the "hidden" MS_REC mountflags bit
143 (the bind mount has the same mount options as
144 the underlying mount point).
145 .TP
146 .BR MS_DIRSYNC " (since Linux 2.5.19)"
147 Make directory changes on this filesystem synchronous.
148 (This property can be obtained for individual directories
149 or subtrees using
150 .BR chattr (1).)
151 .TP
152 .BR MS_LAZYTIME " (since Linux 4.0)"
153 .\" commit 0ae45f63d4ef8d8eeec49c7d8b44a1775fff13e8
154 .\" commit fe032c422c5ba562ba9c2d316f55e258e03259c6
155 .\" commit a26f49926da938f47561f386be56a83dd37a496d
156 Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
157 by maintaining these changes only in memory.
158 The on-disk timestamps are updated only when:
159 .RS
160 .IP (a) 5
161 the inode needs to be updated for some change unrelated to file timestamps;
162 .IP (b)
163 the application employs
164 .BR fsync (2),
165 .BR syncfs (2),
166 or
167 .BR sync (2);
168 .IP (c)
169 an undeleted inode is evicted from memory; or
170 .IP (d)
171 more than 24 hours have passed since the inode was written to disk.
172 .RE
173 .IP
174 This mount option significantly reduces writes
175 needed to update the inode's timestamps, especially mtime and atime.
176 However, in the event of a system crash, the atime and mtime fields
177 on disk might be out of date by up to 24 hours.
178
179 Examples of workloads where this option could be of significant benefit
180 include frequent random writes to preallocated files,
181 as well as cases where the
182 .B MS_STRICTATIME
183 mount option is also enabled.
184 (The advantage of combining
185 .BR MS_STRICTATIME
186 and
187 .BR MS_LAZYTIME
188 is that
189 .BR stat (2)
190 will return the correctly updated atime, but the atime updates
191 will be flushed to disk only in the cases listed above.)
192 .TP
193 .B MS_MANDLOCK
194 Permit mandatory locking on files in this filesystem.
195 (Mandatory locking must still be enabled on a per-file basis,
196 as described in
197 .BR fcntl (2).)
198 Since Linux 4.5,
199 .\" commit 95ace75414f312f9a7b93d873f386987b92a5301
200 this mount option requires the
201 .B CAP_SYS_ADMIN
202 capability.
203 .\" FIXME Describe the MS_MOVE flag in more detail
204 .TP
205 .B MS_MOVE
206 Move a subtree.
207 .I source
208 specifies an existing mount point and
209 .I target
210 specifies the new location.
211 The move is atomic: at no point is the subtree unmounted.
212 The
213 .IR filesystemtype ", " mountflags ", and " data
214 arguments are ignored.
215 .TP
216 .B MS_NOATIME
217 Do not update access times for (all types of) files on this filesystem.
218 .TP
219 .B MS_NODEV
220 Do not allow access to devices (special files) on this filesystem.
221 .TP
222 .B MS_NODIRATIME
223 Do not update access times for directories on this filesystem.
224 This flag provides a subset of the functionality provided by
225 .BR MS_NOATIME ;
226 that is,
227 .BR MS_NOATIME
228 implies
229 .BR MS_NODIRATIME .
230 .TP
231 .B MS_NOEXEC
232 Do not allow programs to be executed from this filesystem.
233 .\" (Possibly useful for a filesystem that contains non-Linux executables.
234 .\" Often used as a security feature, e.g., to make sure that restricted
235 .\" users cannot execute files uploaded using ftp or so.)
236 .TP
237 .B MS_NOSUID
238 Do not honor set-user-ID and set-group-ID bits when executing
239 programs from this filesystem.
240 .\" (This is a security feature to prevent users executing set-user-ID and
241 .\" set-group-ID programs from removable disk devices.)
242 .TP
243 .B MS_RDONLY
244 Mount filesystem read-only.
245 .\"
246 .\" FIXME Document MS_REC, available since 2.4.11.
247 .\" This flag has meaning in conjunction with MS_BIND and
248 .\" also with the shared subtree flags.
249 .TP
250 .BR MS_RELATIME " (since Linux 2.6.20)"
251 When a file on this filesystem is accessed,
252 update the file's last access time (atime) only if the current value
253 of atime is less than or equal to the file's last modification time (mtime)
254 or last status change time (ctime).
255 This option is useful for programs, such as
256 .BR mutt (1),
257 that need to know when a file has been read since it was last modified.
258 Since Linux 2.6.30, the kernel defaults to the behavior provided
259 by this flag (unless
260 .BR MS_NOATIME
261 was specified), and the
262 .B MS_STRICTATIME
263 flag is required to obtain traditional semantics.
264 In addition, since Linux 2.6.30,
265 the file's last access time is always updated if it
266 is more than 1 day old.
267 .\" Matthew Garrett notes in the patch that added this behavior
268 .\" that this lets utilities such as tmpreaper (which deletes
269 .\" files based on last access time) work correctly.
270 .TP
271 .B MS_REMOUNT
272 Remount an existing mount.
273 This allows you to change the
274 .I mountflags
275 and
276 .I data
277 of an existing mount without having to unmount and remount the filesystem.
278 .I target
279 should be the same value specified in the initial
280 .BR mount ()
281 call;
282 .I source
283 and
284 .I filesystemtype
285 are ignored.
286 The
287 .I mountflags
288 and
289 .I data
290 arguments should match the values used in the original
291 .BR mount ()
292 call, except for those parameters that are being deliberately changed.
293
294 The following
295 .I mountflags
296 can be changed:
297 .BR MS_RDONLY ,
298 .BR MS_SYNCHRONOUS ,
299 .BR MS_MANDLOCK ;
300 before kernel 2.6.16, the following could also be changed:
301 .B MS_NOATIME
302 and
303 .BR MS_NODIRATIME ;
304 and, additionally, before kernel 2.4.10, the following could also be changed:
305 .BR MS_NOSUID ,
306 .BR MS_NODEV ,
307 .BR MS_NOEXEC .
308 .TP
309 .BR MS_SILENT " (since Linux 2.6.17)"
310 Suppress the display of certain
311 .RI ( printk ())
312 warning messages in the kernel log.
313 This flag supersedes the misnamed and obsolete
314 .BR MS_VERBOSE
315 flag (available since Linux 2.4.12), which has the same meaning.
316 .TP
317 .BR MS_STRICTATIME " (since Linux 2.6.30)"
318 Always update the last access time (atime) when files on this
319 filesystem are accessed.
320 (This was the default behavior before Linux 2.6.30.)
321 Specifying this flag overrides the effect of setting the
322 .BR MS_NOATIME
323 and
324 .BR MS_RELATIME
325 flags.
326 .TP
327 .B MS_SYNCHRONOUS
328 Make writes on this filesystem synchronous (as though
329 the
330 .B O_SYNC
331 flag to
332 .BR open (2)
333 was specified for all file opens to this filesystem).
334 .PP
335 From Linux 2.4 onward, the
336 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
337 flags are settable on a per-mount-point basis.
338 From kernel 2.6.16 onward,
339 .B MS_NOATIME
340 and
341 .B MS_NODIRATIME
342 are also settable on a per-mount-point basis.
343 The
344 .B MS_RELATIME
345 flag is also settable on a per-mount-point basis.
346 .PP
347 The
348 .I data
349 argument is interpreted by the different filesystems.
350 Typically it is a string of comma-separated options
351 understood by this filesystem.
352 See
353 .BR mount (8)
354 for details of the options available for each filesystem type.
355 .SH RETURN VALUE
356 On success, zero is returned.
357 On error, \-1 is returned, and
358 .I errno
359 is set appropriately.
360 .SH ERRORS
361 The error values given below result from filesystem type independent
362 errors.
363 Each filesystem type may have its own special errors and its
364 own special behavior.
365 See the Linux kernel source code for details.
366 .TP
367 .B EACCES
368 A component of a path was not searchable.
369 (See also
370 .BR path_resolution (7).)
371 Or, mounting a read-only filesystem was attempted without giving the
372 .B MS_RDONLY
373 flag.
374 Or, the block device
375 .I source
376 is located on a filesystem mounted with the
377 .B MS_NODEV
378 option.
379 .\" mtk: Probably: write permission is required for MS_BIND, with
380 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
381 .TP
382 .B EBUSY
383 .I source
384 is already mounted.
385 Or, it cannot be remounted read-only,
386 because it still holds files open for writing.
387 Or, it cannot be mounted on
388 .I target
389 because
390 .I target
391 is still busy (it is the working directory of some thread,
392 the mount point of another device, has open files, etc.).
393 .TP
394 .B EFAULT
395 One of the pointer arguments points outside the user address space.
396 .TP
397 .B EINVAL
398 .I source
399 had an invalid superblock.
400 Or, a remount
401 .RB ( MS_REMOUNT )
402 was attempted, but
403 .I source
404 was not already mounted on
405 .IR target .
406 Or, a move
407 .RB ( MS_MOVE )
408 was attempted, but
409 .I source
410 was not a mount point, or was \(aq/\(aq.
411 .TP
412 .B ELOOP
413 Too many links encountered during pathname resolution.
414 Or, a move was attempted, while
415 .I target
416 is a descendant of
417 .IR source .
418 .TP
419 .B EMFILE
420 (In case no block device is required:)
421 Table of dummy devices is full.
422 .TP
423 .B ENAMETOOLONG
424 A pathname was longer than
425 .BR MAXPATHLEN .
426 .TP
427 .B ENODEV
428 .I filesystemtype
429 not configured in the kernel.
430 .TP
431 .B ENOENT
432 A pathname was empty or had a nonexistent component.
433 .TP
434 .B ENOMEM
435 The kernel could not allocate a free page to copy filenames or data into.
436 .TP
437 .B ENOTBLK
438 .I source
439 is not a block device (and a device was required).
440 .TP
441 .B ENOTDIR
442 .IR target ,
443 or a prefix of
444 .IR source ,
445 is not a directory.
446 .TP
447 .B ENXIO
448 The major number of the block device
449 .I source
450 is out of range.
451 .TP
452 .B EPERM
453 The caller does not have the required privileges.
454 .SH VERSIONS
455 The definitions of
456 .BR MS_DIRSYNC ,
457 .BR MS_MOVE ,
458 .BR MS_REC ,
459 .BR MS_RELATIME ,
460 and
461 .BR MS_STRICTATIME
462 were added to glibc headers in version 2.12.
463 .\" FIXME . Definitions of the so-far-undocumented MS_UNBINDABLE, MS_PRIVATE,
464 .\" MS_SHARED, and MS_SLAVE were (also) only added to glibc headers in 2.12.
465 .SH CONFORMING TO
466 This function is Linux-specific and should not be used in
467 programs intended to be portable.
468 .SH NOTES
469 The original
470 .B MS_SYNC
471 flag was renamed
472 .B MS_SYNCHRONOUS
473 in 1.1.69
474 when a different
475 .B MS_SYNC
476 was added to \fI<mman.h>\fP.
477 .LP
478 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
479 on a filesystem mounted with
480 .B MS_NOSUID
481 would fail with
482 .BR EPERM .
483 Since Linux 2.4 the set-user-ID and set-group-ID bits are
484 just silently ignored in this case.
485 .\" The change is in patch-2.4.0-prerelease.
486 .SS Per-process namespaces
487 Starting with kernel 2.4.19, Linux provides
488 per-process mount namespaces.
489 A mount namespace is the set of filesystem mounts that
490 are visible to a process.
491 Mount-point namespaces can be (and usually are)
492 shared between multiple processes,
493 and changes to the namespace (i.e., mounts and unmounts) by one process
494 are visible to all other processes sharing the same namespace.
495 (The pre-2.4.19 Linux situation can be considered as one in which
496 a single namespace was shared by every process on the system.)
497
498 A child process created by
499 .BR fork (2)
500 shares its parent's mount namespace;
501 the mount namespace is preserved across an
502 .BR execve (2).
503
504 A process can obtain a private mount namespace if:
505 it was created using the
506 .BR clone (2)
507 .BR CLONE_NEWNS
508 flag,
509 in which case its new namespace is initialized to be a
510 .I copy
511 of the namespace of the process that called
512 .BR clone (2);
513 or it calls
514 .BR unshare (2)
515 with the
516 .BR CLONE_NEWNS
517 flag,
518 which causes the caller's mount namespace to obtain a private copy
519 of the namespace that it was previously sharing with other processes,
520 so that future mounts and unmounts by the caller are invisible
521 to other processes (except child processes that the caller
522 subsequently creates) and vice versa.
523
524 The Linux-specific
525 .I /proc/PID/mounts
526 file exposes the list of mount points in the mount
527 namespace of the process with the specified ID; see
528 .BR proc (5)
529 for details.
530 .SH SEE ALSO
531 .BR umount (2),
532 .BR namespaces (7),
533 .BR path_resolution (7),
534 .BR lsblk (8),
535 .BR findmnt (8),
536 .BR mount (8),
537 .BR umount (8)