Skip to content

Latest commit

 

History

History
194 lines (138 loc) · 8.19 KB

File metadata and controls

194 lines (138 loc) · 8.19 KB
title Linux Command Tutorial: mount
date 2026-09-12 00:00:00 +0000
categories
Technology
tags
Linux
util-linux
mount
Linux Command Tutorial
draft false
slug linux-mount-tutorial
description Authoritative reference tutorial for mount (util-linux), detailing VFS filesystem mounting, bind mounts, remounting read-only, fstab integration, and kernel boundaries.
upstream_suite util-linux
upstream_version util-linux 2.40
posix_standard None
research_date 2026-09-12

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

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

Flag Description Default
-a Mount all filesystems mentioned in /etc/fstab (except those with noauto). Specific mount
-t type Specify filesystem type (e.g. ext4, xfs, btrfs, nfs, overlay). Auto-probe via libblkid
-o opts Comma-separated list of mount options. Filesystem defaults
-r, --read-only Mount the filesystem read-only (equivalent to -o ro). Read-write
-w, --rw Mount the filesystem read-write (default). Read-write
-B, --bind Remount a subtree somewhere else (bind mount). Device mount
-R, --rbind Remount a subtree and all submounts somewhere else. Non-recursive
-v Verbose 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

Operation Command Notes
Mount partition sudo mount -t ext4 /dev/sdb1 /mnt/data Attaches block device to mount directory
Mount by UUID sudo mount UUID="..." /mnt/data Deterministic mount across reboots
Mount all from fstab sudo mount -a Mounts all unmounted entries in /etc/fstab
Emergency read-only remount sudo mount -o remount,ro /data Freezes filesystem into read-only state
Bind mount directory sudo mount --bind /src /dest Mirrors folder tree into another location
Loop mount ISO image sudo mount -o loop image.iso /mnt/iso Attaches disk image via loop device
Harden temporary mount sudo mount -o remount,nodev,nosuid,noexec /tmp Restricts execution and privilege escalation

4.2 Mounting a Partition by Device Path

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

4.3 Mounting by UUID

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:

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:

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:

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:

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 Code Meaning
0 Success: mount completed cleanly.
1 Incorrect invocation or permissions (e.g. non-root user).
2 System error (out of memory, cannot fork, cannot allocate loop device).
4 Internal mount bug.
8 User interrupt.
16 Problems writing or locking /etc/mtab.
32 Mount 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