Skip to content

The Linux Command Tutorial series provides rigorous, upstream-verified references for essential system commands across Linux distributions and UNIX-like environments. Each article focuses on a single executable, combining exhaustive option documentation, verified real-world examples, security boundaries, and best practices directly derived from official source documentation and POSIX standards.


1. Introduction

Upstream: util-linux 2.40 | POSIX: Linux-Specific (util-linux extension) | Safety Tier: privileged-system-destructive | Scope: filesystem-mounting

mount attaches a filesystem found on a block device, network export, or pseudo-filesystem to the global Virtual File System (VFS) hierarchy at a specified directory (the mount point).

  • Upstream Project & Provenance: Developed and maintained under util-linux (util-linux).
  • Portability & Standards Baseline: mount is a system administration command specific to Linux VFS semantics; it is not standardized in POSIX.1-2024.
  • Target Research Implementation: Audited against util-linux 2.40 (mount(8)).
  • Applicability & Lifecycle: The fundamental utility for block storage attachment, bind mounts, container filesystem root isolation, and storage management.

2. Syntax and Command Model

2.1 Canonical Synopsis

bash
mount [-l] [-a] [-v] [-t fstype] [-o options] device dir
mount --bind olddir newdir
mount --make-shared | --make-slave | --make-private | --make-unbindable mountpoint

2.2 Execution Model & /etc/fstab Resolution

  • When given both device and dir, mount invokes the kernel mount(2) or modern fsopen(2) / fsmount(2) system calls.
  • When given only device or only dir (e.g. mount /data), mount parses /etc/fstab (and systemd mount units) to locate the corresponding device, mount point, filesystem type, and options automatically.

3. Options

3.1 Primary Operational Flags

FlagDescriptionDefault
-aMount all filesystems mentioned in /etc/fstab (except those with noauto).Specific mount
-t typeSpecify filesystem type (e.g. ext4, xfs, btrfs, nfs, overlay).Auto-probe via libblkid
-o optsComma-separated list of mount options.Filesystem defaults
-r, --read-onlyMount the filesystem read-only (equivalent to -o ro).Read-write
-w, --rwMount the filesystem read-write (default).Read-write
-B, --bindRemount a subtree somewhere else (bind mount).Device mount
-R, --rbindRemount a subtree and all submounts somewhere else.Non-recursive
-vVerbose mode.Normal

3.2 Key Mount Options (-o)

  • ro / rw: Mount read-only vs read-write.
  • remount: Attempt to remount an already-mounted filesystem with new options (e.g. mount -o remount,ro /mountpoint).
  • nodev: Do not interpret character or block special devices on the filesystem (critical for security on /tmp and /home).
  • nosuid: Do not allow set-user-identifier or set-group-identifier bits to take effect.
  • noexec: Disallow direct execution of any binaries on the mounted filesystem.
  • noatime: Do not update file access times (atime); eliminates write overhead on read operations.

4. Basic Usage

4.1 Quick-Reference Cheatsheet Card

OperationCommandNotes
Mount partitionsudo mount -t ext4 /dev/sdb1 /mnt/dataAttaches block device to mount directory
Mount by UUIDsudo mount UUID="..." /mnt/dataDeterministic mount across reboots
Mount all from fstabsudo mount -aMounts all unmounted entries in /etc/fstab
Emergency read-only remountsudo mount -o remount,ro /dataFreezes filesystem into read-only state
Bind mount directorysudo mount --bind /src /destMirrors folder tree into another location
Loop mount ISO imagesudo mount -o loop image.iso /mnt/isoAttaches disk image via loop device
Harden temporary mountsudo mount -o remount,nodev,nosuid,noexec /tmpRestricts execution and privilege escalation

4.2 Mounting a Partition by Device Path

bash
sudo mount -t ext4 /dev/sdb1 /mnt/data

4.3 Mounting by UUID

bash
sudo mount UUID="3f2a1b4c-9d8e-4a7b-b5c6-d7e8f9a0b1c2" /mnt/data

5. Practical Operations

5.1 Emergency Read-Only Remount

Safely locking a corrupt or failing disk into read-only mode to prevent write corruption during diagnostics:

bash
sudo mount -o remount,ro /data
  • Technical Analysis: remount,ro notifies the kernel VFS layer to flush pending journal transactions and refuse further write system calls (EACCES), protecting block integrity.

5.2 Creating a Loop Device Mount from an ISO or Image

Mounting a disk image file without manual losetup:

bash
sudo mount -o loop ubuntu-server.iso /mnt/iso
  • Modern mount automatically allocates an available loop device (/dev/loopX) and attaches the file.

5.3 Hardening /tmp with Security Mount Options

Remounting temporary storage with maximum security restrictions:

bash
sudo mount -o remount,nosuid,nodev,noexec /tmp
  • Prevents malicious actors from dropping and executing binaries or creating SUID root escalation binaries in /tmp.

6. Advanced Usage

6.1 Bind Mounts for Containers and Jails

Exposing an existing host directory inside an unprivileged chroot jail without duplicating files:

bash
sudo mount --bind /var/www/shared_assets /srv/jail/www/assets
  • Both paths now point to the identical directory inode hierarchy. Modifications in either path are immediately visible in the other.

7. Exit Status, Environment, and Configuration

7.1 Exit Status Codes

Exit CodeMeaning
0Success: mount completed cleanly.
1Incorrect invocation or permissions (e.g. non-root user).
2System error (out of memory, cannot fork, cannot allocate loop device).
4Internal mount bug.
8User interrupt.
16Problems writing or locking /etc/mtab.
32Mount failure (filesystem type unknown, superblock corrupt, device busy).

8. Safety, Security, and Portability

8.1 Testing /etc/fstab Edits Without Rebooting

CAUTION

Syntax errors or invalid UUIDs in /etc/fstab can cause the Linux kernel to drop into an emergency maintenance shell during system boot. Never test /etc/fstab by rebooting; always run sudo findmnt --verify to validate syntax and paths before restarting.


9. Best Practices

  1. Mount by Persistent UUID or LABEL, Never Raw Device Names:
    • Guidance: Write UUID=... or LABEL=... in /etc/fstab.
    • Authoritative Justification: Linux kernel device enumeration (/dev/sda, /dev/sdb) is non-deterministic across reboots and hardware changes.
  2. Apply nodev,nosuid,noexec on Non-Root Partitions:
    • Guidance: Harden /tmp, /var/tmp, and /home with nodev,nosuid.
    • Authoritative Justification: Upstream CIS benchmark and Linux kernel security guidelines recommend disabling SUID and device node creation on world-writable partitions.
  3. Use noatime for High-Performance Workloads:
    • Guidance: Append noatime to SSD and database partitions.
    • Authoritative Justification: Prevents every read operation from triggering a metadata write to the disk.

References

  1. util-linux mount(8) Manual: https://man7.org/linux/man-pages/man8/mount.8.html
  2. Linux VFS Documentation: https://docs.kernel.org/filesystems/vfs.html
  3. util-linux Upstream Repository: https://github.com/util-linux/util-linux

Last updated:

Released under the MIT License.