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.
  • Mount the filesystem at /mnt/data.
  • Verify the mount is active using common inspection commands.
  • Add a correct entry to /etc/fstab for persistence at boot.
  • Validate /etc/fstab safely without rebooting.

What You’ll Practice

  • Block device inspection using lsblk.
  • Filesystem creation using mkfs.ext4.
  • Mounting filesystems using mount.
  • Mount verification using mount and findmnt.
  • Persistent mount configuration using /etc/fstab.
  • Safe validation of mount configuration using mount -a.

Walkthrough

Step 1 : Identify the new partition.
Command
lsblk

lsblk displays block devices in a tree view so you can see disks, partitions, sizes, and current mountpoints. This is where you confirm /dev/sdb1 exists and is not already mounted or in use.

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

mkfs.ext4 writes a new ext4 filesystem to the partition. This destroys any existing data on that partition, so you do this only after confirming you are targeting 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
Superblock backups stored on blocks: 32768, 98304, 163840...
Filesystem created successfully.
Step 3 : Mount the filesystem to /mnt/data.
Command
sudo mount /dev/sdb1 /mnt/data

mount attaches the filesystem at the mountpoint so it becomes part of the directory tree. If the mountpoint does not exist, create it first with sudo mkdir -p /mnt/data.

/dev/sdb1 mounted to /mnt/data
Step 4 : Verify the mount is active.
Command
findmnt

Verification matters. findmnt gives a structured view of active mounts, which is useful when multiple devices or bind mounts are present. You can also use mount if you want raw output.

/dev/sdb1 on /mnt/data type ext4 (rw,relatime)
Step 5 : Add a persistent mount entry to /etc/fstab.
Command
# Add this line to /etc/fstab:
/dev/sdb1 /mnt/data ext4 defaults 0 2

/etc/fstab controls what mounts at boot. The fields are: device, mountpoint, filesystem type, options, dump, and fsck pass number. A wrong entry can break boot, so you keep the line minimal and correct.

fstab line added: /dev/sdb1 /mnt/data ext4 defaults 0 2
Step 6 : Validate /etc/fstab without rebooting.
Command
sudo mount -a

mount -a attempts to mount everything in /etc/fstab that is not already mounted (excluding entries marked with noauto). If there is an error, this is where you want to catch it.

All valid entries from /etc/fstab mounted successfully.

Reference

  • lsblk : Lists block devices and partitions, including mountpoints and sizes.
  • mkfs.ext4 <device> : Creates an ext4 filesystem on a block device (destructive operation).
  • mount <device> <mountpoint> : Mounts a filesystem at a directory.
  • findmnt : Displays mounted filesystems in a structured, searchable format.
  • /etc/fstab : Static filesystem table used to define persistent mounts at boot.
  • mount -a : Mounts all filesystems listed in /etc/fstab (except those marked noauto) to validate entries.