OSDN Git Service

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