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  source is already mounted.
318
319       EBUSY  source cannot be remounted read-only,  because  it  still  holds
320              files open for writing.
321
322       EBUSY  source  cannot be mounted on target because target is still busy
323              (it is the working directory of some thread, the mount point  of
324              another device, has open files, etc.).
325
326       EFAULT One  of  the  pointer  arguments points outside the user address
327              space.
328
329       EINVAL source had an invalid superblock.
330
331       EINVAL A remount operation (MS_REMOUNT) was attempted, but  source  was
332              not already mounted on target.
333
334       EINVAL A  move  operation (MS_MOVE) was attempted, but source was not a
335              mount point, or was '/'.
336
337       EINVAL mountflags includes more  than  one  of  MS_SHARED,  MS_PRIVATE,
338              MS_SLAVE, or MS_UNBINDABLE.
339
340       EINVAL mountflags   includes   MS_SHARED,   MS_PRIVATE,   MS_SLAVE,  or
341              MS_UNBINDABLE and also includes a  flag  other  than  MS_REC  or
342              MS_SILENT.
343
344       EINVAL An attempt was made to bind mount an unbindable mount.
345
346       EINVAL In  an  unprivileged  mount  namespace  (i.e., a mount namespace
347              owned by a user namespace that was created  by  an  unprivileged
348              user),  a  bind  mount operation (MS_BIND) was attempted without
349              specifying (MS_REC), which would have  revealed  the  filesystem
350              tree  underneath  one  of  the  submounts of the directory being
351              bound.
352
353       ELOOP  Too many links encountered during pathname resolution.
354
355       ELOOP  A move operation was attempted, and target is  a  descendant  of
356              source.
357
358       EMFILE (In case no block device is required:) Table of dummy devices is
359              full.
360
361       ENAMETOOLONG
362              A pathname was longer than MAXPATHLEN.
363
364       ENODEV filesystemtype not configured in the kernel.
365
366       ENOENT A pathname was empty or had a nonexistent component.
367
368       ENOMEM The kernel could not allocate a free page to copy  filenames  or
369              data into.
370
371       ENOTBLK
372              source is not a block device (and a device was required).
373
374       ENOTDIR
375              target, or a prefix of source, is not a directory.
376
377       ENXIO  The major number of the block device source is out of range.
378
379       EPERM  The caller does not have the required privileges.
380

VERSIONS

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

CONFORMING TO

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

NOTES

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

SEE ALSO

436       mountpoint(1),   umount(2),   mount_namespaces(7),  path_resolution(7),
437       findmnt(8), lsblk(8), mount(8), umount(8)
438

COLOPHON

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