Mounting and fstab
Chapter 14: Mounting and fstab
Section titled “Chapter 14: Mounting and fstab”Overview
Section titled “Overview”This chapter covers mounting file systems, configuring automatic mounting with /etc/fstab, and systemd mount units for modern Linux systems.
Why This Matters in DevOps/SRE
Section titled “Why This Matters in DevOps/SRE”Proper mounting configuration ensures systems boot correctly, data persists, and storage is available. Misconfigured fstab is a common cause of boot failures and downtime.
┌─────────────────────────────────────────────────────────────────────────────┐│ MOUNTING IN DEVOPS │├─────────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────────────────┐ ││ │ COMMON INCIDENT SCENARIOS │ ││ │ │ ││ │ • Boot failure - Wrong fstab entry │ ││ │ • Mount timeout - Network storage unreachable │ ││ │ • Read-only filesystem - Options misconfigured │ ││ │ • Mount order - Dependencies not set │ ││ │ │ ││ └─────────────────────────────────────────────────────────────────────┘ ││ ││ ┌─────────────────────────────────────────────────────────────────────┐ ││ │ PRODUCTION MOUNT OPTIONS │ ││ │ │ ││ │ Data Mounts: │ ││ │ • noatime,nodiratime - Better performance │ ││ │ • barrier=1 - Data integrity │ ││ │ • defaults - Standard options │ ││ │ │ ││ │ Network Mounts: │ ││ │ • _netdev - Wait for network │ ││ │ • x-systemd.automount - On-demand mounting │ ││ │ • soft,intr - Graceful failure │ ││ │ │ ││ └─────────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────────┘14.1 Mount Basics
Section titled “14.1 Mount Basics”mount Command
Section titled “mount Command”# Mount basicsudo mount /dev/sdb1 /mnt/data
# Mount with optionssudo mount -o rw,noexec /dev/sdb1 /mnt/data
# Mount read-onlysudo mount -o ro /dev/sdb1 /mnt/data
# Remountsudo mount -o remount,rw /
# Unmountsudo umount /mnt/datasudo umount /dev/sdb1
# Lazy unmount (force)sudo umount -l /mnt/data
# Check mountsmountfindmntCommon Mount Options
Section titled “Common Mount Options”| Option | Description |
|---|---|
| rw | Read-write |
| ro | Read-only |
| suid | Allow setuid |
| nosuid | Disallow setuid |
| exec | Allow executables |
| noexec | Disallow executables |
| auto | Mount automatically |
| noauto | No auto mount |
| user | Allow user mount |
| nouser | Only root can mount |
| defaults | rw,suid,dev,exec,auto,nouser,async |
| nofail | Don’t fail if device missing |
14.2 /etc/fstab
Section titled “14.2 /etc/fstab”fstab Format
Section titled “fstab Format”<device> <mount point> <type> <options> <dump> <fsck>Example fstab
Section titled “Example fstab”# Device Mount Point Type Options Dump PassUUID=abc123 / ext4 defaults 1 1UUID=def456 /boot ext4 defaults 0 2UUID=ghi789 /home ext4 defaults 0 2UUID=jkl012 none swap sw 0 0/dev/sdb1 /mnt/data ext4 defaults 0 2Fields Explained
Section titled “Fields Explained”| Field | Description |
|---|---|
| Device | Device path, UUID, or LABEL |
| Mount Point | Target directory |
| Type | Filesystem type (ext4, xfs, nfs, etc.) |
| Options | Mount options |
| Dump | Backup (0/1) |
| fsck | Order (0=skip, 1=root, 2=other) |
14.3 UUID and Labels
Section titled “14.3 UUID and Labels”Using UUID
Section titled “Using UUID”# Find UUIDsudo blkidls -l /dev/disk/by-uuid/
# Use in fstabUUID=abc123-def456-ghi789 / ext4 defaults 0 1Using Labels
Section titled “Using Labels”# Label filesystemsudo e2label /dev/sdb1 mydatasudo xfs_admin -L mydata /dev/sdb1
# Use in fstabLABEL=mydata /mnt/data ext4 defaults 0 214.4 Systemd Mount Units
Section titled “14.4 Systemd Mount Units”Mount Units
Section titled “Mount Units”[Unit]Description=Data MountAfter=network.target
[Mount]What=/dev/sdb1Where=/mnt/dataType=ext4Options=defaults
[Install]WantedBy=multi-user.targetEnable Mount
Section titled “Enable Mount”sudo systemctl daemon-reloadsudo systemctl enable mnt-data.mountsudo systemctl start mnt-data.mount
# Check statussystemctl status mnt-data.mountAutomount Units
Section titled “Automount Units”[Unit]Description=Data Automount
[Automount]Where=/mnt/data
[Install]WantedBy=multi-user.target14.5 Common Mount Examples
Section titled “14.5 Common Mount Examples”# Mount NFSsudo mount -t nfs server:/share /mnt/nfs
# With optionssudo mount -t nfs -o rw,hard,intr server:/share /mnt/nfs
# fstab entryserver:/share /mnt/nfs nfs defaults 0 0CIFS/SMB
Section titled “CIFS/SMB”# Mount SMBsudo mount -t cifs //server/share /mnt/share -o user=username
# With passwordsudo mount -t cifs //server/share /mnt/share -o user=username,password=pass
# fstab entry//server/share /mnt/share cifs credentials=/etc/samba/credentials 0 0ISO Image
Section titled “ISO Image”# Mount ISOsudo mount -o loop,ro image.iso /mnt/iso
# fstab entry/path/to/image.iso /mnt/iso iso9660 ro,loop 0 0tmpfs (RAM Disk)
Section titled “tmpfs (RAM Disk)”# Mount tmpfssudo mount -t tmpfs -o size=2G tmpfs /mnt/ramdisk
# fstab entrytmpfs /mnt/ramdisk tmpfs size=2G 0 014.6 Interview Questions
Section titled “14.6 Interview Questions”Q: What is the difference between mount and fstab?A: mount: command to mount immediately; fstab: automatic mount at boot
Q: What does the 'nofail' option do?A: Don't fail if device doesn't exist (useful for optional mounts)
Q: What is the fsck field in fstab?A: Order of filesystem check at boot (0=skip, 1=root, 2=other)
Q: How do you find UUID of a device?A: sudo blkid or ls -l /dev/disk/by-uuid/
Q: What is systemd automount?A: Mount on first access (on-demand)Common Mistakes & Anti-Patterns
Section titled “Common Mistakes & Anti-Patterns”1. Using Device Names Instead of UUIDs
Section titled “1. Using Device Names Instead of UUIDs”WRONG:
/dev/sdb1 /data ext4 defaults 0 2# Device names can change!CORRECT:
UUID=abc123-def456-ghi789 /data ext4 defaults 0 2# OR/dev/disk/by-uuid/abc123-def456-ghi789 /data ext4 defaults 0 2Why: Device names (/dev/sdX) can change between boots, especially in cloud environments.
2. Noatime Missing for Performance
Section titled “2. Noatime Missing for Performance”WRONG:
# Default options - includes atime updates/dev/sdb1 /data ext4 defaults 0 2# Every read updates access time - unnecessary I/OCORRECT:
# With performance options/dev/sdb1 /data ext4 defaults,noatime,nodiratime 0 2Why: noatime eliminates unnecessary writes on every file read.
3. Network Mount Without _netdev
Section titled “3. Network Mount Without _netdev”WRONG:
# NFS mount without network waitserver:/share /mnt/nfs nfs defaults 0 0# Boot hangs if network not ready!CORRECT:
# Wait for network before mountingserver:/share /mnt/nfs nfs defaults,_netdev,x-systemd.requires=network-online.target 0 0Why: _netdev ensures the system waits for network before attempting mount.
4. Wrong fsck Order
Section titled “4. Wrong fsck Order”WRONG:
# Root set to 2 (should be 1)UUID=... / ext4 defaults 0 2# Should be: 0 1
# Non-root set to 1 (slows boot)UUID=... /data ext4 defaults 0 1# Should be: 0 2CORRECT:
# Root: 0 1UUID=... / ext4 defaults 0 1
# Other: 0 2UUID=... /data ext4 defaults 0 2
# Skip: 0 0tmpfs /tmp tmpfs defaults 0 0Why: fsck order determines boot time and what’s checked.
5. No Dump/Pass Settings
Section titled “5. No Dump/Pass Settings”WRONG:
# Missing last two fields/dev/sdb1 /data ext4 defaultsCORRECT:
# dump: 0=don't backup, 1=backup# pass: 0=skip fsck, 1=root, 2=check after root/dev/sdb1 /data ext4 defaults 0 2Why: Proper pass order ensures correct filesystem checking sequence.
Summary
Section titled “Summary”- mount: Command to mount filesystems
- fstab: Automatic mount configuration
- UUID: Preferred way to identify devices
- systemd: Modern mount units
Next Chapter
Section titled “Next Chapter”Chapter 15: Disk Quotas and Limits
Last Updated: February 2026