Filesystems, Formatting, Mounting, and /etc/fstab
Learn how Linux filesystems are created, identified, mounted, verified, and declared for boot—without treating formatting or fstab edits as casual commands.
Learning objectives
By the end of this lesson
- Explain what a filesystem provides beyond raw block storage.
- Compare practical characteristics of ext4, XFS, Btrfs, tmpfs, and network filesystems.
- Use
mkfs,mount,umount,findmnt, and filesystem labels safely. - Interpret every field in
/etc/fstaband validate a proposed entry before reboot. - Build and clean up a filesystem inside a disposable image file.
1. A filesystem turns blocks into named, protected objects
Raw block devices provide addressable storage. A filesystem adds directories, filenames, inode or object metadata, allocation maps, timestamps, ownership, permissions, free-space accounting, crash-recovery structures, and consistency rules. The kernel exposes a common Virtual Filesystem interface so applications can use familiar operations even when the underlying filesystem implementations differ.
flowchart LR A["Application: open, read, write"] --> B["Linux VFS"] B --> C["ext4"] B --> D["XFS"] B --> E["Btrfs"] B --> F["tmpfs or network filesystem"] C --> G["Block device"] D --> G E --> G
Choosing a filesystem is an operational decision involving workload behavior, support lifecycle, recovery tools, growth and shrink capabilities, snapshots, checksumming, quotas, and the distribution's defaults. Avoid selecting solely from benchmark headlines.
2. Match filesystem capabilities to the operating model
Use findmnt -t ext4,xfs,btrfs to see what a system actually runs. The tools used to create and repair a filesystem are filesystem-specific; mkfs is commonly a dispatcher to programs such as mkfs.ext4 or mkfs.xfs.
3. Formatting creates metadata and destroys previous interpretation
# Inspect first; these commands do not create a filesystem.
lsblk -f
sudo blkid
sudo wipefs --no-act /dev/CONFIRMED_DEVICE
# Examples only—never substitute a real device casually.
# sudo mkfs.ext4 -L appdata /dev/CONFIRMED_EMPTY_DEVICE
# sudo mkfs.xfs -L appdata /dev/CONFIRMED_EMPTY_DEVICE
A formatting command writes superblocks and allocation metadata. Existing data may become difficult or impossible to recover even when the command completes instantly. A change plan should capture the device identity, expected old signatures, intended filesystem type and label, ownership model after mounting, and restore or rollback route.
Never copy a mkfs command from a tutorial onto an unverified /dev/* path. This lesson's lab uses a regular file as disposable backing storage.
4. Mounts attach filesystem instances to directories
A mount point is an ordinary directory used as the attachment location for a filesystem. When mounted, the filesystem's root becomes visible at that directory and temporarily hides any pre-existing directory contents until unmounted.
# Inspect mount relationships
findmnt
findmnt --target /var/lib
findmnt --source UUID=YOUR-UUID
# Show kernel mount data and propagation where needed
findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS,PROPAGATION
# A bind mount exposes an existing directory at another path
mkdir -p "$HOME/source-dir" "$HOME/view-dir"
# sudo mount --bind "$HOME/source-dir" "$HOME/view-dir"
# sudo umount "$HOME/view-dir"
Mount options affect correctness and security. Examples include ro, rw, noexec, nosuid, nodev, discard, and filesystem-specific performance or recovery options. Apply them from a threat and workload model rather than a universal hardening list.
5. /etc/fstab is declarative boot-time storage policy
Each non-comment entry has six fields:
# source target type options dump pass
UUID=1111-2222 /srv/app ext4 defaults,nodev,nosuid 0 2
Prefer a verified UUID= or LABEL=; network filesystems use a server/export expression.
The mount-point directory. Spaces and special characters require fstab escaping.
Filesystem implementation such as ext4, xfs, nfs, or swap.
Comma-separated policy including defaults, security flags, network dependencies, or nofail.
Legacy backup-tool flag, commonly zero.
Filesystem-check order; root is commonly 1, other checkable local filesystems 2, and XFS or non-checkable entries 0.
# Review active fstab and resolve identifiers
cat /etc/fstab
findmnt --fstab --evaluate
# Validate syntax and semantics before rebooting
sudo findmnt --verify --verbose
# After an intentional fstab edit, test mounts without rebooting.
# sudo mount -av
On systemd systems, fstab entries are translated into mount units. Options such as x-systemd.automount, x-systemd.device-timeout=, and _netdev can express boot ordering or on-demand behavior, but they should be documented because they change failure semantics.
6. Hands-on lab: create and mount a disposable filesystem image
This lab never touches a real disk. It requires mkfs.ext4 and sudo for the temporary mount. Read every command before running it.
lab="$HOME/devops-academy/linux/chapter10/lesson02"
image="$lab/lab-filesystem.img"
mountpoint="$lab/mnt"
mkdir -p "$mountpoint"
cd "$lab"
# Create a sparse 128 MiB regular file.
truncate -s 128M "$image"
# Confirm it is a regular file, then create ext4 inside that file.
file "$image"
mkfs.ext4 -F -L devops-lab "$image"
# Mount through the kernel's loop mechanism.
sudo mount -o loop,nodev,nosuid "$image" "$mountpoint"
findmnt --target "$mountpoint"
sudo sh -c 'printf "storage lab\n" > "$1/README.txt"' sh "$mountpoint"
sudo chown "$USER":"$(id -gn)" "$mountpoint/README.txt"
stat "$mountpoint/README.txt"
df -hT "$mountpoint"
# Capture the loop device before cleanup.
findmnt -no SOURCE "$mountpoint" > loop-source.txt
sudo umount "$mountpoint"
# Verify that no mount remains.
if findmnt --target "$mountpoint" >/dev/null 2>&1; then
echo 'ERROR: mount still active' >&2
exit 1
fi
file "$image"
ls -lh "$image"
Validate a proposed fstab entry without modifying /etc/fstab
uuid=$(blkid -s UUID -o value "$image")
printf 'UUID=%s %s ext4 loop,nodev,nosuid,nofail 0 2\n' \
"$uuid" "$mountpoint" > proposed-fstab
findmnt --verify --verbose --tab-file proposed-fstab
cat proposed-fstab
Verification checklist
7. Common filesystem and mount mistakes
“Formatting is just preparing an empty disk.”
Formatting writes metadata and can overwrite prior signatures or recoverable structures. Prove the device is intentionally disposable.
“If mount succeeds, the fstab entry is safe.”
Boot ordering, missing devices, network timing, and check options can still create boot failures. Validate and test explicitly.
“Unmount failed, so force it.”
First identify open files, current directories, nested mounts, and active processes with findmnt, fuser, or lsof.
“noexec prevents all execution.”
It prevents direct execution from that mount; interpreters may still read scripts. Treat mount options as defense in depth.
8. Knowledge check
Question 1. What does mounting do?
Question 2. Why are UUIDs usually preferred in fstab?
Question 3. What should you do before rebooting after an fstab change?
9. Summary
Filesystems transform block storage into organized files and metadata. Formatting creates that structure; mounting attaches it to the directory tree; fstab declares persistent policy. Safe storage work separates identity, creation, attachment, validation, and cleanup, with every destructive action confined to verified disposable targets.
10. Further reading
mount(8),umount(8),findmnt(8),fstab(5), andmkfs(8).- ext4, XFS, and Btrfs administration documentation for the deployed distribution.
- systemd mount-unit and automount-unit documentation.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0
Send only Ethereum/ERC-20 compatible assets to this address.