Configure Persistent Mounts

LinuxBeginner
Practice Now

Introduction

Manual mounts disappear after reboot unless the system has a persistent mount configuration. On Linux, /etc/fstab describes filesystems that should be mounted by the system or by mount -a. A correct entry needs a source, a mount point, a filesystem type, mount options, and dump/fsck fields.

In this lab, you will configure one safe lab-owned persistent mount. The setup prepares an ext4 filesystem inside /home/labex/project/persistent-disk.img. You will add a single /etc/fstab line that mounts that image at /home/labex/project/persistent-mount using the loop option, then verify it with mount -a. You will not modify any existing system mount entries.

Inspect the Prepared Filesystem

In this step, you will inspect the prepared filesystem image and mount point before changing /etc/fstab. Persistent mounts are safer when you first confirm the source and target paths.

Move into the project directory.

cd /home/labex/project

Check the image file and mount directory.

ls -lh persistent-disk.img
ls -ld persistent-mount

Read the current /etc/fstab. At this point, you are only inspecting the file so you know what system mount entries already exist before adding the lab-owned line.

cat /etc/fstab

Add a Lab Entry to fstab

In this step, you will add one persistent mount entry. An /etc/fstab line has six fields: source, mount point, filesystem type, options, dump flag, and filesystem check order.

Back up /etc/fstab before editing it. The backup gives you a known file to compare or restore in a real administration session.

sudo cp /etc/fstab /etc/fstab.lab40.bak

Append the lab-owned entry. The source is the image file, the target is persistent-mount, the type is ext4, and the options include loop so the file is mounted through a loop device. The nofail option prevents this lab entry from being treated like a critical boot filesystem.

printf '/home/labex/project/persistent-disk.img /home/labex/project/persistent-mount ext4 loop,nofail,rw 0 0\n' | sudo tee -a /etc/fstab >/dev/null

Show the entry you added.

grep -F '/home/labex/project/persistent-mount' /etc/fstab

Mount from fstab

In this step, you will use /etc/fstab instead of manually naming the source device in the mount command. mount -a asks Linux to mount entries from /etc/fstab that are not already mounted.

Run mount -a. A successful command often prints nothing, which is normal.

sudo mount -a

Inspect the mounted path.

findmnt -T persistent-mount

Check the filesystem capacity.

df -h persistent-mount

Verify Writes on the Persistent Mount

In this step, you will prove that the mounted filesystem is usable. Mounting is not complete until the target path behaves like the filesystem you intended to attach.

Give the labex user ownership of the mounted filesystem root.

sudo chown labex:labex persistent-mount

Create a test file on the mounted filesystem.

printf 'persistent mount ok\n' > persistent-mount/persistent.txt

Read it back.

cat persistent-mount/persistent.txt

Confirm one more time that the test file is on the mounted path.

findmnt -T persistent-mount/persistent.txt

Summary

You configured a persistent mount without changing any existing system mount. You inspected a prepared ext4 image and mount point, backed up /etc/fstab, appended one lab-owned entry using the loop and nofail options, mounted it with mount -a, checked the mounted filesystem with findmnt and df, and wrote a test file. This prepares you for the next troubleshooting lab, where incorrect mount configuration becomes the problem to diagnose.