In Linux systems, mount is an extremely fundamental command. Unlike Windows, which automatically assigns drive letters, Linux organizes all files and directories into a single inverted tree structure that starts at the root directory /. To access a new storage device, you must manually mount it somewhere in this tree.
1. What mount Does
Simply put, mount is used to "attach" a filesystem.
When you connect a new hard disk, USB drive, or network storage to a Linux system, the system does not automatically assign a drive letter. You need to connect that storage device to an empty directory in the directory tree. This process is called mounting, and that directory is called a mount point.
With mount, you tell the system: "Please present the filesystem on this device under this specific directory."
2. mount Parameters
Full syntax of mount:
mount [-t filesystem_type] [-o mount_options] <device_name> <mount_point>Core Parameters
| Parameter | Meaning | Notes |
|---|---|---|
-t | Filesystem type | Specifies the filesystem type on the device, such as ext4, xfs, vfat, ntfs, nfs, iso9660, etc. Linux can usually detect it automatically, so this can often be omitted |
-o | Mount options | Multiple options can be separated by commas: ro (read-only), rw (read-write), remount (remount), loop (mount a regular file as a block device) |
-a | Mount all | Reads /etc/fstab and mounts all devices that are not yet mounted. This is executed automatically at boot |
Common Examples
mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb
mount -t ext4 /dev/sdb1 /mnt/data
mount -o ro /dev/sdb1 /mnt/readonly
mount -o loop /path/to/image.iso /mnt/iso
mount --bind /home/data /var/www/html3. Filesystem Types Explained
The filesystem type specified with -t is essentially telling the kernel which "data organization rule" the device uses. Common types can be grouped into four categories:
1. Native Linux filesystems
| Filesystem | Characteristics | Typical use |
|---|---|---|
| ext4 | Most classic and widely used; stable and mature. Default on Ubuntu/Debian | General-purpose servers and personal computers |
| xfs | High-performance journaling filesystem; excels with large files and high concurrency. Default on CentOS/RHEL | Database servers, large-scale storage |
| btrfs | Copy-on-write (CoW), with native snapshots, transparent compression, and multi-device management | Scenarios requiring frequent backup and rollback |
2. Cross-platform and removable-device filesystems
| Filesystem | Characteristics | Notes |
|---|---|---|
| vfat (FAT32) | Best compatibility; almost all devices can read/write | Does not support single files larger than 4GB |
| exfat | Upgraded FAT32, removes the 4GB limitation | Preferred for large USB drives and cross-platform removable disks |
| ntfs | Default format on Windows | Linux is read-only by default; ntfs-3g is needed for read/write |
3. Network filesystems
| Filesystem | Characteristics | Typical use |
|---|---|---|
| nfs | Standard protocol for sharing directories between Linux systems | File sharing between Linux/Unix servers |
| cifs | Based on SMB protocol | Mounting Windows shared folders on Linux |
4. Special and in-memory filesystems
| Filesystem | Characteristics | Typical use |
|---|---|---|
| tmpfs | Memory-based, very fast, data disappears after reboot | /tmp temporary directory, high-speed cache |
| overlay | Union filesystem that stacks multiple directories like layers | Core storage technology in Docker containers |
| iso9660 | CD/DVD filesystem | Mounting .iso image files |
4. Viewing the Filesystem a File Belongs To
One concept needs clarification: an individual file itself does not have a "filesystem". Filesystems apply to disk partitions or mount points. To see the filesystem type of the partition containing a file, you can use the following methods:
df -T: most intuitive
$ df -T /var/log/syslog
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 50212344 1234567 46000000 5% /The Type column is the filesystem type, and Mounted on is the mount point.
findmnt: most professional
$ findmnt --target /var/log/syslog
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda2 ext4 rw,relatime,errors=remount-rolsblk -f: global overview
$ lsblk -fShows all disks, partitions, filesystem types, and mount points in a tree structure.
5. OS Concepts Behind mount
1. Everything is a file
In Linux, hardware devices are also abstracted as files and placed under /dev:
- Block devices: disks like
/dev/sda, USB drives like/dev/sdb, etc., read/written in blocks. The essence ofmountis mapping a block device file to a directory. - Shadowing effect: when mounting onto a non-empty directory, existing files are "hidden" (not deleted) and become visible again after
umount.
2. Virtual File System (VFS)
The Linux kernel implements the VFS (Virtual File System) abstraction layer, providing a unified system call interface (open(), read(), write()) to upper-layer applications. Whether the underlying filesystem is ext4, NTFS, or NFS, VFS calls the corresponding filesystem driver, so users do not need to care about the differences.
┌─────────────────────────────┐
│ User programs (open/read) │
├─────────────────────────────┤
│ VFS abstraction │
├──────┬──────┬───────┬───────┤
│ ext4 │ xfs │ ntfs │ nfs │ ← Filesystem drivers
├──────┴──────┴───────┴───────┤
│ Block devices / network │
└─────────────────────────────┘3. /etc/fstab: automatic mounts at boot
At startup, the system uses the /etc/fstab (File System Table) configuration file to determine mount policy, and automatically executes mount -a:
UUID=xxxx-xxxx-xxxx / ext4 defaults 1 1
UUID=yyyy-yyyy-yyyy /home ext4 defaults 0 24. Kernel state tracking
When you run mount, it actually sends a system call to the kernel. The kernel records mount state in memory, which you can inspect as follows:
cat /proc/mounts
mount6. Advanced: Root Switching and Container Isolation
Turning a directory into a new root is one of the core operations in container technology.
chroot: classic root switching
sudo chroot /home/user/my_new_root /bin/bash- In the new
bashprocess,/actually points to/home/user/my_new_rooton the host - Prerequisite: the target directory must include a basic Linux filesystem structure (
/bin/bashand its dependent dynamic libraries under/lib) - Security limitation: it only changes path resolution and does not provide true isolation; escape risks exist
pivot_root + Mount Namespace: real isolation
This is the mechanism used by modern container runtimes (such as runc):
- Mount Namespace: creates an isolated mount tree; mount operations inside it do not affect the host
- pivot_root: replaces the root mount with a specified directory; the old root is "pushed" to a temporary location and then unmounted
sudo unshare --mount --pid --fork --root=/home/user/my_new_root /bin/bash
mount -t proc proc /procFor detailed usage of the
unsharecommand, see Linux unshare Command Explained.
Key detail: pseudo filesystems are not created automatically
After entering a new namespace, pseudo filesystems such as /proc and /sys from the host will not appear automatically, nor will they be created automatically. Why:
--rootlocks the process’s "world boundary" inside the new directory; the host’s/procis outside that boundary- The kernel only provides an isolated "mount ledger" and does not proactively populate anything
- If only Mount Namespace is isolated but PID Namespace is not, a manually mounted
/procwill still show all host processes
To achieve full container-level isolation (where /proc only shows the process itself), you need to isolate both Mount and PID namespaces and include the --fork option.