You are on page 1of 7

mount(2) - Linux man page

Name
mount, umount - mount and unmount filesystems

Synopsis
#include <sys/mount.h> int mount(const char *source, const char *target, unsigned long mountflags, const void *data); int umount(const char *target); int umount2(const char *target, int flags); const char *filesystemtype,

Description
mount() attaches the filesystem specified by source (which is often a device name, but can also be a directory name or a dummy) to the directory specified by target. umount() and umount2() remove the attachment of the (topmost) filesystem mounted on target. Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to mount and unmount filesystems. Since Linux 2.4 a single filesystem can be visible at multiple mount points, and multiple mounts can be stacked on the same mount point. Values for the filesystemtype argument supported by the kernel are listed in /proc/filesystems (like "minix", "ext2", "msdos", "proc", "nfs", "iso9660" etc.). Further types may become available when the appropriate modules are loaded. The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits (this was required in kernel versions prior to 2.4, but is no longer required and ignored if specified), and various mount flags (as defined in <linux/fs.h> for libc4 and libc5 and in <sys/mount.h> for glibc2) in the low order 16 bits: MS_BIND (Linux 2.4 onwards) Perform a bind mount, making a file or a directory subtree visible at another point within a file system. Bind mounts may cross file system boundaries and span chroot(2) jails. The filesystemtype, mountflags, and data arguments are ignored. MS_DIRSYNC (since Linux 2.5.19) Make directory changes on this file system synchronous. (This property can be obtained for individual directories or subtrees using chattr(8).) MS_MANDLOCK Permit mandatory locking on files in this file system. (Mandatory locking must still be enabled on a per-file basis, as described in fcntl(2).) MS_MOVE Move a subtree. source specifies an existing mount point and target specifies the new location. The move is atomic: at no point is the subtree unmounted. The filesystemtype, mountflags, and data arguments are ignored.

MS_NOATIME Do not update access times for (all types of) files on this file system. MS_NODEV Do not allow access to devices (special files) on this file system. MS_NODIRATIME Do not update access times for directories on this file system. MS_NOEXEC Do not allow programs to be executed from this file system. MS_NOSUID Do not honour set-user-ID and set-group-ID bits when executing programs from this file system. MS_RDONLY Mount file system read-only. MS_REMOUNT Remount an existing mount. This is allows you to change the mountflags and data of an existing mount without having to unmount and remount the file system. source and target should be the same values specified in the initial mount() call; filesystemtype is ignored. The following mountflags can be changed: MS_RDONLY, MS_SYNCHRONOUS, MS_MANDLOCK; before kernel 2.6.16, the following could also be changed: MS_NOATIME and MS_NODIRATIME; and, additionally, before kernel 2.4, the following could also be changed: MS_NOSUID, MS_NODEV, MS_NOEXEC. MS_SYNCHRONOUS Make writes on this file system synchronous (as though the O_SYNC flag to open(2) was specified for all file opens to this file system). From Linux 2.4 onwards, the MS_NODEV, MS_NOEXEC, and MS_NOSUID flags are settable on a permount-point basis. From kernel 2.6.16 onwards, MS_NOATIME and MS_NODIRATIME are also settable on a per-mount-point basis. The data argument is interpreted by the different file systems. Typically it is a string of comma-separated options understood by this file system. See mount(8) for details of the options available for each filesystem type. Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behaviour of the operation: MNT_FORCE (since Linux 2.1.116) Force unmount even if busy. (Only for NFS mounts.) MNT_DETACH (since Linux 2.4.11) Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy. MNT_EXPIRE (since Linux 2.6.8) Mark the mount point as expired. If a mount point is not currently in use, then an initial call to umount2() with this flag fails with the error EAGAIN, but marks the mount point as expired. The mount point remains expired as long as it isn't accessed by any process. A second umount2() call specifying MNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with either MNT_FORCE or MNT_DETACH.

Return Value
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

Errors
The error values given below result from filesystem type independent errors. Each filesystem type may have its own special errors and its own special behavior. See the kernel source code for details. EACCES A component of a path was not searchable. (See also path_resolution(2).) Or, mounting a read-only filesystem was attempted without giving the MS_RDONLY flag. Or, the block device source is located on a filesystem mounted with the MS_NODEV option. EAGAIN A call to umount2() specifying MNT_EXPIRE successfully marked an unbusy file system as expired. EBUSY source is already mounted. Or, it cannot be remounted read-only, because it still holds files open for writing. Or, it cannot be mounted on target because target is still busy (it is the working directory of some task, the mount point of another device, has open files, etc.). Or, it could not be unmounted because it is busy. EFAULT One of the pointer arguments points outside the user address space. EINVAL source had an invalid superblock. Or, a remount (MS_REMOUNT) was attempted, but source was not already mounted on target. Or, a move (MS_MOVE) was attempted, but source was not a mount point, or was '/'. Or, an unmount was attempted, but target was not a mount point. Or, umount2() was called with MNT_EXPIRE and either MNT_DETACH or MNT_FORCE. ELOOP Too many link encountered during pathname resolution. Or, a move was attempted, while 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. ENOTBLK source is not a block device (and a device was required). ENOTDIR The second argument, or a prefix of the first argument, 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.

Conforming to

These functions are Linux-specific and should not be used in programs intended to be portable.

History
The original umount() function was called as umount(device) and would return ENOTBLK when called with something other than a block device. In Linux 0.98p4 a call umount(dir) was added, in order to support anonymous devices. In Linux 2.3.99-pre7 the call umount(device) was removed, leaving only umount(dir) (since now devices can be mounted in more than one place, so specifying the device does not suffice). The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69 when a different MS_SYNC was added to <mman.h>. 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 are just silently ignored in this case.

Mounting File Systems

Mounting file systems is the next logical step to creating file systems. Mounting refers to naming the file system and attaching it to the inverted tree structure. This enables access from any point in the structure. A file system can be mounted during booting, manually from the command line, or automatically if you have enabled the automount feature. With remote file systems, the server shares the file system over the network and the client mounts it. The / and /usr file systems, as mentioned earlier, are mounted during booting. To mount a file system, attach it to a directory anywhere in the main inverted tree structure. This directory is known as the mount point. The syntax of the mount command is as follows:
# mount <logical block device name> <mount point>

The following steps mount a file system c0t2d0s7 on the /export/home directory:
# mkdir /export/home # mount /dev/dsk/c0t2d0s7 /export/home

You can verify the mounting by using the mount command, which lists all the mounted file systems. Note: If the mount point directory has any content prior to the mounting operation, it is hidden and remains inaccessible until the file system is unmounted.

Data is stored and retrieved from the physical disk where the file system is mounted.

Although there are no defined specifications for creating the file systems on the physical disk, slices are usually allocated as following: 0. Root or / Files and directories of the OS.
1. 2. 3. 4. 5. 6. 7. Swap Virtual memory space. Refers to the entire disk. /export Different OS versions. /export/swap Unused. Left to user's choice. /opt Application software added to a system. /usr OS commands by users. /home Files created by users.

The slices shown above are all allocated on a single single disk. However, there is no restriction that all file systems need to be located on a single disk. They can also span across multiple disks. Slice 2 refers to the entire disk. Hence, if you want to allocate an entire disk for a file system, you can do so by creating it on slice 2. The mount command supports a variety of useful options. Option
-o largefiles -o nolargefiles -o rw -o ro -o bg -o fg -p -m -O

Description Files larger than 2GB are supported in the file system. Does not mount file systems with files larger than 2GB. File system is mounted with read and write permissions. File system is mounted with read-only permission. Repeats mount attempts in the background. Used with non-critical file systems. Repeats mount attempts in the foreground. Used with critical file systems. Prints the list of mounted file systems in /etc/vfstab format. Mounts without making an entry in /etc/mnt /etc/tab file. Performs an Overlay mount. Mounts over an existing mount point.

The mountall command mounts all file systems that have the mount at boot field in the /etc/vfstab file set to yes. It can also be used anytime after booting. Unmounting File Systems

A file system can be unmounted with the umount command. The following is the syntax for umount:
umount <mount-point or logical block device name > File systems cannot be unmounted when they are in use or when the umount command is issued from any subdirectory within the file system mount point.

Note: A file system can be unmounted forcibly if you use the -f option of the umount command. Please refer to the man page to learn about the use of these options. The umountall command is used to unmount a group of file systems. The umountall command unmounts all file systems in the /etc/mnttab file except the /, /usr, /var, and /proc file systems. If you want to unmount all the file systems from a specified host, use the -h option. If you want to unmount all the file systems mounted from remote hosts, use the -r option.
/etc/vfstab File

The /etc/vfstab (Virtual File System Table) file plays a very important role in system operations. This file contains one record for every device that has to be automatically mounted when the system enters run level 2. Column Name device to mount device to fsck Mount point FS type fsck pass Description The logical block name of the device to be mounted. It can also be a remote resource name for NFS. The logical raw device name to be subjected to the fsck check during booting. It is not applicable for read-only file systems, such as High Sierra File System (HSFS) and network File systems such as NFS. The mount point directory. The type of the file system. The number used by fsck to decide whether the file system is to be checked. 0 File system is not checked. 1 File system is checked sequentially. 2 File system is checked simultaneously along with other file systems where this field is set to 2. Mount at boot Mount options The file system to be mounted by the mount all command at boot time is determined by this field. The options are either yes or no. The mount options to be supported by the mount command while the particular file system is mounted.

Note the no values in this field for the root, /usr, and /var file systems. These are mounted by default. The fd field refers to the floppy disk and the swap field refers to the tmpfs in the /tmp directory. A sample vfstab file looks like:

#device device mount #to mount to fsck point # fd /dev/fd fd no /proc /proc proc no /dev/dsk/c0t0d0s4 swap /dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 /dev/dsk/c0t0d0s6 /dev/rdsk/c0t0d0s6 /dev/dsk/c0t0d0s3 /dev/rdsk/c0t0d0s3 /dev/dsk/c0t0d0s7 /dev/rdsk/c0t0d0s7 yes /dev/dsk/c0t0d0s5 /dev/rdsk/c0t0d0s5 /dev/dsk/c0t0d0s1 /dev/rdsk/c0t0d0s1 swap /tmp tmpfs yes -

FS type / /usr /var

fsck pass

mount mount at boot options

no ufs ufs ufs

1 1 1 ufs 2 ufs

no no no 2 yes 2 yes -

/export/home /opt ufs

/usr/openwin

Finding Information About the Mounted File Systems

The /etc/mnttab file comprises a table that defines which partitions and/or disks are currently mounted by the system. The /etc/mnttab file contains the following details about each mounted file system:

The file system name The mount point directory The file system type The mount command options A number denoting the time of the mounted file system

You might also like