Signal9Signal9 — home
online
all lessons

File Systems: Create, Mount, fstab, NFS, autofs, and Swap

Intermediate45 min10 steps
What you'll learn
  • 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
  1. 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 mkfs installs 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/fstab so it returns automatically at every boot
  2. 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 — mkfs lays 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/sdb1
    meta-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/sdb1 is gone. For ext4 instead, the command is sudo 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 blkid to list every block device the kernel knows.
    blkid reads the filesystem's superblock and prints its UUID and TYPE. Copy this UUID exactly — it's what you'll paste into /etc/fstab in the next step. The TYPE="xfs" confirms the format you just laid down.

    Check yourself

    Which command makes a brand-new ext4 filesystem on the partition /dev/sdb1?

  3. 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/fstab is 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 /data
    Create 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 0

    Field 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 dump backup 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).

  4. 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/fstab until you've tested it on the running system, where a mistake is a harmless error message instead of a failed boot. mount -a mounts 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 exist or unknown filesystem type, you have a broken line and you've caught it while the system is still up. Fix it and run mount -a again 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. findmnt reads the live mount table; its --verify mode parses fstab and reports problems without mounting anything.

    Runnable in the st08 room — that room’s setup plants the files it reads

    findmnt /data
    TARGET SOURCE    FSTYPE OPTIONS
    /data  /dev/sdb1 xfs    rw,relatime
    A row for /data proves 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. Note findmnt resolves the UUID back to /dev/sdb1 for you, which is a quick sanity check that you pointed at the right disk.
    findmnt --verify
    Success, 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 -a might skip — for example a line whose device is already mounted. Clean output here plus a silent mount -a is 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?

  5. 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 defaults in the fourth field — the options field — and _netdev for 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.

    defaults is shorthand for rw,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 2

    Example — not runnable on your lab box

    findmnt -no OPTIONS /srv/uploads
    rw,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, findmnt is the current reality. Seeing noexec,nosuid,nodev here means the hardening is live right now.

    Example — not runnable on your lab box

    sudo mount -o remount /srv/uploads
    Re-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?

  6. 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.master says "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 autofs
    Complete!
    Installs the autofs service and its automount daemon. 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.home

    This means "manage mounts under /mnt/home using the rules in /etc/auto.home." Then create that map file /etc/auto.home with the mount rule:

    * -rw 192.0.2.50:/exports/home/&

    The * is a wildcard key and & substitutes it back: accessing /mnt/home/alice triggers a mount of 192.0.2.50:/exports/home/alice. The -rw field carries the mount options.

    sudo systemctl enable --now autofs
    Created 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/alice
    Desktop  Documents  Downloads
    The very act of listing /mnt/home/alice triggers autofs to mount 192.0.2.50:/exports/home/alice on 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 manual umount.

    Check yourself

    Under autofs, what causes a configured directory like /mnt/home/alice to actually get mounted?

  7. 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-utils
    Complete!
    Provides the client-side NFS support (helpers and the mount.nfs handler). Without it, an NFS line in fstab fails with unknown filesystem type 'nfs'. Installs the NFS client tooling.

    The persistent fstab line for an NFS mount of /exports/data from server 192.0.2.50 onto /mnt/data:

    192.0.2.50:/exports/data /mnt/data nfs _netdev 0 0

    The what field is server:/export-path rather than a UUID (a remote share has no local UUID). The type is nfs. The key option is `_netdev`.

    sudo mount -a
    Same 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/data to 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?

  8. 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 run mkswap. Then swapon activates it for the running system, exactly the way mount attaches a filesystem.

    Example — not runnable on your lab box

    sudo mkswap /dev/sdb2
    Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
    no label, UUID=7f8e9d0c-1b2a-3948-5746-8392a1b0c9d8
    Formats /dev/sdb2 as swap and prints its UUID — capture it for the fstab line just as you did for a filesystem. mkswap is the swap analogue of mkfs.

    Example — not runnable on your lab box

    sudo swapon /dev/sdb2
    Activates 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 with swapon --show. Persist it with an fstab entry (type swap) or it's gone at reboot.
    swapon --show
    NAME      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/sdb2 is now an active swap area. SIZE is its capacity and USED is how much the kernel has parked there so far. Seeing your device here means swapon worked.

    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 0

    Swap has no directory, so the where field is none (the activation target is swap itself); the type field is swap. After adding it, run sudo swapon -a to test the swap lines in fstab — the swap-specific cousin of mount -a.

    Check yourself

    In the /etc/fstab line for a swap area, what is the filesystem TYPE field set to?

  9. 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. fsck is only a front-end: it looks up the filesystem's TYPE (the same field blkid prints, or the type column in fstab) and hands the job to a type-specific checker named fsck.<type>. For ext2/3/4 that is fsck.ext4, another name for e2fsck. For XFS it is fsck.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.img
    ext4
    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 blkid reads each one's TYPE from its superblock, exactly as it would for /dev/sdb1. That TYPE is the word fsck uses 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 fsck full 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.img
    e2fsck 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).
    clean plus the inode and block counts means the ext4 journal and metadata are consistent. On a damaged filesystem you would unmount it and run fsck.ext4 -f (without -n) to repair. The version banner and counts vary with the e2fsprogs release.
    fsck.xfs fs-xfs.img
    If you wish to check the consistency of an XFS filesystem or
    repair a damaged filesystem, see xfs_repair(8).
    fsck.xfs exists only so the boot-time fsck pass 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 of 0. The real checker is xfs_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 -n walks the whole filesystem in no-modify mode; its seven phases are hidden here so you can read the verdict, the exit status. 0 means no corruption was found; 1 means it found damage that a real repair (xfs_repair without -n, on the unmounted device) would fix. Remove the practice images with rm fs-ext4.img fs-xfs.img.

    Check yourself

    Running fsck /dev/sdc1 on an XFS partition prints a pointer to another tool and exits 0. Which command actually checks and repairs XFS?

  10. 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 blkid
    List 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/fstab
    Read 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 --verify
    Success, 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 -h
    Show mounted filesystems with human-readable sizes and free space — a quick view of what's currently attached and how full it is.
    cat /proc/swaps
    Filename                                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 --show prints the same thing more prettily; this sandbox runs a hypervisor shim in place of swapon that only accepts a bare path, so read the kernel's own table instead.
Recap
  • Raw device → mkfs.xfs/mkfs.ext4 to 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 (and findmnt --verify) and confirm BEFORE rebooting — a bad line drops you into emergency mode. Recover with mount -o remount,rw /, fix the line, mount -a, reboot.
  • The fstab options field is a security control: defaults permits executables, set-UID bits and device nodes. Harden user-writable data mounts with defaults,noexec,nosuid,nodev, then mount -o remount to 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 + swapon enable it now, but you MUST add the none swap swap fstab line or it's gone after reboot — the field's most common storage miss.
  • fsck dispatches on the filesystem TYPE (from blkid) to fsck.<type>: fsck.ext4 (e2fsck) checks ext4, but fsck.xfs is a stub; check XFS with xfs_repair -n and repair it unmounted with xfs_repair. Add nofail to fstab lines for disks boot can live without.
Task → command → fstab line / gotcha
TaskMake / enablefstab lineWatch for
Local filesystemmkfs.xfs /dev/sdb1UUID=... /data xfs defaults 0 0Use UUID, not /dev/sdX
Verify before rebootmount -a + findmnt --verify(tests existing lines)Skipping this → emergency mode
Harden a data mountmount -o remount /srv/uploadsLABEL=... /srv/uploads ext4 defaults,noexec,nosuid,nodev 0 2Append to the options field; don't replace it
NFS client mountdnf install nfs-utils192.0.2.50:/exp /mnt/data nfs _netdev 0 0Omitting _netdev stalls boot
On-demand mountsystemctl enable --now autofs(none — uses auto.master + map)Mounts on access, not in fstab
Check a filesystemfsck.ext4 -n (ext4) · xfs_repair -n (XFS)(last field: fsck pass, 0 for XFS)Unmount first; fsck.xfs checks nothing
Swapmkswap + swaponUUID=... none swap defaults 0 0No fstab line → gone after reboot