Category
Linux Command
Usage
mount [-lhV]
Manual
All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over sev- eral devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again. The standard form of the mount command, is mount -t type device dir This tells the kernel to attach the filesystem found on device (which is of type type) at the directory dir. The previous contents (if any) and owner and mode of dir become invisible, and as long as this filesystem remains mounted, the pathname dir refers to the root of the filesystem on device. The listing and help. Three forms of invocation do not actually mount anything: mount -h prints a help message mount -V prints a version string mount [-l] [-t type] lists all mounted filesystems (of type type). The option -l adds the labels in this listing. See below. The device indication. Most devices are indicated by a file name (of a block special device), like /dev/sda1, but there are other possibilities. For example, in the case of an NFS mount, device may look like knuth.cwi.nl:/dir. It is possible to indicate a block special device using its volume LABEL or UUID (see the -L and -U options below). The recommended setup is to use LABEL= or UUID= tags rather than /dev/disk/by-{label,uuid} udev symlinks in the /etc/fstab file. The tags are more readable, robust and portable. The mount(8) command internally uses udev symlinks, so use the symlinks in /etc/fstab is not advantage over LABEL=/UUID=. For more details see libblkid(3). The proc filesystem is not associated with a special device, and when mounting it, an arbitrary keyword, such as proc can be used instead of a device specification. (The customary choice none is less fortunate: the error message ‘none busy’ from umount can be confusing.) The /etc/fstab, /etc/mtab and /proc/mounts files. The file /etc/fstab (see fstab(5)), may contain lines describing what devices are usually mounted where, using which options. The command mount -a [-t type] [-O optlist] (usually given in a bootscript) causes all filesystems mentioned in fstab (of the proper type and/or having or not having the proper options) to be mounted as indicated, except for those whose line contains the noauto keyword. Adding the -F option will make mount fork, so that the filesystems are mounted simul- taneously. When mounting a filesystem mentioned in fstab or mtab, it suf- fices to give only the device, or only the mount point. The programs mount and umount maintain a list of currently mounted filesystems in the file /etc/mtab. If no arguments are given to mount, this list is printed. The mount program does not read the /etc/fstab file if device (or LABEL/UUID) and dir are specified. For example: mount /dev/foo /dir If you want to override mount options from /etc/fstab you have to use: mount device|dir -o and then the mount options from command line will be appended to the list of options from /etc/fstab. The usual behaviour is that the last option wins if there is more duplicated options. When the proc filesystem is mounted (say at /proc), the files /etc/mtab and /proc/mounts have very similar contents. The for- mer has somewhat more information, such as the mount options used, but is not necessarily up-to-date (cf. the -n option below). It is possible to replace /etc/mtab by a symbolic link to /proc/mounts, and especially when you have very large numbers of mounts things will be much faster with that symlink, but some information is lost that way, and in particular using the "user" option will fail. The non-superuser mounts. Normally, only the superuser can mount filesystems. However, when fstab contains the user option on a line, anybody can mount the corresponding system. Thus, given a line /dev/cdrom /cd iso9660 ro,user,noauto,unhide any user can mount the iso9660 filesystem found on his CDROM using the command mount /dev/cdrom or mount /cd For more details, see fstab(5). Only the user that mounted a filesystem can unmount it again. If any user should be able to unmount, then use users instead of user in the fstab line. The owner option is similar to the user option, with the restriction that the user must be the owner of the special file. This may be useful e.g. for /dev/fd if a login script makes the console user owner of this device. The group option is similar, with the restriction that the user must be member of the group of the special file. The bind mounts. Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is mount --bind olddir newdir or shortoption mount -B olddir newdir or fstab entry is: /olddir /newdir none bind After this call the same contents is accessible in two places. One can also remount a single file (on a single file). This call attaches only (part of) a single filesystem, not pos- sible submounts. The entire file hierarchy including submounts is attached a second place using mount --rbind olddir newdir or shortoption mount -R olddir newdir Note that the filesystem mount options will remain the same as those on the original mount point, and cannot be changed by passing the -o option along with --bind/--rbind. The mount options can be changed by a separate remount command, for exam- ple: mount --bind olddir newdir mount -o remount,ro newdir The move operation. Since Linux 2.5.1 it is possible to atomically move a mounted tree to another place. The call is mount --move olddir newdir or shortoption mount -M olddir newdir This will cause the contents which previously appeared under olddir to be accessed under newdir. The physical location of the files is not changed. Note also that moving a mount residing under a shared mount is invalid and unsupported (in the other words the parent of the olddir has to use private propagation flag). See /proc/self/mountinfo for the current propagation flags. The shared subtrees operations. Since Linux 2.6.15 it is possible to mark a mount and its sub- mounts as shared, private, slave or unbindable. A shared mount provides ability to create mirrors of that mount such that mounts and umounts within any of the mirrors propagate to the other mirror. A slave mount receives propagation from its mas- ter, but any not vice-versa. A private mount carries no propa- gation abilities. A unbindable mount is a private mount which cannot cloned through a bind operation. Detailed semantics is documented in Documentation/sharedsubtree.txt file in the kernel source tree. mount --make-shared mountpoint mount --make-slave mountpoint mount --make-private mountpoint mount --make-unbindable mountpoint The following commands allows one to recursively change the type of all the mounts under a given mountpoint. mount --make-rshared mountpoint mount --make-rslave mountpoint mount --make-rprivate mountpoint mount --make-runbindable mountpoint
Share your experience or ask a question