OSDN Git Service

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