Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

mount

Attach a file system (disk, partition, ISO, network share) to a folder, or show what is mounted.

Level
RHCSA exam
Group
Disks and file systems
Needs root
For changes
Package
util-linux

What it does

mount DEVICE FOLDER makes the file system on DEVICE visible in FOLDER (the mount point). The type is detected automatically. mount -a mounts everything in /etc/fstab that is not mounted yet — the test after editing fstab. Options (-o) control the behaviour: read-only, no programs, no SUID …

Without arguments it lists all mounts; findmnt shows the same in a clearer way.

How to write it

mount [OPTION]... DEVICE|UUID=…|LABEL=… DIRECTORY
mount [OPTION]... DEVICE|DIRECTORY
mount -a [-t TYPE] [-O OPTIONS]

Main parts

defaults
rw, suid, dev, exec, auto, nouser, async.
ro / rw
Read-only / read-write.
noexec
Programs cannot run from this file system.
nosuid
SUID/SGID bits do not work.
nodev
Device files do not work.
noatime / relatime
Do not update / update access times sometimes.
_netdev
Network file system: mount after the network is up.
nofail
Do not fail the boot if the device is missing.
noauto
Not mounted by mount -a or at boot.
user / users
Normal users may mount it.
loop
Mount a file (like an ISO) through a loop device.
remount
Change options of a mounted file system.
bind
Mount a folder in a second place.
context=
SELinux context for the whole file system.
uid=, gid=, umask=
Owner and mode for file systems without Linux rights (vfat).

Options 29

Most used

-a, --all
Mount everything in /etc/fstab.
-t, --types TYPE
File system type (xfs, ext4, vfat, nfs, iso9660, tmpfs …).
-o, --options OPTIONS
Mount options, comma separated.
-r, --read-only
Read-only (same as -o ro).
-w, --rw, --read-write
Read-write.
-L, --label LABEL
Mount by label.
-U, --uuid UUID
Mount by UUID.
-B, --bind
Bind mount (a folder in another place).
-R, --rbind
Bind mount with all sub-mounts.
-M, --move
Move a mount to another folder.
-m, --mkdir[=MODE]
Create the mount point if it is missing.
-O, --test-opts OPTIONS
With -a: only fstab lines with these options.
-T, --fstab PATH
Use another fstab.
-F, --fork
With -a: mount in parallel.
-f, --fake
Do everything except the mount (test).
-n, --no-mtab
Do not write /etc/mtab (old systems).
-l, --show-labels
Show labels in the list.
-c, --no-canonicalize
Do not resolve paths.
-i, --internal-only
Do not call /sbin/mount.TYPE helpers.
-N, --namespace NS
Mount in another mount namespace.
--source DEVICE, --target DIR
Name the source or target clearly.
--target-prefix DIR
Prefix for all targets.
--onlyonce
Fail if already mounted.
--options-mode MODE
How to use fstab options (ignore, append, prepend, replace).
--options-source SOURCE
Where to read options (fstab, mtab, disable).
--options-source-force
Always read options from the source.
-v, --verbose
Verbose.
-h, --help
Show help.
-V, --version
Show the version.

Examples 12

$ run as a normal user# run as root (or with sudo)

  1. 1Mount a partition

    mkdir /data; mount /dev/vdb1 /data

    The type is detected.

  2. 2Mount by UUID or label

    mount UUID="4e5c7a6b-3f1d-4c2e-9a5b-7d2f8e1c0a93" /data
    mount LABEL=data /data

    Stable names.

  3. 3Test /etc/fstab

    systemctl daemon-reload; mount -a

    No output = all lines work. Do it before every reboot.

  4. 4Mount an ISO file

    mount -o loop,ro rhel-10.0-x86_64-dvd.iso /repo

    Use it as a local repository.

  5. 5Read-only

    mount -o ro /dev/vdb1 /mnt

    Safe for inspection of a disk.

  6. 6Change options without unmount

    mount -o remount,ro /data

    Also used in rescue mode: mount -o remount,rw /.

  7. 7Harden /tmp-like folders (security)

    mount -o remount,noexec,nosuid,nodev /var/tmp

    Attackers cannot run downloaded programs from there. Put it in fstab to keep it.

  8. 8Bind mount a folder

    mount --bind /srv/www /var/www/html

    Same files in two places.

  9. 9A RAM disk

    mount -t tmpfs -o size=512M tmpfs /mnt/ram

    Fast temporary space; gone after unmount.

  10. 10NFS share

    mount -t nfs server2:/exports/share /mnt

    Network file systems are covered in the NFS chapter.

  11. 11Create the mount point automatically

    mount -m /dev/vdb1 /mnt/new

    Newer util-linux.

  12. 12List mounts of one type

    mount -t xfs

    Or better: findmnt -t xfs.

Watch out

  • Mounting on a folder hides its old content until you unmount.
  • A mount by hand is gone after reboot; use /etc/fstab or a mount unit.

Files

/etc/fstab
File systems to mount at boot.
/proc/self/mountinfo
The kernel list of mounts.

Exit codes

0Done.
1Wrong use or permissions.
2System error (out of memory, cannot fork …).
4Internal mount bug.
8User interrupt.
16Problems writing or locking mtab.
32Mount failure.
64Some mounts worked (with -a).

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man 8 mount