← Full reference

mount

Attaching file systems — mount, umount, -o options, /etc/fstab, findmnt, loop devices and bind

Linux has a single directory tree, and every file system (a disk partition, an image, tmpfs, a network share) is attached to some directory — a mount point. mount attaches, umount detaches, findmnt shows what is mounted where. What to mount at boot is described in /etc/fstab.

Only root can mount (it needs the CAP_SYS_ADMIN capability). This privilege is disabled in the IzzyLab sandbox: mount and umount answer "permission denied" — even for tmpfs and bind. What does work: findmnt, findmnt --verify for checking fstab, blkid and creating images (see filesystems).

Syntax

mount                                  # list (findmnt is better)
mount [-t type] [-o options] source dir
mount dir                              # take the rest from /etc/fstab
mount -a                               # mount everything from fstab
umount dir|device
findmnt [options] [device|dir]

mount options

OptionWhat it does
-t typeFS type: ext4, xfs, vfat, tmpfs, nfs… Usually detected automatically
-o listcomma-separated mount options (table below)
-r / -wread-only (-o ro) / read-write (the default)
-amount everything from fstab except noauto lines and what is already mounted
-T fileanother file instead of /etc/fstab
-f"fake": everything except the actual system call
-vverbose
-L label / -U uuidsource by label or UUID (same as LABEL=…, UUID=…)
-mcreate the mount point directory if it doesn't exist
--bind / -Bmake a directory also available at another place
--rbind / -Rthe same, including all nested mount points
--move / -Mmove a mount point

-o options

OptionMeaning
defaultsrw,suid,dev,exec,auto,nouser,async — the standard set for fstab
ro / rwread-only / read-write
remountchange options of an already mounted FS without unmounting: -o remount,ro /data
noexecforbid running programs from this FS
nosuidignore setuid/setgid bits
nodevignore device files
noatime / relatimedon't update access time / update it rarely (relatime is the default)
loopmount an image file via a loop device
bindsame as --bind
noautodon't mount on mount -a and at boot
nofaildon't stop the boot if the device is missing
user / usersallow a regular user to mount (from fstab only)
uid=, gid=, umask=owner and permissions for file systems without Unix permissions (vfat, ntfs)
size=100M, mode=1777size and permissions for tmpfs
_netdevnetwork FS: mount after the network is up

umount options

OptionWhat it does
-l"lazy" unmount: remove from the tree now, release when files are closed
-fforce (for an unreachable NFS)
-Runmount together with everything nested
-dfor loop: also free the loop device
-aunmount everything that is mounted
-qdon't complain if not mounted

/etc/fstab

One line — one file system, six whitespace-separated fields:

# source                                   mountpoint type  options           dump pass
UUID=247f8868-2629-4efe-94cd-dd6ac84027cc  /data      ext4  defaults,noatime  0    2
LABEL=backup                               /backup    ext4  defaults,nofail   0    2
/srv/disk.img                              /mnt/img   ext4  loop,ro           0    0
tmpfs                                      /mnt/tmp   tmpfs size=100M,mode=1777 0  0
#FieldMeaning
1source/dev/sdb1, UUID=…, LABEL=…, path to an image, tmpfs, server:/export
2mount pointthe directory must exist; for swap — none
3typeext4, xfs, tmpfs, nfs, swap, auto
4optionsas in -o; at least defaults
5dump0 almost always
6passfsck check order at boot: 1 — root, 2 — the rest, 0 — don't check

blkid shows the UUID and label. Names like /dev/sdb1 can change after a reboot, the UUID doesn't.

findmnt

OptionWhat it does
(no options)tree of all mount points: TARGET, SOURCE, FSTYPE, OPTIONS
dir / deviceonly this mount point; exit code 1 if there is none
-T pathwhich FS this file or directory is on
-t type[,type]only the given types
-O optiononly those with the given mount option (-O ro)
-lflat list instead of a tree
-nno header
-o columnschoose columns: TARGET,SOURCE,FSTYPE,OPTIONS,SIZE,USED,AVAIL,UUID,LABEL
-Ddf-style output
-J / -P / -rJSON / KEY="value" pairs / raw output — for scripts
-sread /etc/fstab instead of current mounts
-F filewith -s: another file instead of fstab
-x (--verify)check fstab; --verbose — detailed; --tab-file file — another file

Examples

# what is mounted where; which FS a directory is on
findmnt
findmnt -T /var/log
findmnt -n -o FSTYPE,OPTIONS /

# all real disks, df style
findmnt -D -t ext4,xfs

# is something mounted on a directory (for scripts)
mountpoint -q /data && echo mounted

# mount a partition and an image (needs root on a real machine)
mkdir -p /data /mnt/img
mount /dev/sdb1 /data
mount -o loop,ro /srv/disk.img /mnt/img

# an in-memory tmpfs and a bind mount of a directory elsewhere
mount -t tmpfs -o size=100M tmpfs /mnt/tmp
mount --bind /srv/www /var/www

# make an FS read-only on the fly and back
mount -o remount,ro /data
mount -o remount,rw /data

# check fstab BEFORE rebooting (works even without the right to mount)
findmnt --verify
findmnt --verify --verbose --tab-file ./fstab.new

# mount everything from fstab and unmount
mount -a
umount /data

# a loop device by hand
losetup -f --show /srv/disk.img     # prints, e.g., /dev/loop0
losetup -l
losetup -d /dev/loop0

Pitfalls

  • "target is busy" on umount. Something is working in the directory — including your own shell if you are standing in it. Leave it (cd /) and find the processes: fuser -vm /data (the psmisc package, not in the sandbox) or by hand: ls -l /proc/*/cwd /proc/*/fd 2>/dev/null | grep /data. Last resort — umount -l.
  • An error in fstab breaks the boot. A line with a nonexistent UUID and no nofail drops the system into emergency mode. After editing, always run findmnt --verify and mount -a.
  • mount -f checks nothing: it reports "successfully mounted" even for a nonexistent device and a wrong type. To check fstab, use findmnt --verify.
  • Mounting hides the directory's contents. Files that were in /data before mount are not gone, they are just invisible while the FS is mounted. That's how gigabytes "go missing": du doesn't see them, df counts them.
  • The mount point must exist — mount doesn't create it (except with -m). Create the directory from fstab in advance.
  • Changes don't persist. mount from the command line lasts until reboot; for an FS to be mounted always, you need a line in /etc/fstab.
  • /etc/mtab and mount with no arguments show the same as /proc/self/mounts; findmnt presents it more clearly and can filter.
  • In a container (Docker, the IzzyLab sandbox) mounting is forbidden without --privileged or CAP_SYS_ADMIN, and there is no /dev/loop* at all: "cannot find an unused loop device". You can inspect an image's contents without mounting via debugfs (see filesystems).

See also

filesystems · df-du · proc · dd · truncate · capabilities