mount(2) System Calls Manual mount(2) mount - . LIBRARY Standard C library (libc, -lc) #include int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *_Nullable data); mount() , source ( , , , ), target( ). (Linux: CAP_SYS_ADMIN). filesystemtype /proc/filesystems (: "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse", "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660"). . The data argument is interpreted by the different filesystems. Typically it is a string of comma-separated options understood by this filesystem. See mount(8) for details of the options available for each filesystem type. This argument may be specified as NULL, if there are no options. mount() , , mountflags. , mountflags, : o : mountflags MS_REMOUNT. o (bind mount): mountflags MS_BIND. o : mountflags MS_SHARED, MS_PRIVATE, MS_SLAVE MS_UNBINDABLE. o : mountflags MS_MOVE. o : mountflags . . mount() mountflags, . , mountflags. , . . MS_DIRSYNC ( Linux 2.5.19) . chattr(1). MS_LAZYTIME ( Linux 4.0) , (atime, mtime, ctime) . : o , ; o fsync(2), syncfs(2), or sync(2); o ; o 24 . , inode, mtime atime. , , atime mtime 24 . , , , MS_STRICTATIME ( MS_STRICTATIME MS_LAZYTIME , stat(2) , atime ). MS_MANDLOCK Permit mandatory locking on files in this filesystem. (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. MS_NOATIME ( ) . MS_NODEV ( ) . MS_NODIRATIME . MS_NOATIME; MS_NOATIME MS_NODIRATIME. MS_NOEXEC . MS_NOSUID Do not honor set-user-ID and set-group-ID bits or file capabilities when executing programs from this filesystem. In addition, SELinux domain transitions require the permission nosuid_transition, which in turn needs also the policy capability nnp_nosuid_transition. MS_RDONLY . MS_REC ( Linux 2.4.11) MS_BIND . . MS_RELATIME ( Linux 2.6.20) (atime) , atime (mtime) (ctime). (, mutt(1)), , . Linux 2.6.30 ( MS_NOATIME), MS_STRICTATIME. , Linux 2.6.30 , . MS_SILENT ( Linux 2.6.17) (printk()) . MS_VERBOSE ( Linux 2.4.12), . MS_STRICTATIME ( Linux 2.6.30) (atime) ( Linux 2.6.30). MS_NOATIME MS_RELATIME. MS_SYNCHRONOUS ( O_SYNC open(2) , ). MS_NOSYMFOLLOW ( Linux 5.10) Do not follow symbolic links when resolving paths. Symbolic links can still be created, and readlink(1), readlink(2), realpath(1), and realpath(3) all still work properly. Linux 2.4 ( ), -- , ( ). : o Linux 2.4: MS_NODEV, MS_NOEXEC MS_NOSUID . o Additionally, since Linux 2.6.16: MS_NOATIME and MS_NODIRATIME. o Additionally, since Linux 2.6.20: MS_RELATIME. 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 will be shared by all subsequent mounts of the same filesystem. Subsequently, the settings of the flags can be changed via a remount operation (see below). Such changes will be visible via all mounts associated with the filesystem. Linux 2.6.16 MS_RDONLY , . , . . , MS_REMOUNT mountflags. mountflags data . target mount(). source filesystemtype . mountflags data , mount(), , . The following mountflags can be changed: 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. Note that changes to per-superblock flags are visible via all mounts of the associated filesystem (because the per-superblock flags are shared by all mounts). Linux 3.17, MS_NOATIME, MS_NODIRATIME, MS_RELATIME, MS_STRICTATIME mountflags , ( MS_RELATIME). 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 underlying filesystem. Specifying mountflags as: MS_REMOUNT | MS_BIND | MS_RDONLY will make access through this mountpoint read-only, without affecting other mounts. mountflags MS_BIND (, Linux 2.4), . . chroot(2). filesystemtype data . The remaining bits (other than MS_REC, described below) in the mountflags argument are also ignored. (The bind mount has the same mount options as the underlying mount.) However, see the discussion of remounting above, for a method of making an existing bind mount read-only. , , ; , . MS_REC, : source ( ) target. mountflags MS_SHARED, MS_PRIVATE, MS_SLAVE, MS_UNBINDABLE ( Linux 2.6.15), . , . MS_REC ( ) MS_SILENT (). source, filesystemtype data . : MS_SHARED Make this mount shared. Mount and unmount events immediately under this mount will propagate to the other mounts that are members of this mount's peer group. Propagation here means that the same mount or unmount will automatically occur under all of the other mounts in the peer group. Conversely, mount and unmount events that take place under peer mounts will propagate to this mount. MS_PRIVATE Make this mount private. Mount and unmount events do not propagate into or out of this mount. MS_SLAVE If this is a shared mount that is a member of a peer group that contains other members, convert it to a slave mount. If this is a shared mount that is a member of a peer group that contains no other members, convert it to a private mount. Otherwise, the propagation type of the mount is left unchanged. When a mount is a slave, mount and unmount events propagate into this mount from the (master) shared peer group of which it was formerly a member. Mount and unmount events under this mount do not propagate to any peer. A mount can be the slave of another peer group while at the same time sharing mount and unmount events with a peer group of which it is a member. MS_UNBINDABLE . . (mount() MS_BIND MS_REC) (. ., ) . By default, changing the propagation type affects only the target mount. If the MS_REC flag is also specified in mountflags, then the propagation type of all mounts under target is also changed. ( , ) mount_namespaces(7). If mountflags contains the flag MS_MOVE (available since Linux 2.4.18), then move a subtree: source specifies an existing mount and target specifies the new location to which that mount is to be relocated. The move is atomic: at no point is the subtree unmounted. mountflags , filesystemtype data. 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() performs its default action: creating a new mount. source specifies the source for the new mount, and target specifies the directory at which to create the mount point. filesystemtype data, mountflags. On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. , , . . Linux. EACCES - , (. path_resolution(7)). EACCES , ms_rdonly. : , ; , ; ; , - / ( ). EROFS. EACCES source , MS_NODEV. EBUSY , . EBUSY source , , . EFAULT - . EINVAL . EINVAL (MS_REMOUNT), source 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 (MS_MOVE), source 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 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 MS_SHARED, MS_PRIVATE, MS_SLAVE, MS_UNBINDABLE. EINVAL mountflags MS_SHARED, MS_PRIVATE, MS_SLAVE, MS_UNBINDABLE , MS_REC MS_SILENT. EINVAL , . EINVAL (. ., , , ) (MS_BIND) (MS_REC), , , . ELOOP . ELOOP , . EMFILE ( , ): . ENAMETOOLONG MAXPATHLEN. ENODEV filesystemtype . ENOENT . ENOMEM . ENOTBLK source ( ). ENOTDIR target source . ENXIO source . EPERM . 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 MS_RDONLY. EACCES, . Linux. The definitions of MS_DIRSYNC, MS_MOVE, MS_PRIVATE, MS_REC, MS_RELATIME, MS_SHARED, MS_SLAVE, MS_STRICTATIME, and MS_UNBINDABLE were added to glibc headers in glibc 2.12. Linux 2.4 , . The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits. (All of the other flags discussed 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 is no longer required and is ignored if specified. MS_SYNC MS_SYNCHRONOUS 1.1.69, MS_SYNC. Linux 2.4 set-UID set-GID , MS_NOSUID, EPERM. Linux 2.4 set-UID set-GID . Starting with Linux 2.4.19, Linux provides mount namespaces. A mount namespace is the set of filesystem mounts that are visible to a process. Mount namespaces can be (and usually are) shared between multiple processes, and changes to the namespace (i.e., mounts and unmounts) by one process are visible to all other processes sharing the same namespace. (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.) -, fork(2), ; execve(2). : clone(2) CLONE_NEWNS; , clone(2); unshare(2) CLONE_NEWNS; , , ( , ) . For further details on mount namespaces, see mount_namespaces(7). Parental relationship between mounts Each mount has a parent mount. The overall parental relationship of all mounts defines the single directory hierarchy seen by the processes within a mount namespace. 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. In the case where 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. The parental relationship between mounts can be discovered via the /proc/pid/mountinfo file (see below). /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. 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. See proc(5) and mount_namespaces(7) for details of this file. . mountpoint(1), chroot(2), ioctl_iflags(2), mount_setattr(2), pivot_root(2), umount(2), mount_namespaces(7), path_resolution(7), findmnt(8), lsblk(8), mount(8), umount(8) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . mount(2)