Introduction
Operating filesystems safely requires a clear distinction between devices, filesystems, mount points, and persistent configuration. A small error in /etc/fstab can delay or stop boot, so every change should be testable before rebooting.
What you should be able to do after this lesson:
- Inspect current mounts and filesystem identifiers.
- Write and test
/etc/fstabentries. - Mount filesystems with appropriate options.
- Create and manage swap partitions and files.
- Understand native systemd mount units.
Big Idea: Device, Filesystem, and Mount Are Different Layers
A block device can exist without a filesystem, and a filesystem can exist without being mounted. A mount connects a filesystem root to a directory in the current namespace. Persistent configuration describes what should happen later; it is not proof of current kernel state.
Use this mapping when reading a problem:
device or file -> filesystem identity -> mount options -> mount point -> application path
Inspect Current State
findmnt
findmnt /var
lsblk -f
blkid
cat /proc/mounts
/proc/mounts reports kernel state. /etc/mtab is commonly a link to /proc/self/mounts. findmnt presents the same relationships more clearly.
/etc/fstab
Each entry contains six fields:
source mountpoint type options dump pass
Example:
UUID=1111-2222 /srv/data ext4 defaults,noatime 0 2
Using UUID or a filesystem label is generally more stable than /dev/sdb1, because device names can change.
Common options:
defaultsfor the usual option setroorrwnoexec,nosuid, andnodevas hardening controlsnoatimeto reduce access-time writesnofailfor an optional filesystem_netdevfor a network-dependent mount
Test all entries without rebooting:
sudo mount -a
findmnt --verify
Mount and Unmount
mount /dev/sdb1 /srv/data
mount -o remount,ro /srv/data
umount /srv/data
When unmounting reports that a target is busy, identify users instead of forcing it immediately:
fuser -vm /srv/data
lsof +D /srv/data
sync requests that buffered writes be sent to storage, but it does not replace a clean unmount.
Swap
Create a swap file safely:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon --show
Persistent entry:
/swapfile none swap sw 0 0
Disable swap with swapoff. Be sure enough RAM is available before doing so.
systemd Mount Units
systemd converts many fstab entries into units automatically. Native mount unit names derive from paths: /srv/data becomes srv-data.mount.
[Unit]
Description=Application data
[Mount]
What=/dev/disk/by-uuid/1111-2222
Where=/srv/data
Type=ext4
Options=defaults,noatime
[Install]
WantedBy=multi-user.target
Automount units can mount on first access and reduce boot dependencies.
Guided Practice: Test an fstab Entry Safely
Use a disposable image rather than a real disk:
truncate -s 128M /tmp/lpic-filesystem.img
sudo mkfs.ext4 -L LPIC_LAB /tmp/lpic-filesystem.img
sudo mkdir -p /mnt/lpic-lab
sudo mount -o loop /tmp/lpic-filesystem.img /mnt/lpic-lab
findmnt /mnt/lpic-lab
lsblk -f
Locate the loop device reported by findmnt, then inspect its filesystem UUID with blkid. Write a temporary candidate entry on paper or in a separate test file:
UUID=<observed-uuid> /mnt/lpic-lab ext4 defaults,nosuid,nodev 0 2
Do not append it to /etc/fstab until you can explain all six fields. Clean up:
sudo umount /mnt/lpic-lab
If you test a real fstab change, use findmnt --verify and mount -a before rebooting.
Troubleshooting Scenario
A server enters emergency mode because an optional archive disk is absent. Its fstab entry uses /dev/sdb1 with defaults.
Replace the unstable device name with a verified UUID and decide whether nofail plus an appropriate device timeout matches the service requirement. If applications require the archive, hiding the failure with nofail may be wrong; instead express the dependency and repair the storage path.
Exam Focus
- Know all six
/etc/fstabfields and the meaning of the finalfs_passnovalue. - Distinguish
/etc/mtab,/proc/mounts, and persistent configuration. - Use
blkid, UUIDs,mount,umount,sync,swapon, andswapoff. - Derive systemd mount unit names from paths.
Recap
- Kernel mount state and persistent configuration are separate.
- Prefer stable identifiers and test
fstabbefore rebooting. - Diagnose busy mounts before using force or lazy unmount options.
- systemd can generate mount units from
fstabor use native units.
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
