mount(2)
๐ NAME ๐
mount โ mount a filesystem ๐
(this one's from the System Calls Manual, section 2, iykyk)
โจ LIBRARY โจ
Standard C library (libc, -lc) ๐ซถ
๐ธ SYNOPSIS ๐ธ
#include <sys/mount.h>
int mount(const char *_Nullable source, const char *target,
const char *_Nullable filesystemtype, unsigned long mountflags,
const void *_Nullable data);
๐ DESCRIPTION ๐
okay so mount() does exactly what it says on the tin: it attaches the filesystem specified by source to the location (a directory or file) named by the pathname in target. and bestie, source is usually a pathname pointing at a device, but plot twist โ it can also be the pathname of a directory or a file, or honestly just a dummy string. the range is giving versatility ๐ซ
to actually mount filesystems you need the appropriate privilege. on Linux that's the CAP_SYS_ADMIN capability. no cap, you need it ๐
the filesystemtype values the kernel supports are listed in /proc/filesystems โ like "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse", "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660". and more types can pop up once the right modules get loaded, so the roster is always expanding โจ
the data argument is interpreted by each different filesystem โ it's a whole "you do you" situation. typically it's a string of comma-separated options that the filesystem understands. for the deets on what options each filesystem type takes, go look at mount(8). and if there are no options at all, you can just pass this argument as NULL, easy ๐
every call to mount() performs one of a bunch of general types of operation, depending on which bits are set in mountflags. the choice of which operation happens is decided by testing the bits set in mountflags, and the tests happen in this exact order, so pay attention bestie:
- Remount an existing mount โ
mountflagsincludesMS_REMOUNT. - Create a bind mount โ
mountflagsincludesMS_BIND. - Change the propagation type of an existing mount โ
mountflagsincludes one ofMS_SHARED,MS_PRIVATE,MS_SLAVE, orMS_UNBINDABLE. - Move an existing mount to a new location โ
mountflagsincludesMS_MOVE. - Create a new mount โ
mountflagsincludes none of the above flags.
each of these operations gets its own deep dive later in this page. and you can stack further flags into mountflags to modify how mount() behaves โ those are described right below ๐
๐ Additional mount flags ๐
here's the list of the extra flags you can throw into mountflags. heads up tho: some operation types straight-up ignore some or all of these flags, and that's explained later on in the page. don't come for me, it's just how it is ๐
MS_DIRSYNC(since Linux 2.5.19) โ makes directory changes on this filesystem synchronous. (fun fact: you can get this same property for individual directories or subtrees usingchattr(1).)MS_LAZYTIME(since Linux 4.0) โ reduces on-disk updates of inode timestamps (atime,mtime,ctime) by keeping those changes only in memory. the on-disk timestamps get updated only when:
this mount option significantly cuts down the writes needed to update the inode's timestamps, especially mtime and atime. but โ and this is the important part ๐จ โ in the event of a system crash, the atime and mtime fields on disk might be out of date by up to 24 hours.
examples of workloads where this option could be of significant benefit include frequent random writes to preallocated files, plus cases where the MS_STRICTATIME mount option is also enabled. (the advantage of combining MS_STRICTATIME and MS_LAZYTIME is that stat(2) will return the correctly updated atime, but the atime updates will be flushed to disk only in the cases listed above. chef's kiss combo honestly ๐ง)
MS_MANDLOCKโ permits mandatory locking on files in this filesystem. (note: mandatory locking must still be enabled on a per-file basis, as described infcntl(2).) since Linux 4.5, this mount option requires theCAP_SYS_ADMINcapability and a kernel configured with theCONFIG_MANDATORY_FILE_LOCKINGoption. mandatory locking has been fully deprecated in Linux 5.15, so this flag should be considered deprecated. yeah... it's giving legacy ๐MS_NOATIMEโ do not update access times for (all types of) files on this filesystem.MS_NODEVโ do not allow access to devices (special files) on this filesystem.MS_NODIRATIMEโ do not update access times for directories on this filesystem. this flag is a subset of whatMS_NOATIMEgives you โ that is,MS_NOATIMEimpliesMS_NODIRATIME.MS_NOEXECโ do not allow programs to be executed from this filesystem.MS_NOSUIDโ do not honor set-user-ID and set-group-ID bits or file capabilities when executing programs from this filesystem. also, SELinux domain transitions require the permissionnosuid_transition, which in turn needs also the policy capabilitynnp_nosuid_transition.MS_RDONLYโ mount filesystem read-only. it's giving "look, don't touch" โMS_REC(since Linux 2.4.11) โ used together withMS_BINDto create a recursive bind mount, and together with the propagation type flags to recursively change the propagation type of all of the mounts in a subtree. see below for more deets.MS_RELATIME(since Linux 2.6.20) โ when a file on this filesystem is accessed, update the file's last access time (atime) only if the current value ofatimeis less than or equal to the file's last modification time (mtime) or last status change time (ctime). this one's useful for programs likemutt(1)that need to know when a file has been read since it was last modified. since Linux 2.6.30, the kernel defaults to the behavior this flag provides (unlessMS_NOATIMEwas specified), and theMS_STRICTATIMEflag is required to get the traditional semantics back. and also: since Linux 2.6.30, the file's last access time is always updated if it's more than 1 day old.MS_SILENT(since Linux 2.6.17) โ suppresses the display of certain (printk()) warning messages in the kernel log. this flag supersedes the misnamed and obsoleteMS_VERBOSEflag (available since Linux 2.4.12), which means the same thing. ripMS_VERBOSE, you had a bad name bestie ๐ญMS_STRICTATIME(since Linux 2.6.30) โ always update the last access time (atime) when files on this filesystem are accessed. (this was the default behavior before Linux 2.6.30.) specifying this flag overrides the effect of setting theMS_NOATIMEandMS_RELATIMEflags.MS_SYNCHRONOUSโ make writes on this filesystem synchronous (as though theO_SYNCflag toopen(2)was specified for all file opens to this filesystem).MS_NOSYMFOLLOW(since Linux 5.10) โ do not follow symbolic links when resolving paths. symlinks can still be created, andreadlink(1),readlink(2),realpath(1), andrealpath(3)all still work properly. so everyone's fine, chill ๐
from Linux 2.4 onward, some of those flags are settable on a per-mount basis, while others apply to the superblock of the mounted filesystem โ meaning all mounts of the same filesystem share those flags. (previously, like in the olden days, all of the flags were per-superblock.)
the per-mount-point flags are as follows:
- since Linux 2.4:
MS_NODEV,MS_NOEXEC, andMS_NOSUIDare settable on a per-mount-point basis. - additionally, since Linux 2.6.16:
MS_NOATIMEandMS_NODIRATIME. - additionally, since Linux 2.6.20:
MS_RELATIME.
and the following flags are per-superblock: MS_DIRSYNC, MS_LAZYTIME, MS_MANDLOCK, MS_SILENT, and MS_SYNCHRONOUS. the initial settings of these flags are determined on the first mount of the filesystem, and every subsequent mount of the same filesystem shares them. after that, you can change the settings of the flags via a remount operation (see below). those changes will be visible via all mounts associated with the filesystem โ it's a group chat, everyone sees it ๐ฌ
since Linux 2.6.16, MS_RDONLY can be set or cleared on a per-mount-point basis as well as on the underlying filesystem superblock. the mounted filesystem will be writable only if neither the filesystem nor the mount point are flagged as read-only. both have to say yes bestie, no half measures ๐
๐ Remounting an existing mount ๐
an existing mount can be remounted by specifying MS_REMOUNT in mountflags. this is the glow-up hack that lets you change the mountflags and data of an existing mount without having to unmount and remount the filesystem. target should be the same value you specified in the initial mount() call. no need to redo the whole thing, just tweak the vibe โจ
the source and filesystemtype arguments are ignored.
the mountflags and data arguments should match the values used in the original mount() call โ except for those parameters you're deliberately changing, obviously.
these are the mountflags you can change: MS_LAZYTIME, MS_MANDLOCK, MS_NOATIME, MS_NODEV, MS_NODIRATIME, MS_NOEXEC, MS_NOSUID, MS_RELATIME, MS_RDONLY, MS_STRICTATIME (whose effect is to clear the MS_NOATIME and MS_RELATIME flags), and MS_SYNCHRONOUS. attempts to change the setting of the MS_DIRSYNC and MS_SILENT flags during a remount are silently ignored โ like, they just don't hear you ๐. and note that changes to per-superblock flags are visible via all mounts of the associated filesystem, because per-superblock flags are shared by all mounts.
since Linux 3.17, if none of MS_NOATIME, MS_NODIRATIME, MS_RELATIME, or MS_STRICTATIME is specified in mountflags, then the remount operation preserves the existing values of these flags (rather than defaulting to MS_RELATIME). preservation era ๐ซถ
since Linux 2.6.26, the MS_REMOUNT flag can be used with MS_BIND to modify only the per-mount-point flags. this is particularly useful for setting or clearing the "read-only" flag on a mount without changing the filesystem parameters of the underlying filesystem. the data argument is ignored. the existing per-mount-point flags of the mount point are cleared and replaced with those in mountflags. which means โ and this is the gotcha โ if you wish to preserve any existing per-mount-point flags, you need to include them in mountflags, along with the per-mount-point flags you wish to set (or with the flags you wish to clear missing). specifying mountflags as:
MS_REMOUNT | MS_BIND | MS_RDONLY
will make access through this mount point read-only (clearing all other per-mount-point flags), without affecting other mounts of this filesystem. clean, targeted, iconic ๐
๐ Creating a bind mount ๐
If mountflags includes MS_BIND (hey, this has been around since Linux 2.4 bestie), then you're doing a bind mount. A bind mount is literally making a file or a whole directory subtree visible at some other point inside the one single directory hierarchy. And the glow-up? Bind mounts can cross filesystem boundaries and span chroot(2) jails. Iconic behavior, no cap.
The filesystemtype and data arguments get ignored. Sorry to them.
The rest of the bits in mountflags (other than MS_REC, which we'll get to in a sec) are also ignored. That's because the bind mount just rocks the same mount options as the underlying mount. But bestie โ peep the discussion of remounting above if you wanna know the trick for making an existing bind mount read-only.
By default, when you bind mount a directory, only that directory gets mounted. If there are submounts hanging out under that directory tree, they do not come along. But if you also pass the MS_REC flag, then you get a recursive bind mount: every submount under the source subtree (except the unbindable ones, they said what they said) also gets bind mounted at the corresponding spot in the target subtree. ๐
๐ฆ Changing the propagation type of an existing mount ๐ฆ
If mountflags includes one of MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE (all of these have been available since Linux 2.6.15), then you're changing the propagation type of a mount that already exists. Specify more than one of these? Boom โ error. Pick a lane.
The only other flags you can specify while changing propagation type are MS_REC (more below) and MS_SILENT (which straight up gets ignored, rude).
The source, filesystemtype, and data arguments are ignored.
So here's what each propagation type flag actually means, bestie, let's break it down:
MS_SHAREDโ Make this mount shared. Mount and unmount events that happen immediately under this mount will propagate to the other mounts that are members of this mount's peer group. "Propagate" = the same mount or unmount automatically happens under all the other mounts in the peer group too. And the other direction? Mount and unmount events that happen under peer mounts propagate to this mount. It's giving mutuals. ๐MS_PRIVATEโ Make this mount private. Mount and unmount events do not propagate into or out of this mount. Boundaries. ๐งMS_SLAVEโ Okay so: if this is a shared mount that's part of a peer group with other members, it gets converted to a slave mount. If it's a shared mount in a peer group with no other members, it gets converted to a private mount instead. And otherwise (neither of those), the propagation type just stays exactly as it was, untouched.
When a mount is a slave, mount and unmount events propagate into this mount from the (master) shared peer group it used to be a member of. But mount and unmount events under this mount do not propagate out to any peer. One-way street.
And plot twist: a mount can be the slave of another peer group while at the same time sharing mount and unmount events with a peer group it's a member of. Multitasking queen. ๐
MS_UNBINDABLEโ Make this mount unbindable. This is like a private mount, and on top of that, this mount can't be bind mounted at all. And when you do a recursive bind mount (mount()with bothMS_BINDandMS_RECflags) on a directory subtree, any unbindable mounts inside that subtree are automatically pruned (meaning: not replicated) when the subtree gets replicated to make the target subtree.
By default, changing the propagation type only affects the target mount itself. But if MS_REC is also chillin' in mountflags, then the propagation type of all mounts under target also gets changed. Recursive, obviously. โจ
For all the further deets about mount propagation types (including which default propagation type new mounts get assigned), go read mount_namespaces(7).
๐ธ Moving a mount ๐ธ
If mountflags contains the MS_MOVE flag (available since Linux 2.4.18), then you're moving a subtree: source specifies an existing mount, and target specifies the new location you want that mount relocated to. The move is atomic โ at literally no point in time is the subtree unmounted. Seamless. ๐ฆ
The remaining bits in the mountflags argument get ignored, and so do the filesystemtype and data arguments.
โญ Creating a new mount โญ
If none of MS_REMOUNT, MS_BIND, MS_MOVE, MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE is specified in mountflags, then mount() just does its default thing: creating a new mount. source specifies the source for the new mount, and target specifies the directory where the mount point gets created.
Here the filesystemtype and data arguments actually get used, and you can layer in further bits in mountflags to modify how the call behaves. Main character energy. ๐
๐ RETURN VALUE ๐
On success, zero is returned. On error, -1 is returned, and errno gets set to indicate the error. Classic.
๐ญ ERRORS ๐ญ
The error values below come from filesystem-type-independent errors. Every individual filesystem type may have its own special errors and its own special behavior โ check the Linux kernel source code for those deets.
EACCESโ A component of a path was not searchable. (Also peeppath_resolution(7).)EACCESโ An attempt was made to mount a read-only filesystem without giving theMS_RDONLYflag.
A filesystem might be read-only for a whole bunch of reasons, including: it lives on a read-only optical disk; it resides on a device with a physical switch that's been set to mark the device read-only; the filesystem implementation was compiled with read-only support; or errors got detected when the filesystem was initially mounted, so it was marked read-only and can't be remounted as read-write (not until those errors get fixed, anyway).
Some filesystems instead return the error EROFS on an attempt to mount a read-only filesystem.
EACCESโ The block devicesourceis located on a filesystem that's mounted with theMS_NODEVoption.EBUSYโ An attempt was made to stack a new mount directly on top of an existing mount point that was created in this mount namespace with the samesourceandtarget.EBUSYโsourcecannot be remounted read-only, because it still holds files open for writing.EFAULTโ One of the pointer arguments points outside the user address space.EINVALโsourcehad an invalid superblock.EINVALโ A remount operation (MS_REMOUNT) was attempted, butsourcewas not already mounted ontarget.EINVALโ A move operation (MS_MOVE) was attempted, but the mount tree undersourceincludes unbindable mounts andtargetis a mount that has propagation typeMS_SHARED.EINVALโ A move operation (MS_MOVE) was attempted, but the parent mount of thesourcemount has propagation typeMS_SHARED.EINVALโ A move operation (MS_MOVE) was attempted, butsourcewas not a mount, or was'/'.EINVALโ A bind operation (MS_BIND) was requested wheresourcereferred to a mount namespace magic link (i.e., a/proc/pid/ns/mntmagic link, or a bind mount to such a link) and the propagation type of the parent mount oftargetwasMS_SHARED, but propagation of the requested bind mount could lead to a circular dependency that might prevent the mount namespace from ever being freed. ๐EINVALโmountflagsincludes more than one ofMS_SHARED,MS_PRIVATE,MS_SLAVE, orMS_UNBINDABLE.EINVALโmountflagsincludesMS_SHARED,MS_PRIVATE,MS_SLAVE, orMS_UNBINDABLEand also includes a flag other thanMS_RECorMS_SILENT.EINVALโ An attempt was made to bind mount an unbindable mount.EINVALโ In an unprivileged mount namespace (i.e., a mount namespace owned by a user namespace that was created by an unprivileged user), a bind mount operation (MS_BIND) was attempted without specifying (MS_REC), which would have revealed the filesystem tree underneath one of the submounts of the directory being bound.ELOOPโ Too many links encountered during pathname resolution.ELOOPโ A move operation was attempted, andtargetis a descendant ofsource.EMFILEโ (In case no block device is required:) Table of dummy devices is full.ENAMETOOLONGโ A pathname was longer thanMAXPATHLEN.ENODEVโfilesystemtypenot configured in the kernel.ENOENTโ A pathname was empty or had a nonexistent component.ENOMEMโ The kernel could not allocate a free page to copy filenames or data into.ENOSPCโ Number of mounts will exceed the limit after this syscall in some mount namespaces. This limit is controlled by/proc/sys/fs/mount-max, seeproc_sys_fs(5)for details of this limit. Note that this limit applies both to the mount namespace where the mount operation occurs and to any mount namespaces to which the mount will propagate. Seemount_namespaces(7)for details of mount namespaces and mount propagation.ENOTBLKโsourceis not a block device (and a device was required).ENOTDIRโtarget, or a prefix ofsource, is not a directory.ENXIOโ The major number of the block devicesourceis out of range.EPERMโ The caller does not have the required privileges.EPERMโ An attempt was made to modify (MS_REMOUNT) theMS_RDONLY,MS_NOSUID, orMS_NOEXECflag, or one of the "atime" flags (MS_NOATIME,MS_NODIRATIME,MS_RELATIME) of an existing mount, but the mount is locked; seemount_namespaces(7).EROFSโ Mounting a read-only filesystem was attempted without giving theMS_RDONLYflag. SeeEACCES, above.
๐ STANDARDS ๐
Linux. Periodt.
๐ HISTORY ๐
The definitions of MS_DIRSYNC, MS_MOVE, MS_PRIVATE, MS_REC, MS_RELATIME, MS_SHARED, MS_SLAVE, MS_STRICTATIME, and MS_UNBINDABLE got added to glibc headers in glibc 2.12.
Since Linux 2.4, a single filesystem can be mounted at multiple mount points, and multiple mounts can be stacked on the same mount point. Glow-up.
The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits. (All the other flags we talked about in DESCRIPTION occupy the low order 16 bits of mountflags.) Specifying MS_MGC_VAL was required before Linux 2.4, but since Linux 2.4 it's no longer required and it just gets ignored if you do specify it.
The original MS_SYNC flag got renamed to MS_SYNCHRONOUS in 1.1.69, back when a different MS_SYNC was added to <mman.h>. Name collision drama. ๐ญ
Before Linux 2.4, an attempt to execute a set-user-ID or set-group-ID program on a filesystem mounted with MS_NOSUID would fail with EPERM. Since Linux 2.4, the set-user-ID and set-group-ID bits just get silently ignored in this case.
โจ NOTES โจ
๐ช Mount namespaces ๐ช
Okay bestie, history lesson but make it cute: starting with Linux 2.4.19, Linux serves up mount namespaces. A mount namespace is literally just the set of filesystem mounts that a process can see. That's it. That's the whole vibe. ๐
These namespaces can be โ and usually are โ shared between multiple processes, and any changes to the namespace (like mounts and unmounts) made by one process are visible to every other process sharing that same namespace. And if you're wondering what life was like before 2.4.19? The pre-2.4.19 Linux situation can be considered as one in which a single namespace was shared by every process on the system. One namespace, everybody piled in. Iconic in a chaotic way.
A child process created by fork(2) shares its parent's mount namespace, and that mount namespace is preserved across an execve(2). So it just keeps getting passed down like a family recipe. ๐ซถ
Now, how does a process get its own private mount namespace? Two slay options:
- It was created using the
clone(2)CLONE_NEWNSflag โ in which case its new namespace is initialized to be a copy of the namespace of the process that calledclone(2). - Or it calls
unshare(2)with theCLONE_NEWNSflag โ which causes the caller's mount namespace to obtain a private copy of the namespace that it was previously sharing with other processes. So future mounts and unmounts by the caller are invisible to other processes (except child processes that the caller subsequently creates), and vice versa. Main character energy: your mounts, your rules.
For further details on mount namespaces, see mount_namespaces(7). No cap, it's all there. ๐
๐งฌ Parental relationship between mounts ๐งฌ
Every mount has a parent mount. It's giving family tree, but for filesystems. The overall parental relationship of all mounts defines the single directory hierarchy seen by the processes within a mount namespace. So yes, the whole directory tree you see? That's the result of all these mounts holding hands. ๐ณ
The parent of a new mount is defined when the mount is created. In the usual case, the parent of a new mount is the mount of the filesystem containing the directory or file at which the new mount is attached. But when a new mount is stacked on top of an existing mount, the parent of the new mount is the previous mount that was stacked at that location. Stacked mounts, bestie. Layers on layers. ๐
And how do you peek at the family drama? The parental relationship between mounts can be discovered via the /proc/pid/mountinfo file โ see below for the tea. โ
๐ /proc/pid/mounts and /proc/pid/mountinfo ๐
The Linux-specific /proc/pid/mounts file exposes the list of mounts in the mount namespace of the process with the specified ID. Simple, clean, to the point. โจ
The /proc/pid/mountinfo file exposes even more information about mounts, including the propagation type and mount ID information that makes it possible to discover the parental relationship between mounts. So if you need the lore, not just the list, go here. ๐
See proc(5) and mount_namespaces(7) for details of this file. Periodt.
๐ SEE ALSO ๐
mountpoint(1)chroot(2)FS_IOC_SETFLAGS(2const)mount_setattr(2)pivot_root(2)umount(2)mount_namespaces(7)path_resolution(7)findmnt(8)lsblk(8)mount(8)umount(8)
That's the whole page, bestie! This lil masterpiece came from Linux man-pages 6.20, dated 2026-10-10, and it's literally the mount(2) manual. Go forth and mount responsibly. ๐๐ฆ๐ธ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Rickard E. Faith <faith@cs.unc.edu>
- Copyright 1994, Andries E. Brouwer <aeb@cwi.nl>
- Copyright 2002-2016, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms