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.
mount [-t TYPE] [-o OPTIONS] DEVICE DIRECTORY mount --bind OLDDIR NEWDIR
Try it
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.
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
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/wwwshows 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. UseUUID=there so a changed/dev/sdXname does not break boot. Test withmount -abefore 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,noexecon/tmp,/var/tmpand 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 asnfs-commonorntfs-3g, or a damaged filesystem.dmesg | tailusually has the real reason. Seedmesg. mountoutput formats differ fromfindmnt.mountprintsdevice on /dir type fs (options);findmntshows a tree and is better for scripts.- The truth is in
/proc/self/mounts. The old/etc/mtabis 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/isomounts a file as if it were a disk.