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