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 โ€” mountflags includes MS_REMOUNT.
  • Create a bind mount โ€” mountflags includes MS_BIND.
  • Change the propagation type of an existing mount โ€” mountflags includes one of MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE.
  • Move an existing mount to a new location โ€” mountflags includes MS_MOVE.
  • Create a new mount โ€” mountflags includes 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 using chattr(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:
    • the inode needs to be updated for some change unrelated to file timestamps;
    • the application employs fsync(2), syncfs(2), or sync(2);
    • an undeleted inode is evicted from memory; or
    • more than 24 hours have passed since the inode was written to disk.

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 in fcntl(2).) since Linux 4.5, this mount option requires the CAP_SYS_ADMIN capability and a kernel configured with the CONFIG_MANDATORY_FILE_LOCKING option. 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 what MS_NOATIME gives you โ€” that is, MS_NOATIME implies MS_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 permission nosuid_transition, which in turn needs also the policy capability nnp_nosuid_transition.
  • MS_RDONLY โ€” mount filesystem read-only. it's giving "look, don't touch" โœ‹
  • MS_REC (since Linux 2.4.11) โ€” used together with MS_BIND to 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 of atime is less than or equal to the file's last modification time (mtime) or last status change time (ctime). this one's useful for programs like mutt(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 (unless MS_NOATIME was specified), and the MS_STRICTATIME flag 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 obsolete MS_VERBOSE flag (available since Linux 2.4.12), which means the same thing. rip MS_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 the MS_NOATIME and MS_RELATIME flags.
  • MS_SYNCHRONOUS โ€” make writes on this filesystem synchronous (as though the O_SYNC flag to open(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, and readlink(1), readlink(2), realpath(1), and realpath(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, and MS_NOSUID are settable on a per-mount-point basis.
  • additionally, since Linux 2.6.16: MS_NOATIME and MS_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 both MS_BIND and MS_REC flags) 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 peep path_resolution(7).)
  • EACCES โ€” An attempt was made to mount a read-only filesystem without giving the MS_RDONLY flag.

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 device source is located on a filesystem that's mounted with the MS_NODEV option.
  • 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 same source and target.
  • EBUSY โ€” source cannot 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 โ€” source had an invalid superblock.
  • EINVAL โ€” A remount operation (MS_REMOUNT) was attempted, but source was not already mounted on target.
  • EINVAL โ€” A move operation (MS_MOVE) was attempted, but the mount tree under source includes unbindable mounts and target is a mount that has propagation type MS_SHARED.
  • EINVAL โ€” A move operation (MS_MOVE) was attempted, but the parent mount of the source mount has propagation type MS_SHARED.
  • EINVAL โ€” A move operation (MS_MOVE) was attempted, but source was not a mount, or was '/'.
  • EINVAL โ€” A bind operation (MS_BIND) was requested where source referred to a mount namespace magic link (i.e., a /proc/pid/ns/mnt magic link, or a bind mount to such a link) and the propagation type of the parent mount of target was MS_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 โ€” mountflags includes more than one of MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE.
  • EINVAL โ€” mountflags includes MS_SHARED, MS_PRIVATE, MS_SLAVE, or MS_UNBINDABLE and also includes a flag other than MS_REC or MS_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, and target is a descendant of source.
  • EMFILE โ€” (In case no block device is required:) Table of dummy devices is full.
  • ENAMETOOLONG โ€” A pathname was longer than MAXPATHLEN.
  • ENODEV โ€” filesystemtype not 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, see proc_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. See mount_namespaces(7) for details of mount namespaces and mount propagation.
  • ENOTBLK โ€” source is not a block device (and a device was required).
  • ENOTDIR โ€” target, or a prefix of source, is not a directory.
  • ENXIO โ€” The major number of the block device source is out of range.
  • EPERM โ€” The caller does not have the required privileges.
  • EPERM โ€” An attempt was made to modify (MS_REMOUNT) the MS_RDONLY, MS_NOSUID, or MS_NOEXEC flag, or one of the "atime" flags (MS_NOATIME, MS_NODIRATIME, MS_RELATIME) of an existing mount, but the mount is locked; see mount_namespaces(7).
  • EROFS โ€” Mounting a read-only filesystem was attempted without giving the MS_RDONLY flag. See EACCES, 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_NEWNS flag โ€” in which case its new namespace is initialized to be a copy of the namespace of the process that called clone(2).
  • Or it calls unshare(2) with the CLONE_NEWNS flag โ€” 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 ๐ŸŒˆ


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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms