1MOUNT(2)                   Linux Programmer's Manual                  MOUNT(2)
2
3
4

NAME

6       mount - mount file system
7

SYNOPSIS

9       #include <sys/mount.h>
10
11       int mount(const char *source, const char *target,
12                 const char *filesystemtype, unsigned long mountflags,
13                 const void *data);
14

DESCRIPTION

16       mount()  attaches the file system specified by source (which is often a
17       device name, but can also be a directory name or a dummy) to the direc‐
18       tory specified by target.
19
20       Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
21       to mount file systems.
22
23       Since Linux 2.4 a single file system can be visible at  multiple  mount
24       points, and multiple mounts can be stacked on the same mount point.
25
26       Values  for  the  filesystemtype  argument  supported by the kernel are
27       listed in  /proc/filesystems  (like  "minix",  "ext2",  "ext3",  "jfs",
28       "xfs",  "reiserfs",  "msdos",  "proc", "nfs", "iso9660" etc.).  Further
29       types may become available when the appropriate modules are loaded.
30
31       The mountflags argument may have the magic number  0xC0ED  (MS_MGC_VAL)
32       in  the top 16 bits (this was required in kernel versions prior to 2.4,
33       but is no longer required and ignored if specified), and various  mount
34       flags   (as  defined  in  <linux/fs.h>  for  libc4  and  libc5  and  in
35       <sys/mount.h> for glibc2) in the low order 16 bits:
36
37       MS_BIND (Linux 2.4 onwards)
38              Perform a bind mount, making a file or a directory subtree visi‐
39              ble  at  another  point  within  a file system.  Bind mounts may
40              cross file system boundaries  and  span  chroot(2)  jails.   The
41              filesystemtype  and  data arguments are ignored.  Up until Linux
42              2.6.26, mountflags was also ignored (the bind mount has the same
43              mount  options  as  the  underlying  mount  point).  Since Linux
44              2.6.26, the MS_RDONLY flag is honored when making a bind mount.
45
46       MS_DIRSYNC (since Linux 2.5.19)
47              Make directory changes on this file system  synchronous.   (This
48              property  can be obtained for individual directories or subtrees
49              using chattr(1).)
50
51       MS_MANDLOCK
52              Permit mandatory locking on files in this file system.   (Manda‐
53              tory  locking  must  still  be  enabled  on a per-file basis, as
54              described in fcntl(2).)
55
56       MS_MOVE
57              Move a subtree.  source specifies an existing  mount  point  and
58              target  specifies  the  new location.  The move is atomic: at no
59              point is the subtree unmounted.  The filesystemtype, mountflags,
60              and data arguments are ignored.
61
62       MS_NOATIME
63              Do not update access times for (all types of) files on this file
64              system.
65
66       MS_NODEV
67              Do not allow access to devices (special files) on this file sys‐
68              tem.
69
70       MS_NODIRATIME
71              Do  not update access times for directories on this file system.
72              This flag provides a subset of  the  functionality  provided  by
73              MS_NOATIME; that is, MS_NOATIME implies MS_NODIRATIME.
74
75       MS_NOEXEC
76              Do not allow programs to be executed from this file system.
77
78       MS_NOSUID
79              Do  not  honor  set-user-ID and set-group-ID bits when executing
80              programs from this file system.
81
82       MS_RDONLY
83              Mount file system read-only.
84
85       MS_RELATIME (Since Linux 2.6.20)
86              When a file on this file system is  accessed,  only  update  the
87              file's last access time (atime) if the current value of atime is
88              less than or equal to the file's last modification time  (mtime)
89              or  last  status change time (ctime).  This option is useful for
90              programs, such as mutt(1), that need to know  when  a  file  has
91              been  read  since it was last modified.  Since Linux 2.6.30, the
92              kernel defaults to the behavior provided by  this  flag  (unless
93              MS_NOATIME  was  specified),  and  the  MS_STRICTATIME  flag  is
94              required to obtain traditional semantics.   In  addition,  since
95              Linux  2.6.30,  the file's last access time is always updated if
96              it is more than 1 day old.
97
98       MS_REMOUNT
99              Remount an existing mount.  This allows you to change the mount‐
100              flags  and  data  of an existing mount without having to unmount
101              and remount the file system.  source and target  should  be  the
102              same  values  specified in the initial mount() call; filesystem‐
103              type is ignored.
104
105              The following mountflags can be changed: MS_RDONLY,  MS_SYNCHRO‐
106              NOUS,  MS_MANDLOCK;  before  kernel  2.6.16, the following could
107              also be changed: MS_NOATIME and  MS_NODIRATIME;  and,  addition‐
108              ally, before kernel 2.4.10, the following could also be changed:
109              MS_NOSUID, MS_NODEV, MS_NOEXEC.
110
111       MS_SILENT (since Linux 2.6.17)
112              Suppress the display of certain (printk()) warning  messages  in
113              the  kernel log.  This flag supersedes the misnamed and obsolete
114              MS_VERBOSE flag (available since Linux 2.4.12),  which  has  the
115              same meaning.
116
117       MS_STRICTATIME (Since Linux 2.6.30)
118              Always  update  the  last access time (atime) when files on this
119              file system are accessed.  (This was the default behavior before
120              Linux  2.6.30.)   Specifying  this  flag overrides the effect of
121              setting the MS_NOATIME and MS_RELATIME flags.
122
123       MS_SYNCHRONOUS
124              Make writes on this  file  system  synchronous  (as  though  the
125              O_SYNC  flag to open(2) was specified for all file opens to this
126              file system).
127
128       From Linux 2.4 onwards, the MS_NODEV, MS_NOEXEC,  and  MS_NOSUID  flags
129       are  settable  on a per-mount-point basis.  From kernel 2.6.16 onwards,
130       MS_NOATIME and MS_NODIRATIME are also  settable  on  a  per-mount-point
131       basis.   The  MS_RELATIME  flag  is  also settable on a per-mount-point
132       basis.
133
134       The data argument is interpreted by the different file systems.   Typi‐
135       cally it is a string of comma-separated options understood by this file
136       system.  See mount(8) for details of the  options  available  for  each
137       filesystem type.
138

RETURN VALUE

140       On  success,  zero is returned.  On error, -1 is returned, and errno is
141       set appropriately.
142

ERRORS

144       The error values given below result from  filesystem  type  independent
145       errors.   Each  filesystem type may have its own special errors and its
146       own special behavior.  See the kernel source code for details.
147
148       EACCES A component of a path was not searchable.  (See also  path_reso‐
149              lution(7).)   Or,  mounting a read-only filesystem was attempted
150              without giving the MS_RDONLY flag.  Or, the block device  source
151              is located on a filesystem mounted with the MS_NODEV option.
152
153       EBUSY  source  is  already  mounted.   Or, it cannot be remounted read-
154              only, because it still holds files open  for  writing.   Or,  it
155              cannot  be mounted on target because target is still busy (it is
156              the working directory of some task, the mount point  of  another
157              device, has open files, etc.).
158
159       EFAULT One  of  the  pointer  arguments points outside the user address
160              space.
161
162       EINVAL source had an invalid superblock.  Or,  a  remount  (MS_REMOUNT)
163              was  attempted,  but  source  was not already mounted on target.
164              Or, a move (MS_MOVE) was attempted, but source was not  a  mount
165              point, or was '/'.
166
167       ELOOP  Too  many  links  encountered during pathname resolution.  Or, a
168              move was attempted, while target is a descendant of source.
169
170       EMFILE (In case no block device is required:) Table of dummy devices is
171              full.
172
173       ENAMETOOLONG
174              A pathname was longer than MAXPATHLEN.
175
176       ENODEV filesystemtype not configured in the kernel.
177
178       ENOENT A pathname was empty or had a nonexistent component.
179
180       ENOMEM The  kernel  could not allocate a free page to copy filenames or
181              data into.
182
183       ENOTBLK
184              source is not a block device (and a device was required).
185
186       ENOTDIR
187              target, or a prefix of source, is not a directory.
188
189       ENXIO  The major number of the block device source is out of range.
190
191       EPERM  The caller does not have the required privileges.
192

CONFORMING TO

194       This function is Linux-specific and should  not  be  used  in  programs
195       intended to be portable.
196

NOTES

198       The  original  MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69 when a
199       different MS_SYNC was added to <mman.h>.
200
201       Before Linux 2.4 an attempt to execute a  set-user-ID  or  set-group-ID
202       program  on  a filesystem mounted with MS_NOSUID would fail with EPERM.
203       Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently
204       ignored in this case.
205
206   Per-process Namespaces
207       Starting  with  kernel  2.4.19, Linux provides per-process mount names‐
208       paces.  A mount namespace is the set of file  system  mounts  that  are
209       visible  to a process.  Mount-point namespaces can be (and usually are)
210       shared between multiple processes, and changes to the namespace  (i.e.,
211       mounts  and unmounts) by one process are visible to all other processes
212       sharing the same namespace.  (The pre-2.4.19  Linux  situation  can  be
213       considered  as  one  in  which  a  single namespace was shared by every
214       process on the system.)
215
216       A child process created by fork(2) shares its parent's mount namespace;
217       the mount namespace is preserved across an execve(2).
218
219       A process can obtain a private mount namespace if: it was created using
220       the clone() CLONE_NEWNS flag, in which case its new namespace  is  ini‐
221       tialized  to  be  a  copy  of  the namespace of the process that called
222       clone(); or it calls unshare(2) with the CLONE_NEWNS flag, which causes
223       the  caller's mount namespace to obtain a private copy of the namespace
224       that it was previously sharing with other  processes,  so  that  future
225       mounts  and  unmounts  by  the  caller are invisible to other processes
226       (except child processes that the caller subsequently creates) and  vice
227       versa.
228
229       The  Linux-specific  /proc/PID/mounts  file  exposes  the list of mount
230       points in the mount namespace of the process with the specified ID; see
231       proc(5) for details.
232

SEE ALSO

234       umount(2), path_resolution(7), mount(8), umount(8)
235

COLOPHON

237       This  page  is  part of release 3.25 of the Linux man-pages project.  A
238       description of the project, and information about reporting  bugs,  can
239       be found at http://www.kernel.org/doc/man-pages/.
240
241
242
243Linux                             2010-05-22                          MOUNT(2)
Impressum