Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Disks and Filesystems

Linux mount command

Reference for the Linux mount command: attach a filesystem to a directory, list mounts, use options such as ro, noexec and bind, and read /proc/self/mounts.

mount attaches a filesystem to a directory. Linux has a single directory tree; a disk partition, a USB stick, a network share or a memory-backed tmpfs becomes part of it only when it is mounted on an existing directory (the mount point). Whatever was in that directory is hidden until the filesystem is unmounted again.

Without arguments, mount lists what is mounted now. Mounting requires root in almost all cases (or an entry in /etc/fstab that marks it as user-mountable), so in our sandbox the attaching examples are read-only; the live examples read the kernel's list of mounts, which anyone can do.

Terminal
mount [-t TYPE] [-o OPTIONS] DEVICE DIRECTORY
mount --bind OLDDIR NEWDIR

Try it

Bash The kernel's list of mounts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Why mounting needs privileges

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
mount [-fnrsvw] [-t TYPE] [-o OPTIONS] DEVICE|LABEL=|UUID= DIRECTORY
mount -a [-t TYPE]
mount --bind|--rbind|--move SOURCE DIRECTORY
mount -o remount,OPTIONS DIRECTORY
Form or option Description
mount List all mounted filesystems. mount -t ext4 lists only that type.
-t TYPE Filesystem type: ext4, xfs, vfat, tmpfs, nfs, iso9660, ... Usually detected automatically.
-o OPTIONS Comma-separated options (see below).
-a Mount everything listed in /etc/fstab that is not mounted yet (except noauto).
--bind SRC DIR Make a directory or file visible at a second place. --rbind includes submounts.
--move Move an existing mount point.
-r, -w Mount read-only or read-write.
-L LABEL, -U UUID Select the device by label or UUID instead of /dev/....
-n Do not update /etc/mtab.
-v Verbose output.

Common options: ro/rw, noexec (no programs), nosuid (ignore setuid), nodev, noatime (do not update access times), sync, defaults (rw,suid,dev,exec,auto,nouser,async), remount, loop (use a file as a device), size= (tmpfs), uid=/gid=/umask= (FAT and similar).

Returns: 0 on success. Non-zero codes include 1 (incorrect invocation or permissions), 32 (mount failure, for example wrong filesystem type) and 64 (some mounts succeeded with -a).

Usage notes

  • Mount over a non-empty directory works, but the old content is hidden, not deleted. Unmounting brings it back.
  • Bind mounts do not copy anything. mount --bind /data/site /srv/www shows the same files in two places; containers use this to hand directories to a service.
  • Make it permanent by adding a line to /etc/fstab. Use UUID= there so a changed /dev/sdX name does not break boot. Test with mount -a before rebooting; a bad line can block the next boot.
  • Remount to change options without unmounting: mount -o remount,ro / switches the root filesystem to read-only (for example to check it).
  • Hardening. Put nosuid,nodev,noexec on /tmp, /var/tmp and user-writable data mounts where possible.
  • "mount: wrong fs type, bad option, bad superblock". The message covers many causes: wrong -t, a missing helper such as nfs-common or ntfs-3g, or a damaged filesystem. dmesg | tail usually has the real reason. See dmesg.
  • mount output formats differ from findmnt. mount prints device on /dir type fs (options); findmnt shows a tree and is better for scripts.
  • The truth is in /proc/self/mounts. The old /etc/mtab is normally a symbolic link to it. Each process may have its own mount namespace, which is why containers see a different list.
  • Loop mounts. mount -o loop image.iso /mnt/iso mounts a file as if it were a disk.