]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/mount.2
mount.2: srcfix
[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 2014-09-21 "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 bieing cloned.
94
95 .\" mount --make-rshared ==> MS_SHARED | MS_REC
96
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 Up until Linux 2.6.26,
142 .I mountflags
143 was also ignored
144 .\" with the exception of the "hidden" MS_REC mountflags bit
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 .B MS_MANDLOCK
155 Permit mandatory locking on files in this filesystem.
156 (Mandatory locking must still be enabled on a per-file basis,
157 as described in
158 .BR fcntl (2).)
159 .\" FIXME Describe the MS_MOVE flag in more detail
160 .TP
161 .B MS_MOVE
162 Move a subtree.
163 .I source
164 specifies an existing mount point and
165 .I target
166 specifies the new location.
167 The move is atomic: at no point is the subtree unmounted.
168 The
169 .IR filesystemtype ", " mountflags ", and " data
170 arguments are ignored.
171 .TP
172 .B MS_NOATIME
173 Do not update access times for (all types of) files on this filesystem.
174 .TP
175 .B MS_NODEV
176 Do not allow access to devices (special files) on this filesystem.
177 .TP
178 .B MS_NODIRATIME
179 Do not update access times for directories on this filesystem.
180 This flag provides a subset of the functionality provided by
181 .BR MS_NOATIME ;
182 that is,
183 .BR MS_NOATIME
184 implies
185 .BR MS_NODIRATIME .
186 .TP
187 .B MS_NOEXEC
188 Do not allow programs to be executed from this filesystem.
189 .\" (Possibly useful for a filesystem that contains non-Linux executables.
190 .\" Often used as a security feature, e.g., to make sure that restricted
191 .\" users cannot execute files uploaded using ftp or so.)
192 .TP
193 .B MS_NOSUID
194 Do not honor set-user-ID and set-group-ID bits when executing
195 programs from this filesystem.
196 .\" (This is a security feature to prevent users executing set-user-ID and
197 .\" set-group-ID programs from removable disk devices.)
198 .TP
199 .B MS_RDONLY
200 Mount filesystem read-only.
201 .\"
202 .\" FIXME Document MS_REC, available since 2.4.11.
203 .\" This flag has meaning in conjunction with MS_BIND and
204 .\" also with the shared subtree flags.
205 .TP
206 .BR MS_RELATIME " (since Linux 2.6.20)"
207 When a file on this filesystem is accessed,
208 update the file's last access time (atime) only if the current value
209 of atime is less than or equal to the file's last modification time (mtime)
210 or last status change time (ctime).
211 This option is useful for programs, such as
212 .BR mutt (1),
213 that need to know when a file has been read since it was last modified.
214 Since Linux 2.6.30, the kernel defaults to the behavior provided
215 by this flag (unless
216 .BR MS_NOATIME
217 was specified), and the
218 .B MS_STRICTATIME
219 flag is required to obtain traditional semantics.
220 In addition, since Linux 2.6.30,
221 the file's last access time is always updated if it
222 is more than 1 day old.
223 .\" Matthew Garrett notes in the patch that added this behavior
224 .\" that this lets utilities such as tmpreaper (which deletes
225 .\" files based on last access time) work correctly.
226 .TP
227 .B MS_REMOUNT
228 Remount an existing mount.
229 This allows you to change the
230 .I mountflags
231 and
232 .I data
233 of an existing mount without having to unmount and remount the filesystem.
234 .I target
235 should be the same value specified in the initial
236 .BR mount ()
237 call;
238 .I source
239 and
240 .I filesystemtype
241 are ignored.
242 The
243 .I mountflags
244 and
245 .I data
246 arguments should match the values used in the original
247 .BR mount ()
248 call, except for those parameters that are being deliberately changed.
249
250 The following
251 .I mountflags
252 can be changed:
253 .BR MS_RDONLY ,
254 .BR MS_SYNCHRONOUS ,
255 .BR MS_MANDLOCK ;
256 before kernel 2.6.16, the following could also be changed:
257 .B MS_NOATIME
258 and
259 .BR MS_NODIRATIME ;
260 and, additionally, before kernel 2.4.10, the following could also be changed:
261 .BR MS_NOSUID ,
262 .BR MS_NODEV ,
263 .BR MS_NOEXEC .
264 .TP
265 .BR MS_SILENT " (since Linux 2.6.17)"
266 Suppress the display of certain
267 .RI ( printk ())
268 warning messages in the kernel log.
269 This flag supersedes the misnamed and obsolete
270 .BR MS_VERBOSE
271 flag (available since Linux 2.4.12), which has the same meaning.
272 .TP
273 .BR MS_STRICTATIME " (since Linux 2.6.30)"
274 Always update the last access time (atime) when files on this
275 filesystem are accessed.
276 (This was the default behavior before Linux 2.6.30.)
277 Specifying this flag overrides the effect of setting the
278 .BR MS_NOATIME
279 and
280 .BR MS_RELATIME
281 flags.
282 .TP
283 .B MS_SYNCHRONOUS
284 Make writes on this filesystem synchronous (as though
285 the
286 .B O_SYNC
287 flag to
288 .BR open (2)
289 was specified for all file opens to this filesystem).
290 .PP
291 From Linux 2.4 onward, the
292 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
293 flags are settable on a per-mount-point basis.
294 From kernel 2.6.16 onward,
295 .B MS_NOATIME
296 and
297 .B MS_NODIRATIME
298 are also settable on a per-mount-point basis.
299 The
300 .B MS_RELATIME
301 flag is also settable on a per-mount-point basis.
302 .PP
303 The
304 .I data
305 argument is interpreted by the different filesystems.
306 Typically it is a string of comma-separated options
307 understood by this filesystem.
308 See
309 .BR mount (8)
310 for details of the options available for each filesystem type.
311 .SH "RETURN VALUE"
312 On success, zero is returned.
313 On error, \-1 is returned, and
314 .I errno
315 is set appropriately.
316 .SH ERRORS
317 The error values given below result from filesystem type independent
318 errors.
319 Each filesystem type may have its own special errors and its
320 own special behavior.
321 See the Linux kernel source code for details.
322 .TP
323 .B EACCES
324 A component of a path was not searchable.
325 (See also
326 .BR path_resolution (7).)
327 Or, mounting a read-only filesystem was attempted without giving the
328 .B MS_RDONLY
329 flag.
330 Or, the block device
331 .I source
332 is located on a filesystem mounted with the
333 .B MS_NODEV
334 option.
335 .\" mtk: Probably: write permission is required for MS_BIND, with
336 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
337 .TP
338 .B EBUSY
339 .I source
340 is already mounted.
341 Or, it cannot be remounted read-only,
342 because it still holds files open for writing.
343 Or, it cannot be mounted on
344 .I target
345 because
346 .I target
347 is still busy (it is the working directory of some thread,
348 the mount point of another device, has open files, etc.).
349 .TP
350 .B EFAULT
351 One of the pointer arguments points outside the user address space.
352 .TP
353 .B EINVAL
354 .I source
355 had an invalid superblock.
356 Or, a remount
357 .RB ( MS_REMOUNT )
358 was attempted, but
359 .I source
360 was not already mounted on
361 .IR target .
362 Or, a move
363 .RB ( MS_MOVE )
364 was attempted, but
365 .I source
366 was not a mount point, or was \(aq/\(aq.
367 .TP
368 .B ELOOP
369 Too many links encountered during pathname resolution.
370 Or, a move was attempted, while
371 .I target
372 is a descendant of
373 .IR source .
374 .TP
375 .B EMFILE
376 (In case no block device is required:)
377 Table of dummy devices is full.
378 .TP
379 .B ENAMETOOLONG
380 A pathname was longer than
381 .BR MAXPATHLEN .
382 .TP
383 .B ENODEV
384 .I filesystemtype
385 not configured in the kernel.
386 .TP
387 .B ENOENT
388 A pathname was empty or had a nonexistent component.
389 .TP
390 .B ENOMEM
391 The kernel could not allocate a free page to copy filenames or data into.
392 .TP
393 .B ENOTBLK
394 .I source
395 is not a block device (and a device was required).
396 .TP
397 .B ENOTDIR
398 .IR target ,
399 or a prefix of
400 .IR source ,
401 is not a directory.
402 .TP
403 .B ENXIO
404 The major number of the block device
405 .I source
406 is out of range.
407 .TP
408 .B EPERM
409 The caller does not have the required privileges.
410 .SH VERSIONS
411 The definitions of
412 .BR MS_DIRSYNC ,
413 .BR MS_MOVE ,
414 .BR MS_REC ,
415 .BR MS_RELATIME ,
416 and
417 .BR MS_STRICTATIME
418 were added to glibc headers in version 2.12.
419 .\" FIXME . Definitions of the so-far-undocumented MS_UNBINDABLE, MS_PRIVATE,
420 .\" MS_SHARED, and MS_SLAVE were (also) only added to glibc headers in 2.12.
421 .SH "CONFORMING TO"
422 This function is Linux-specific and should not be used in
423 programs intended to be portable.
424 .SH NOTES
425 The original
426 .B MS_SYNC
427 flag was renamed
428 .B MS_SYNCHRONOUS
429 in 1.1.69
430 when a different
431 .B MS_SYNC
432 was added to \fI<mman.h>\fP.
433 .LP
434 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
435 on a filesystem mounted with
436 .B MS_NOSUID
437 would fail with
438 .BR EPERM .
439 Since Linux 2.4 the set-user-ID and set-group-ID bits are
440 just silently ignored in this case.
441 .\" The change is in patch-2.4.0-prerelease.
442 .SS Per-process namespaces
443 Starting with kernel 2.4.19, Linux provides
444 per-process mount namespaces.
445 A mount namespace is the set of filesystem mounts that
446 are visible to a process.
447 Mount-point namespaces can be (and usually are)
448 shared between multiple processes,
449 and changes to the namespace (i.e., mounts and unmounts) by one process
450 are visible to all other processes sharing the same namespace.
451 (The pre-2.4.19 Linux situation can be considered as one in which
452 a single namespace was shared by every process on the system.)
453
454 A child process created by
455 .BR fork (2)
456 shares its parent's mount namespace;
457 the mount namespace is preserved across an
458 .BR execve (2).
459
460 A process can obtain a private mount namespace if:
461 it was created using the
462 .BR clone (2)
463 .BR CLONE_NEWNS
464 flag,
465 in which case its new namespace is initialized to be a
466 .I copy
467 of the namespace of the process that called
468 .BR clone (2);
469 or it calls
470 .BR unshare (2)
471 with the
472 .BR CLONE_NEWNS
473 flag,
474 which causes the caller's mount namespace to obtain a private copy
475 of the namespace that it was previously sharing with other processes,
476 so that future mounts and unmounts by the caller are invisible
477 to other processes (except child processes that the caller
478 subsequently creates) and vice versa.
479
480 The Linux-specific
481 .I /proc/PID/mounts
482 file exposes the list of mount points in the mount
483 namespace of the process with the specified ID; see
484 .BR proc (5)
485 for details.
486 .SH "SEE ALSO"
487 .BR umount (2),
488 .BR namespaces (7),
489 .BR path_resolution (7),
490 .BR lsblk (8),
491 .BR mount (8),
492 .BR umount (8)