File Systems: Create, Mount, fstab, NFS, autofs, and Swap
- Format a block device with a filesystem and mount it persistently by UUID in /etc/fstab
- Validate a new fstab line with mount -a (and findmnt --verify) BEFORE rebooting — and recover in emergency mode if you didn't
- Configure autofs to mount a share on demand and release it when idle
- Mount an NFS export from a client, persistently, with the _netdev option
- Add swap space with mkswap and swapon and make it survive a reboot
- Check a filesystem with the right tool for its type: fsck.ext4 (e2fsck) for ext4, xfs_repair for XFS
Why filesystems and persistent mounts matter
Frame the whole topic: a raw disk is useless until you put a filesystem on it and attach it where it survives reboots.
A fresh disk or partition is just a featureless slab of blocks — the kernel can read and write bytes to it, but there are no files, no directories, no notion of "this region belongs to that file." A filesystem is the bookkeeping layer that turns those raw blocks into named files and folders.
Think of a brand-new disk as an empty warehouse: lots of square footage, but no shelving, no aisle labels, no inventory list. Running
mkfsinstalls the shelving and the labelling scheme. Mounting then connects that organized warehouse to a door in your building — a directory like/data— so you can walk in and use it.Three verbs carry this entire topic:
- make a filesystem on a device (
mkfs.xfs,mkfs.ext4) - mount it onto a directory so processes can use it
- persist that mount in
/etc/fstabso it returns automatically at every boot
- make a filesystem on a device (
Make a filesystem
Turn a raw block device into a usable XFS or ext4 filesystem and read back its UUID.
On RHEL the default filesystem is XFS; ext4 is the other one you must know. Both are journaling filesystems and either is acceptable unless the task names one. Formatting is destructive —
mkfslays down fresh metadata over whatever was there, so be certain of the device name before you run it.Example — not runnable on your lab box
sudo mkfs.xfs /dev/sdb1meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131072 blks data = bsize=4096 blocks=524288, imaxpct=25 naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 realtime =none extsz=4096 blocks=0, rtextents=0
This writes a fresh XFS filesystem onto the partition /dev/sdb1. The summary describes the geometry it just created — block size, log size, inode size. There is no "are you sure?" prompt: the moment you press Enter, any old data on/dev/sdb1is gone. For ext4 instead, the command issudo mkfs.ext4 /dev/sdb1.Every filesystem gets a UUID (Universally Unique Identifier) baked into it at creation. This is the stable name you will mount by. Read it back with
blkid:sudo blkid /dev/sdb1/dev/sdb1: UUID="a1b2c3d4-5e6f-7081-92a3-b4c5d6e7f809" TYPE="xfs"
- (device arg)
- Naming one device prints just that device's identifiers; run plain
blkidto list every block device the kernel knows.
blkidreads the filesystem's superblock and prints its UUID and TYPE. Copy this UUID exactly — it's what you'll paste into/etc/fstabin the next step. TheTYPE="xfs"confirms the format you just laid down.Check yourself
Which command makes a brand-new ext4 filesystem on the partition /dev/sdb1?
Persist the mount in /etc/fstab — by UUID
Write a durable fstab entry that mounts the filesystem at boot by its UUID rather than its device name.
/etc/fstabis the table the system reads at boot to decide what to mount where. Each line has six fields:<what> <where> <type> <options> <dump> <fsck-pass>First create the mount point and add the line. Mount by UUID, not by
/dev/sdb1.Runnable in the st08 room — that room’s setup plants the files it reads
sudo mkdir -p /dataCreate the directory the filesystem will attach to. A mount point is just an ordinary empty directory; if it doesn't exist, the mount has nowhere to land. Silent — creates the mount point (an empty directory the filesystem will cover). Now add the entry. The line you append looks like this (one line, fields separated by whitespace):
UUID=a1b2c3d4-5e6f-7081-92a3-b4c5d6e7f809 /data xfs defaults 0 0Field by field: the UUID is what to mount; /data is where; xfs is the filesystem type; defaults is a sensible option bundle (read-write, auto-mount at boot, and more); the first 0 disables the legacy
dumpbackup tool; the final 0 sets the boot-time fsck pass (0 = don't check — correct for XFS, which checks itself; data partitions on ext4 typically use 2).The safety habit: mount -a and verify BEFORE you reboot
Prove a new fstab line is correct on a running system, and know how to recover if it isn't.
Never trust a freshly edited
/etc/fstabuntil you've tested it on the running system, where a mistake is a harmless error message instead of a failed boot.mount -amounts everything in fstab that isn't already mounted — so it exercises your new line immediately.sudo mount -a- -a
- Mount all filesystems listed in /etc/fstab (except those marked noauto) — exactly what boot does.
Silence is success. No output means every fstab line, including your new one, mounted cleanly — and boot will do the same. If instead you see something like mount: /data: special device ... does not existorunknown filesystem type, you have a broken line and you've caught it while the system is still up. Fix it and runmount -aagain until it's silent. Silent on success — mounts every fstab entry not already mounted. Run it BEFORE rebooting: a typo surfaces as an error now instead of an unbootable system.Then confirm the mount actually landed where you expect.
findmntreads the live mount table; its--verifymode parses fstab and reports problems without mounting anything.Runnable in the st08 room — that room’s setup plants the files it reads
findmnt /dataTARGET SOURCE FSTYPE OPTIONS /data /dev/sdb1 xfs rw,relatime
A row for /dataproves it's mounted and shows the real source device and the active options. No row means it isn't mounted — go back and check the fstab line. Notefindmntresolves the UUID back to/dev/sdb1for you, which is a quick sanity check that you pointed at the right disk.findmnt --verifySuccess, no errors
- --verify
- Parse /etc/fstab and flag errors (bad sources, missing mount points, bogus options) WITHOUT mounting.
A static lint of your fstab. It catches mistakes that mount -amight skip — for example a line whose device is already mounted. Clean output here plus a silentmount -ais strong evidence your boot will succeed. Parses fstab and reports problems (bad options, missing targets) without mounting anything — the safe pre-reboot check.Check yourself
You just added a line to /etc/fstab. Which command should you run BEFORE rebooting to prove the line works, so a typo doesn't leave the machine stuck at boot?
Mount options: harden a data filesystem
Read and edit the options field of an fstab entry, and apply the noexec/nosuid/nodev trio to a data mount.
So far every fstab line in this lesson has used
defaultsin the fourth field — the options field — and_netdevfor network mounts. That field is where a filesystem's behaviour is actually decided, and on any mount that holds user-supplied data it is a security control, not a formality.defaultsis shorthand forrw,suid,dev,exec,auto,nouser,async. Read that list again: it says the filesystem may contain executables, honour set-UID bits, and carry device nodes. For/that is correct. For an uploads or scratch volume that anyone can write to, all three are attack surface — and turning them off costs nothing.You add them by appending to the existing options field, comma-separated with no spaces — never by replacing it, or you silently drop whatever was there:
LABEL=uploads /srv/uploads ext4 defaults,noexec,nosuid,nodev 0 2Example — not runnable on your lab box
findmnt -no OPTIONS /srv/uploadsrw,relatime,noexec,nosuid,nodev
- -n
- No header line — just the value, which is what you want when reading one field.
- -o OPTIONS
- Print only the OPTIONS column: the options actually in force on the live mount.
Reads back the options the kernel is really applying, which is not always what fstab says — fstab is the boot-time intent, findmntis the current reality. Seeingnoexec,nosuid,nodevhere means the hardening is live right now.Example — not runnable on your lab box
sudo mount -o remount /srv/uploadsRe-reads the fstab entry and applies the new options to the already-mounted filesystem, without unmounting it or disturbing processes using it. This is how you make an fstab options change take effect now instead of at the next reboot. Silent on success — re-applies the fstab options to a live mount. Check yourself
Which mount option makes the kernel ignore set-UID and set-GID bits on a filesystem, blocking a planted set-UID-root binary from escalating privileges?
Mount on demand with autofs
Configure autofs to mount a share only when something accesses it, and unmount it when idle.
A normal fstab mount is attached for the whole uptime of the machine, whether anyone uses it or not. autofs instead mounts a path the instant something touches it and unmounts it after a period of inactivity. The classic use case is NFS home directories: a server may export hundreds of users' homes, but any one machine should only mount the homes of people actually logged in.
The analogy is a motion-sensor light: the corridor stays dark (unmounted) until you walk into it, then switches on (mounts), and turns itself off again once you leave (idle unmount). You don't flip a switch; access is the switch.
autofs is driven by two files. The master map
/etc/auto.mastersays "for this directory, use that map file." The map file it points to spells out the individual mounts. Install the package, then wire up the two maps.Example — not runnable on your lab box
sudo dnf install -y autofsComplete!
Installs the autofs service and its automountdaemon. On the exam, installing the package is a step people forget — the config below does nothing without the daemon running. Installs the on-demand automounter.Add one line to the master map
/etc/auto.master:/mnt/home /etc/auto.homeThis means "manage mounts under
/mnt/homeusing the rules in/etc/auto.home." Then create that map file/etc/auto.homewith the mount rule:* -rw 192.0.2.50:/exports/home/&The
*is a wildcard key and&substitutes it back: accessing/mnt/home/alicetriggers a mount of192.0.2.50:/exports/home/alice. The-rwfield carries the mount options.sudo systemctl enable --now autofsCreated symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.
- enable
- Set autofs to start at every boot — so on-demand mounting survives a reboot.
- --now
- Also start it immediately, so the maps take effect without waiting for a reboot.
Starts the automount daemon now and marks it to start at boot. Nothing is mounted yet — that's the point. The mount only happens when a process first steps into /mnt/home/<user>. enable --now — running now and at every boot, the systemctl idiom.Example — not runnable on your lab box
ls /mnt/home/aliceDesktop Documents Downloads
The very act of listing /mnt/home/alicetriggers autofs to mount192.0.2.50:/exports/home/aliceon the fly, and you immediately see its contents. Leave it untouched for a few minutes and autofs quietly unmounts it again — no fstab entry, no manualumount.Check yourself
Under autofs, what causes a configured directory like /mnt/home/alice to actually get mounted?
Mount an NFS export from the client
Mount a remote NFS share persistently with the _netdev option so boot waits for the network.
NFS lets a client mount a directory that physically lives on another server, so the share looks like a local folder. From the client side you only need the nfs-utils package and the right fstab line; the server's exports are someone else's job. The wrinkle is timing: a network share can't mount until the network is up, and at early boot it usually isn't.
Example — not runnable on your lab box
sudo dnf install -y nfs-utilsComplete!
Provides the client-side NFS support (helpers and the mount.nfshandler). Without it, an NFS line in fstab fails withunknown filesystem type 'nfs'. Installs the NFS client tooling.The persistent fstab line for an NFS mount of
/exports/datafrom server192.0.2.50onto/mnt/data:192.0.2.50:/exports/data /mnt/data nfs _netdev 0 0The what field is
server:/export-pathrather than a UUID (a remote share has no local UUID). The type isnfs. The key option is `_netdev`.sudo mount -aSame safety habit as for a local filesystem: test the new NFS line on the running system. Silent output means it mounted; an error here is far cheaper to fix than one discovered at the next boot. Follow with findmnt /mnt/datato confirm the source server and options. Silent on success — mounts every fstab entry not already mounted. Run it BEFORE rebooting: a typo surfaces as an error now instead of an unbootable system.Check yourself
Which fstab option ensures the system waits for the network before trying to mount an NFS share, so the mount doesn't fail and break the boot?
Add swap and make it persistent
Format swap space, enable it now, and add the fstab line so it returns after a reboot.
Swap is disk space the kernel uses as overflow when RAM fills — inactive memory pages get parked on disk to free real memory for active work. It's not a faster substitute for RAM; it's a pressure-relief valve that keeps the system from killing processes when memory runs short.
Swap has its own format, so you don't run
mkfs— you runmkswap. Thenswaponactivates it for the running system, exactly the waymountattaches a filesystem.Example — not runnable on your lab box
sudo mkswap /dev/sdb2Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=7f8e9d0c-1b2a-3948-5746-8392a1b0c9d8
Formats /dev/sdb2as swap and prints its UUID — capture it for the fstab line just as you did for a filesystem.mkswapis the swap analogue ofmkfs.Example — not runnable on your lab box
sudo swapon /dev/sdb2Activates the swap area immediately for the running system. Silent on success. This is runtime-only, though — exactly like a manual mount, it does not survive a reboot on its own. Silent on success — activates the swap area now; verify withswapon --show. Persist it with an fstab entry (type swap) or it's gone at reboot.swapon --showNAME TYPE SIZE USED PRIO /dev/sdb2 partition 2G 0B -2
- --show
- List active swap areas in a readable table — name, type, size, current usage, priority.
Confirms /dev/sdb2is now an active swap area.SIZEis its capacity andUSEDis how much the kernel has parked there so far. Seeing your device here meansswaponworked.Now make it persistent. The fstab line for swap uses the literal mount point `swap` and the type `swap`:
UUID=7f8e9d0c-1b2a-3948-5746-8392a1b0c9d8 none swap defaults 0 0Swap has no directory, so the where field is
none(the activation target isswapitself); the type field isswap. After adding it, runsudo swapon -ato test the swap lines in fstab — the swap-specific cousin ofmount -a.Check yourself
In the /etc/fstab line for a swap area, what is the filesystem TYPE field set to?
Check a filesystem: fsck picks its checker from TYPE
Know which checker runs for ext4 and for XFS, and run a read-only check on each.
After a crash or an unclean power-off you check a filesystem for damage.
fsckis only a front-end: it looks up the filesystem's TYPE (the same fieldblkidprints, or the type column in fstab) and hands the job to a type-specific checker namedfsck.<type>. For ext2/3/4 that isfsck.ext4, another name fore2fsck. For XFS it isfsck.xfs, which, as you'll see, deliberately does almost nothing. So the first question before any check is always what type is it?You can practise without a spare disk: a filesystem can live inside an ordinary file. Make one of each type and read their types back:
truncate -s 32M fs-ext4.img && mkfs.ext4 -q -F fs-ext4.img truncate -s 300M fs-xfs.img && mkfs.xfs -q -f fs-xfs.img blkid -o value -s TYPE fs-ext4.img fs-xfs.imgext4 xfs
- truncate -s 32M
- Create (or resize) a file of that size; it takes no real disk space until written.
- -q
- (mkfs) quiet: skip the geometry summary.
- -F / -f
- (mkfs.ext4 / mkfs.xfs) overwrite an existing filesystem without asking, so the line is safe to re-run.
- -o value -s TYPE
- (blkid) print only the TYPE value, no device name or quotes.
Two image files, two filesystems, and blkidreads each one's TYPE from its superblock, exactly as it would for/dev/sdb1. That TYPE is the wordfsckuses to choose a checker.fsck -N "$PWD/fs-ext4.img" "$PWD/fs-xfs.img"fsck from util-linux 2.39.3 [/usr/sbin/fsck.ext4 (1) -- /root/fs-ext4.img] fsck.ext4 /root/fs-ext4.img [/usr/sbin/fsck.xfs (2) -- /root/fs-xfs.img] fsck.xfs /root/fs-xfs.img
- -N
- Dry run: print which checker fsck WOULD run for each target, and run nothing.
The dispatch made visible: one front-end, two different back-ends, chosen by type. Give fsckfull paths ($PWD/...): a bare name is looked up as an fstab mount point instead. The util-linux version, the checker's directory and your working directory show up in the output, so yours may differ.fsck.ext4 -n fs-ext4.imge2fsck 1.47.0 (5-Feb-2023) fs-ext4.img: clean, 11/8192 files, 1549/8192 blocks
- -n
- Open read-only and answer 'no' to every repair question: report problems, change nothing.
- -f
- Force a full check even when the filesystem is marked clean (use it after a crash).
cleanplus the inode and block counts means the ext4 journal and metadata are consistent. On a damaged filesystem you would unmount it and runfsck.ext4 -f(without-n) to repair. The version banner and counts vary with the e2fsprogs release.fsck.xfs fs-xfs.imgIf you wish to check the consistency of an XFS filesystem or repair a damaged filesystem, see xfs_repair(8).
fsck.xfsexists only so the boot-timefsckpass has something to call. It checks nothing and exits 0. XFS replays its own journal when it mounts, which is why XFS lines in fstab use a final field of0. The real checker isxfs_repair.xfs_repair -n fs-xfs.img >/dev/null 2>&1; echo "xfs_repair -n exit: $?"xfs_repair -n exit: 0
- -n
- No-modify mode: scan and report, write nothing.
xfs_repair -nwalks the whole filesystem in no-modify mode; its seven phases are hidden here so you can read the verdict, the exit status.0means no corruption was found;1means it found damage that a real repair (xfs_repairwithout-n, on the unmounted device) would fix. Remove the practice images withrm fs-ext4.img fs-xfs.img.Check yourself
Running
fsck /dev/sdc1on an XFS partition prints a pointer to another tool and exits 0. Which command actually checks and repairs XFS?Try it in your live terminal
Inspect real filesystem and swap state on the sandbox — read-only, nothing destructive.
You have a real root shell to the right. Every command below is read-only — it inspects existing state and changes nothing. This is the verification half of the workflow you'd run after configuring storage: never reboot until these look right.
sudo blkidList every block device with a filesystem, its UUID, and its type. This is where you'd copy a UUID from when building an fstab line. cat /etc/fstabRead the current mount table. Walk each line's six fields and ask: is the source a UUID, is the type right, and does any network mount carry _netdev? findmnt --verifySuccess, no errors
Statically lint /etc/fstab for errors without mounting anything — the safe pre-reboot check. Clean output is what you want before ever restarting. Parses fstab and reports problems (bad options, missing targets) without mounting anything — the safe pre-reboot check. df -hShow mounted filesystems with human-readable sizes and free space — a quick view of what's currently attached and how full it is. cat /proc/swapsFilename Type Size Used Priority
Confirm which swap areas are active right now. A header line with nothing under it means no swap is enabled — a hint to check for a missing fstab swap line. On a normal host swapon --showprints the same thing more prettily; this sandbox runs a hypervisor shim in place ofswaponthat only accepts a bare path, so read the kernel's own table instead.
- Raw device →
mkfs.xfs/mkfs.ext4to make a filesystem → mount it → persist it in/etc/fstab. RHCSA grades the post-reboot end state, so persistence is the real goal. - Mount by UUID (from
blkid), never/dev/sdX— device names shift when hardware changes; a UUID lives inside the filesystem and follows the data. - After ANY fstab edit, run
mount -a(andfindmnt --verify) and confirm BEFORE rebooting — a bad line drops you into emergency mode. Recover withmount -o remount,rw /, fix the line,mount -a, reboot. - The fstab options field is a security control:
defaultspermits executables, set-UID bits and device nodes. Harden user-writable data mounts withdefaults,noexec,nosuid,nodev, thenmount -o remountto apply it live. - autofs mounts on access and unmounts when idle (master map → map file), ideal for NFS home directories; network fstab mounts need
_netdev. - Swap:
mkswap+swaponenable it now, but you MUST add thenone swap swapfstab line or it's gone after reboot — the field's most common storage miss. fsckdispatches on the filesystem TYPE (fromblkid) tofsck.<type>:fsck.ext4(e2fsck) checks ext4, butfsck.xfsis a stub; check XFS withxfs_repair -nand repair it unmounted withxfs_repair. Addnofailto fstab lines for disks boot can live without.
| Task | Make / enable | fstab line | Watch for |
|---|---|---|---|
| Local filesystem | mkfs.xfs /dev/sdb1 | UUID=... /data xfs defaults 0 0 | Use UUID, not /dev/sdX |
| Verify before reboot | mount -a + findmnt --verify | (tests existing lines) | Skipping this → emergency mode |
| Harden a data mount | mount -o remount /srv/uploads | LABEL=... /srv/uploads ext4 defaults,noexec,nosuid,nodev 0 2 | Append to the options field; don't replace it |
| NFS client mount | dnf install nfs-utils | 192.0.2.50:/exp /mnt/data nfs _netdev 0 0 | Omitting _netdev stalls boot |
| On-demand mount | systemctl enable --now autofs | (none — uses auto.master + map) | Mounts on access, not in fstab |
| Check a filesystem | fsck.ext4 -n (ext4) · xfs_repair -n (XFS) | (last field: fsck pass, 0 for XFS) | Unmount first; fsck.xfs checks nothing |
| Swap | mkswap + swapon | UUID=... none swap defaults 0 0 | No fstab line → gone after reboot |
