Loading...

Lab 17: Mounting Filesystems and Editing /etc/fstab

Prepare a new partition for use by formatting it, mounting it to a target directory, and confirming it is active. Persist the mount across reboots by adding a correct entry to /etc/fstab and validating it safely.

storage boot core

Scenario

A new partition has been added as /dev/sdb1. You are responsible for formatting it, mounting it to /mnt/data, and ensuring it mounts automatically at boot by correctly updating /etc/fstab. You also need to validate the entry without rebooting.

Operator context

Persistent mounts are a common failure point. A single bad /etc/fstab line can drop a system into emergency mode, so you verify device identity, mount state, and fstab correctness before calling it done.

Objective

  • Identify the new block device and confirm it is the correct partition.
  • Create an ext4 filesystem on /dev/sdb1.
  • Create the mountpoint at /mnt/data and mount the filesystem.
  • Verify the mount is active and backed by the expected device.
  • Add a correct entry to /etc/fstab (prefer UUID) for persistence at boot.
  • Validate /etc/fstab safely without rebooting.

Concepts

  • Use stable identifiers in /etc/fstab. Device names like /dev/sdb1 can change; UUIDs typically do not.
  • Filesystem creation is destructive. Verify the target device before running mkfs.
  • A mount is not “done” until you can prove it: check the mount table and confirm the source device matches expectations.
  • mount -a is your safety net. It lets you catch a bad fstab entry while you still have a working shell.

Walkthrough

Step 1: Identify the new partition and confirm it is unused.
Command
lsblk

lsblk shows disks, partitions, sizes, filesystem types, and mountpoints. Confirm /dev/sdb1 exists and has no active mountpoint before you format it.

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk
├─sda1   8:1    0  512M  0 part /boot
└─sda2   8:2    0 39.5G  0 part /
sdb      8:16   0   20G  0 disk
└─sdb1   8:17   0   20G  0 part
Step 2: Create an ext4 filesystem on /dev/sdb1.
Command
sudo mkfs.ext4 /dev/sdb1

This writes a new filesystem and destroys any existing data on the partition. Do this only after you confirm the correct device.

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: abc12345-6789-4def-aaaa-bbbbccccdddd
Filesystem created successfully.
Step 3: Create the mountpoint and mount the filesystem.
Commands
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

The mountpoint is just an empty directory that becomes the attach point for the filesystem. After mounting, the filesystem content is accessible under /mnt/data.

/dev/sdb1 mounted to /mnt/data
Step 4: Verify the mount is active and points to the expected device.
Commands
findmnt /mnt/data
df -hT /mnt/data

findmnt is structured evidence: source device, target, filesystem type, and options. df -hT confirms size, usage, and filesystem type for the mountpoint.

/mnt/data  /dev/sdb1  ext4  rw,relatime
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext4   20G   24M   19G   1% /mnt/data
Step 5: Capture the UUID and prepare the /etc/fstab entry.
Command
sudo blkid /dev/sdb1

Using UUID= in /etc/fstab avoids failures caused by device renaming (/dev/sdb becoming /dev/sdc, etc.). Copy the UUID exactly.

/dev/sdb1: UUID="abc12345-6789-4def-aaaa-bbbbccccdddd" TYPE="ext4"
# Add this line to /etc/fstab (use your real UUID):
UUID=abc12345-6789-4def-aaaa-bbbbccccdddd  /mnt/data  ext4  defaults  0  2
Step 6: Validate /etc/fstab safely without rebooting.
Commands
sudo umount /mnt/data
sudo mount -a
findmnt /mnt/data

Unmounting first forces your fstab entry to be used by mount -a. If anything is wrong, you catch it now instead of at boot.

/mnt/data  /dev/sdb1  ext4  rw,relatime

Common breakpoints

I formatted the wrong device

Stop immediately and document what happened. This is why you confirm with lsblk -f and double-check the target device before running mkfs. Treat it as a data loss incident.

mount: mount point does not exist

Create it first with sudo mkdir -p /mnt/data, then re-run the mount.

mount -a fails after editing /etc/fstab

Your fstab line is incorrect (bad UUID, wrong field order, invalid options, or missing mountpoint). Fix the line and re-run mount -a until it succeeds.

It mounts manually, but not on reboot

Confirm the final fstab line uses UUID=, the mountpoint exists at boot, and the filesystem type matches. Validate with findmnt and confirm the UUID using blkid.

Cleanup checklist

If this was a test mount, remove the /etc/fstab entry before you forget. Otherwise, leave it in place. Always confirm the system is in a stable state before moving on.

Commands
findmnt /mnt/data
sudo blkid /dev/sdb1
Success signal

findmnt shows /mnt/data backed by /dev/sdb1 (or the expected UUID), and your last mount -a run completed without errors.

Reference

  • lsblk: Lists block devices and partitions, including sizes, types, and mountpoints.
    • -f: Show filesystem type, UUID, and label for each device.
    • -p: Show full device paths (example: /dev/sdb1).
  • mkfs.ext4 <device>: Creates an ext4 filesystem on a block device (destructive).
    • -L <label>: Set a filesystem label (example: -L DATA).
  • mkdir -p <dir>: Creates a directory (and parents) for a mountpoint.
    • -p: Do not error if the directory exists; create parent dirs as needed.
  • mount <device> <mountpoint>: Mounts a filesystem at a directory.
    • -t <type>: Specify filesystem type explicitly (example: -t ext4).
  • umount <mountpoint>: Unmounts a mounted filesystem.
    • -l: Lazy unmount (detaches now, cleans up when no longer busy).
  • findmnt <path>: Query the mount that backs a specific path (example: findmnt /mnt/data).
    • -r: Raw output (useful for scripting).
  • df -hT <path>: Shows space usage and filesystem type for a path.
    • -h: Human-readable sizes.
    • -T: Include filesystem type.
  • blkid <device>: Prints UUID and filesystem type for a block device.
    • -s UUID: Print only the UUID field.
  • /etc/fstab: Static filesystem table used to define persistent mounts at boot.
    • Field order: <source> <mountpoint> <type> <options> <dump> <fsck_pass>
    • Prefer UUID=<uuid> as the source for stability.
  • mount -a: Mounts all filesystems from /etc/fstab that are not already mounted.
    • Primary safety check after editing /etc/fstab.
    • Entries with noauto are skipped.