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

NAME

6       mount - mount filesystem
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 filesystem specified by source (which is often a
17       pathname referring to a device, but can  also  be  the  pathname  of  a
18       directory  or  file, or a dummy string) to the location (a directory or
19       file) specified by the pathname in target.
20
21       Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
22       to mount filesystems.
23
24       Values  for  the  filesystemtype  argument  supported by the kernel are
25       listed in  /proc/filesystems  (e.g.,  "btrfs",  "ext4",  "jfs",  "xfs",
26       "vfat",  "fuse",  "tmpfs",  "cgroup",  "proc", "mqueue", "nfs", "cifs",
27       "iso9660").  Further types may become available  when  the  appropriate
28       modules are loaded.
29
30       The  data  argument is interpreted by the different filesystems.  Typi‐
31       cally it is a string of  comma-separated  options  understood  by  this
32       filesystem.  See mount(8) for details of the options available for each
33       filesystem type.
34
35       A call to mount() performs one of a number of general types  of  opera‐
36       tion,  depending  on  the  bits specified in mountflags.  The choice of
37       which operation to perform is determined by testing  the  bits  set  in
38       mountflags, with the tests being conducted in the order listed here:
39
40       *  Remount an existing mount: mountflags includes MS_REMOUNT.
41
42       *  Create a bind mount: mountflags includes MS_BIND.
43
44       *  Change  the  propagation  type  of  an  existing  mount:  mountflags
45          includes one of MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE.
46
47       *  Move an existing  mount  to  a  new  location:  mountflags  includes
48          MS_MOVE.
49
50       *  Create a new mount: mountflags includes none of the above flags.
51
52       Each of these operations is detailed later in this page.  Further flags
53       may be specified in mountflags to modify the behavior  of  mount(),  as
54       described below.
55
56   Additional mount flags
57       The  list below describes the additional flags that can be specified in
58       mountflags.  Note that some operation types ignore some or all of these
59       flags, as described later in this page.
60
61       MS_DIRSYNC (since Linux 2.5.19)
62              Make  directory  changes  on this filesystem synchronous.  (This
63              property can be obtained for individual directories or  subtrees
64              using chattr(1).)
65
66       MS_LAZYTIME (since Linux 4.0)
67              Reduce on-disk updates of inode timestamps (atime, mtime, ctime)
68              by maintaining these changes only in memory.  The on-disk  time‐
69              stamps are updated only when:
70
71              (a)  the  inode needs to be updated for some change unrelated to
72                   file timestamps;
73
74              (b)  the application employs fsync(2), syncfs(2), or sync(2);
75
76              (c)  an undeleted inode is evicted from memory; or
77
78              (d)  more than 24 hours have passed since the inode was  written
79                   to disk.
80
81              This  mount option significantly reduces writes needed to update
82              the inode's timestamps, especially mtime and atime.  However, in
83              the  event of a system crash, the atime and mtime fields on disk
84              might be out of date by up to 24 hours.
85
86       Examples of workloads where this option could be of significant benefit
87       include  frequent random writes to preallocated files, as well as cases
88       where the MS_STRICTATIME mount option is also enabled.  (The  advantage
89       of combining MS_STRICTATIME and MS_LAZYTIME is that stat(2) will return
90       the correctly updated atime, but the atime updates will be  flushed  to
91       disk only in the cases listed above.)
92
93       MS_MANDLOCK
94              Permit  mandatory  locking on files in this filesystem.  (Manda‐
95              tory locking must still be  enabled  on  a  per-file  basis,  as
96              described  in  fcntl(2).)   Since  Linux  4.5, this mount option
97              requires the CAP_SYS_ADMIN capability.
98
99       MS_NOATIME
100              Do not update access times for (all  types  of)  files  on  this
101              filesystem.
102
103       MS_NODEV
104              Do  not allow access to devices (special files) on this filesys‐
105              tem.
106
107       MS_NODIRATIME
108              Do not update access times for directories on  this  filesystem.
109              This  flag  provides  a  subset of the functionality provided by
110              MS_NOATIME; that is, MS_NOATIME implies MS_NODIRATIME.
111
112       MS_NOEXEC
113              Do not allow programs to be executed from this filesystem.
114
115       MS_NOSUID
116              Do not honor set-user-ID and set-group-ID bits or file capabili‐
117              ties when executing programs from this filesystem.
118
119       MS_RDONLY
120              Mount filesystem read-only.
121
122       MS_REC (since Linux 2.4.11)
123              Used  in  conjunction  with  MS_BIND  to create a recursive bind
124              mount, and in conjunction with the  propagation  type  flags  to
125              recursively  change the propagation type of all of the mounts in
126              a subtree.  See below for further details.
127
128       MS_RELATIME (since Linux 2.6.20)
129              When a file on this filesystem is accessed,  update  the  file's
130              last  access  time (atime) only if the current value of atime is
131              less than or equal to the file's last modification time  (mtime)
132              or  last  status change time (ctime).  This option is useful for
133              programs, such as mutt(1), that need to know  when  a  file  has
134              been  read  since it was last modified.  Since Linux 2.6.30, the
135              kernel defaults to the behavior provided by  this  flag  (unless
136              MS_NOATIME  was  specified),  and  the  MS_STRICTATIME  flag  is
137              required to obtain traditional semantics.   In  addition,  since
138              Linux  2.6.30,  the file's last access time is always updated if
139              it is more than 1 day old.
140
141       MS_SILENT (since Linux 2.6.17)
142              Suppress the display of certain (printk()) warning  messages  in
143              the  kernel log.  This flag supersedes the misnamed and obsolete
144              MS_VERBOSE flag (available since Linux 2.4.12),  which  has  the
145              same meaning.
146
147       MS_STRICTATIME (since Linux 2.6.30)
148              Always  update  the  last access time (atime) when files on this
149              filesystem are accessed.  (This was the default behavior  before
150              Linux  2.6.30.)   Specifying  this  flag overrides the effect of
151              setting the MS_NOATIME and MS_RELATIME flags.
152
153       MS_SYNCHRONOUS
154              Make writes on this filesystem synchronous (as though the O_SYNC
155              flag  to  open(2)  was  specified  for  all  file  opens to this
156              filesystem).
157
158       From Linux 2.4 onward, the MS_NODEV, MS_NOEXEC, and MS_NOSUID flags are
159       settable  on  a  per-mount-point  basis.   From  kernel  2.6.16 onward,
160       MS_NOATIME and MS_NODIRATIME are also  settable  on  a  per-mount-point
161       basis.   The  MS_RELATIME  flag  is  also settable on a per-mount-point
162       basis.  Since Linux 2.6.16, MS_RDONLY can be set or cleared on  a  per-
163       mount-point basis as well as on the underlying filesystem.  The mounted
164       filesystem will be writable only if  neither  the  filesystem  nor  the
165       mountpoint are flagged as read-only.
166
167   Remounting an existing mount
168       An  existing  mount may be remounted by specifying MS_REMOUNT in mount‐
169       flags.  This allows you to change the mountflags and data of an  exist‐
170       ing mount without having to unmount and remount the filesystem.  target
171       should be the same value specified in the initial mount() call.
172
173       The source and filesystemtype arguments are ignored.
174
175       The mountflags and data arguments should match the values used  in  the
176       original  mount()  call,  except  for  those  parameters that are being
177       deliberately changed.  Another exception is that MS_BIND has a  differ‐
178       ent  meaning  for remount, and it should be included only if explicitly
179       desired.
180
181       The following mountflags  can  be  changed:  MS_LAZYTIME,  MS_MANDLOCK,
182       MS_NOATIME, MS_NODEV, MS_NODIRATIME, MS_NOEXEC, MS_NOSUID, MS_RELATIME,
183       MS_RDONLY, and MS_SYNCHRONOUS.  Attempts to change the setting  of  the
184       MS_DIRSYNC flag during a remount are silently ignored.
185
186       Since Linux 3.17, if none of MS_NOATIME, MS_NODIRATIME, MS_RELATIME, or
187       MS_STRICTATIME is specified in mountflags, then the  remount  operation
188       preserves the existing values of these flags (rather than defaulting to
189       MS_RELATIME).
190
191       Since Linux 2.6.26, this flag can be used with MS_BIND to  modify  only
192       the  per-mount-point flags.  This is particularly useful for setting or
193       clearing the "read-only" flag on a mount  point  without  changing  the
194       underlying filesystem.  Specifying mountflags as:
195
196           MS_REMOUNT | MS_BIND | MS_RDONLY
197
198       will  make  access through this mountpoint read-only, without affecting
199       other mount points.
200
201   Creating a bind mount
202       If mountflags includes MS_BIND (available since Linux 2.4),  then  per‐
203       form  a  bind  mount.  A bind mount makes a file or a directory subtree
204       visible at another point within the single directory  hierarchy.   Bind
205       mounts may cross filesystem boundaries and span chroot(2) jails.
206
207       The filesystemtype and data arguments are ignored.
208
209       The  remaining  bits  in the mountflags argument are also ignored, with
210       the exception of MS_REC.  (The bind mount has the same mount options as
211       the underlying mount point.)  However, see the discussion of remounting
212       above, for a method of making an existing bind mount read-only.
213
214       By default, when a directory is bind mounted, only  that  directory  is
215       mounted;  if there are any submounts under the directory tree, they are
216       not bind mounted.  If the MS_REC flag is also specified, then a  recur‐
217       sive  bind mount operation is performed: all submounts under the source
218       subtree (other than unbindable mounts) are also  bind  mounted  at  the
219       corresponding location in the target subtree.
220
221   Changing the propagation type of an existing mount
222       If  mountflags  includes  one  of  MS_SHARED,  MS_PRIVATE, MS_SLAVE, or
223       MS_UNBINDABLE (all available since Linux 2.6.15), then the  propagation
224       type  of an existing mount is changed.  If more than one of these flags
225       is specified, an error results.
226
227       The only flags that can be used with changing the propagation type  are
228       MS_REC and MS_SILENT.
229
230       The source, filesystemtype, and data arguments are ignored.
231
232       The meanings of the propagation type flags are as follows:
233
234       MS_SHARED
235              Make  this mount point shared.  Mount and unmount events immedi‐
236              ately under this mount point will propagate to the  other  mount
237              points that are members of this mount's peer group.  Propagation
238              here means that the same mount  or  unmount  will  automatically
239              occur  under  all  of  the other mount points in the peer group.
240              Conversely, mount and unmount events that take place under  peer
241              mount points will propagate to this mount point.
242
243       MS_PRIVATE
244              Make  this mount point private.  Mount and unmount events do not
245              propagate into or out of this mount point.
246
247       MS_SLAVE
248              If this is a shared mount point that is a member of a peer group
249              that  contains  other  members, convert it to a slave mount.  If
250              this is a shared mount point that is a member of  a  peer  group
251              that  contains  no other members, convert it to a private mount.
252              Otherwise, the propagation type  of  the  mount  point  is  left
253              unchanged.
254
255       When  a mount point is a slave, mount and unmount events propagate into
256       this mount point from the (master) shared peer group of  which  it  was
257       formerly  a member.  Mount and unmount events under this mount point do
258       not propagate to any peer.
259
260       A mount point can be the slave of another peer group while at the  same
261       time  sharing mount and unmount events with a peer group of which it is
262       a member.
263
264       MS_UNBINDABLE
265              Make this mount unbindable.  This is like a private  mount,  and
266              in  addition this mount can't be bind mounted.  When a recursive
267              bind mount (mount() with the MS_BIND and MS_REC flags)  is  per‐
268              formed  on  a directory subtree, any bind mounts within the sub‐
269              tree are automatically pruned (i.e., not replicated) when repli‐
270              cating that subtree to produce the target subtree.
271
272       By default, changing the propagation type affects only the target mount
273       point.  If the MS_REC flag is also specified in  mountflags,  then  the
274       propagation type of all mount points under target is also changed.
275
276       For  further  details  regarding mount propagation types (including the
277       default propagation type assigned  to  new  mounts),  see  mount_names‐
278       paces(7).
279
280   Moving a mount
281       If mountflags contains the flag MS_MOVE (available since Linux 2.4.18),
282       then move a subtree: source specifies an existing mount point and  tar‐
283       get specifies the new location to which that mount point is to be relo‐
284       cated.  The move is atomic: at no point is the subtree unmounted.
285
286       The remaining bits in the mountflags argument are ignored, as  are  the
287       filesystemtype and data arguments.
288
289   Creating a new mount point
290       If   none  of  MS_REMOUNT,  MS_BIND,  MS_MOVE,  MS_SHARED,  MS_PRIVATE,
291       MS_SLAVE, or MS_UNBINDABLE is specified  in  mountflags,  then  mount()
292       performs its default action: creating a new mount point.  source speci‐
293       fies the source for the new  mount  point,  and  target  specifies  the
294       directory at which to create the mount point.
295
296       The  filesystemtype  and  data arguments are employed, and further bits
297       may be specified in mountflags to modify the behavior of the call.
298

RETURN VALUE

300       On success, zero is returned.  On error, -1 is returned, and  errno  is
301       set appropriately.
302

ERRORS

304       The  error  values  given below result from filesystem type independent
305       errors.  Each filesystem type may have its own special errors  and  its
306       own special behavior.  See the Linux kernel source code for details.
307
308       EACCES A  component of a path was not searchable.  (See also path_reso‐
309              lution(7).)
310
311       EACCES Mounting a read-only filesystem was attempted without giving the
312              MS_RDONLY flag.
313
314       EACCES The  block device source is located on a filesystem mounted with
315              the MS_NODEV option.
316
317       EBUSY  An attempt was made to stack a new mount directly on top  of  an
318              existing  mount  point  that was created in this mount namespace
319              with the same source and target.
320
321       EBUSY  source cannot be remounted read-only,  because  it  still  holds
322              files open for writing.
323
324       EFAULT One  of  the  pointer  arguments points outside the user address
325              space.
326
327       EINVAL source had an invalid superblock.
328
329       EINVAL A remount operation (MS_REMOUNT) was attempted, but  source  was
330              not already mounted on target.
331
332       EINVAL A  move  operation (MS_MOVE) was attempted, but source was not a
333              mount point, or was '/'.
334
335       EINVAL mountflags includes more  than  one  of  MS_SHARED,  MS_PRIVATE,
336              MS_SLAVE, or MS_UNBINDABLE.
337
338       EINVAL mountflags   includes   MS_SHARED,   MS_PRIVATE,   MS_SLAVE,  or
339              MS_UNBINDABLE and also includes a  flag  other  than  MS_REC  or
340              MS_SILENT.
341
342       EINVAL An attempt was made to bind mount an unbindable mount.
343
344       EINVAL In  an  unprivileged  mount  namespace  (i.e., a mount namespace
345              owned by a user namespace that was created  by  an  unprivileged
346              user),  a  bind  mount operation (MS_BIND) was attempted without
347              specifying (MS_REC), which would have  revealed  the  filesystem
348              tree  underneath  one  of  the  submounts of the directory being
349              bound.
350
351       ELOOP  Too many links encountered during pathname resolution.
352
353       ELOOP  A move operation was attempted, and target is  a  descendant  of
354              source.
355
356       EMFILE (In case no block device is required:) Table of dummy devices is
357              full.
358
359       ENAMETOOLONG
360              A pathname was longer than MAXPATHLEN.
361
362       ENODEV filesystemtype not configured in the kernel.
363
364       ENOENT A pathname was empty or had a nonexistent component.
365
366       ENOMEM The kernel could not allocate a free page to copy  filenames  or
367              data into.
368
369       ENOTBLK
370              source is not a block device (and a device was required).
371
372       ENOTDIR
373              target, or a prefix of source, is not a directory.
374
375       ENXIO  The major number of the block device source is out of range.
376
377       EPERM  The caller does not have the required privileges.
378

VERSIONS

380       The  definitions  of  MS_DIRSYNC, MS_MOVE, MS_PRIVATE, MS_REC, MS_RELA‐
381       TIME, MS_SHARED, MS_SLAVE, MS_STRICTATIME and MS_UNBINDABLE were  added
382       to glibc headers in version 2.12.
383

CONFORMING TO

385       This  function  is  Linux-specific  and  should not be used in programs
386       intended to be portable.
387

NOTES

389       Since Linux 2.4 a single filesystem can be mounted  at  multiple  mount
390       points, and multiple mounts can be stacked on the same mount point.
391
392       The  mountflags  argument may have the magic number 0xC0ED (MS_MGC_VAL)
393       in the top 16 bits.  (All of the other flags discussed  in  DESCRIPTION
394       occupy the low order 16 bits of mountflags.)  Specifying MS_MGC_VAL was
395       required in kernel versions prior to 2.4, but since  Linux  2.4  is  no
396       longer required and is ignored if specified.
397
398       The  original  MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69 when a
399       different MS_SYNC was added to <mman.h>.
400
401       Before Linux 2.4 an attempt to execute a  set-user-ID  or  set-group-ID
402       program  on  a filesystem mounted with MS_NOSUID would fail with EPERM.
403       Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently
404       ignored in this case.
405
406   Per-process namespaces
407       Starting  with  kernel  2.4.19, Linux provides per-process mount names‐
408       paces.  A mount namespace is the set of filesystem mounts that are vis‐
409       ible  to  a  process.   Mount-point namespaces can be (and usually are)
410       shared between multiple processes, and changes to the namespace  (i.e.,
411       mounts  and unmounts) by one process are visible to all other processes
412       sharing the same namespace.  (The pre-2.4.19  Linux  situation  can  be
413       considered  as  one  in  which  a  single namespace was shared by every
414       process on the system.)
415
416       A child process created by fork(2) shares its parent's mount namespace;
417       the mount namespace is preserved across an execve(2).
418
419       A process can obtain a private mount namespace if: it was created using
420       the clone(2) CLONE_NEWNS flag, in which case its new namespace is  ini‐
421       tialized  to  be  a  copy  of  the namespace of the process that called
422       clone(2); or it calls  unshare(2)  with  the  CLONE_NEWNS  flag,  which
423       causes  the  caller's  mount  namespace to obtain a private copy of the
424       namespace that it was previously sharing with other processes, so  that
425       future  mounts  and  unmounts by the caller are invisible to other pro‐
426       cesses (except child processes that the  caller  subsequently  creates)
427       and vice versa.
428
429       The  Linux-specific  /proc/[pid]/mounts  file exposes the list of mount
430       points in the mount namespace of the process with the specified ID; see
431       proc(5) for details.
432

SEE ALSO

434       mountpoint(1),   umount(2),   mount_namespaces(7),  path_resolution(7),
435       findmnt(8), lsblk(8), mount(8), umount(8)
436

COLOPHON

438       This page is part of release 4.16 of the Linux  man-pages  project.   A
439       description  of  the project, information about reporting bugs, and the
440       latest    version    of    this    page,    can     be     found     at
441       https://www.kernel.org/doc/man-pages/.
442
443
444
445Linux                             2018-02-02                          MOUNT(2)
Impressum