Rocky Linux 10 Tutorial / Mount XFS by UUID with fstab and recover errors
To connect an additional disk every time you boot Rocky Linux 10, register the actual UUID of the filesystem in /etc/fstab, check the candidate file before saving, and after reboot, verify up to the mount source. For optional data disks, you can consider nofail and device wait limits, but the fact that boot continues does not guarantee the disk is usable. This lesson covers automatic mounting of XFS disks, failures due to incorrect UUIDs, and VM console recovery and restoration.
Prepare the formatted lab disk and an empty mount point
Reuse the 4 GiB disk from the new-disk identification, GPT and XFS lesson. Since it already has a file system and test files, mkfs.xfs will not be run again. The source lab environment was Rocky Linux 10.2, systemd 257, util-linux 2.40.2, XFS, and we will only handle the additional disk separated from the existing root, boot, and swap disks in a dedicated VirtualBox VM.
UUID stands for Universally Unique Identifier and here refers to the value used to identify a file system. Instead of /dev/sdb1, which can change depending on the device connection order, use the UUID of that file system. However, since cloned disks may have duplicate UUIDs, do not rely solely on the copied value; also check the device serial number and actual connection.
lsblk -o NAME,PATH,SIZE,SERIAL,FSTYPE,LABEL,UUID,MOUNTPOINTS
sudo blkid /dev/disk/by-id/ata-VBOX_HARDDISK_VB36d9d5af-5d5369e3-part1
findmnt /
findmnt --source UUID=278b7913-3bf0-433e-a8f1-6de4d3027b76
This partition is TYPE=xfs, LABEL=lfdata21, UUID 278b7913-3bf0-433e-a8f1-6de4d3027b76. The UUID in the example is the actual measured value, and in other environments, replace it with your own disk's value. If any existing mounts appear during the last check, finish using them and properly unmount that location before proceeding.
Use /mnt/lf-data22 for this lesson. If it already exists, first examine the data and existing settings inside it, and do not arbitrarily clear or overwrite it to mount. If the commands below fail due to the existing path, stop.
sudo mkdir -m 755 /mnt/lf-data22
findmnt --mountpoint /mnt/lf-data22
Since the new directory is not yet mounted, the second command returns a non-zero exit status without any output. findmnt --target /mnt/lf-data22 searches up to the parent file system that contains that path, so when checking whether it is separately mounted, it should be distinguished from --mountpoint. The findmnt manual explains these options and verification functions.
The six fields of fstab and option selection
fstab is a configuration file that records the file system to be mounted along with its location and options. We will use the following single line and keep the existing root, boot, and swap entries as they are. Each field is separated by a space or tab.
UUID=278b7913-3bf0-433e-a8f1-6de4d3027b76 /mnt/lf-data22 xfs defaults,nofail,x-systemd.device-timeout=5s 0 0
| Field | Example value | What to consider |
|---|---|---|
| Mount source | UUID=... |
Verify that it is an actual file system UUID. Do not confuse it with a GPT PARTUUID. |
| Mount point | /mnt/lf-data22 |
Use a new path that does not contain existing data. |
| File System | xfs |
Must match the actual format shown in blkid. |
| Options | defaults,nofail,x-systemd.device-timeout=5s |
Specifies the boot dependencies of the selected disk and device wait times. |
| Dump Target | 0 |
Not designated as a target for traditional dump tools. Not a value that makes other backups unnecessary. |
| fsck Order | 0 |
Does not specify the normal fsck check order at boot in this XFS example. |
The fstab manual defines the fields and explains UUID-based sources. If there are spaces in the path, simply adding quotes is not enough, and you must follow fstab's escape rules. No spaces were used in the practice paths.
The fsck.xfs of XFS generally terminates with a success status, and XFS performs the necessary log recovery at mount time. Therefore, do not mechanically copy 0 0 to another file system, or interpret a successful fsck as passing the entire integrity check of XFS. Damage inspection and repair require separate judgment. The operation is explained in the fsck.xfs manual of the XFS project .
nofail is an option that does not require the success of this mount as a prerequisite for the local file system boot target. It fits the practice purpose of allowing access to the server and fixing it even without additional disks. Conversely, disks containing database materials or essential service data should be designed to include service start conditions, and this is not an option to be added comprehensively to root/boot entries.
x-systemd.device-timeout=5s limits the time to wait for the device in the fstab entry to appear. This is different from x-systemd.mount-timeout=, which is a limit for the file system mount operation itself. Also, this example is automatic connection at boot, and it does not use x-systemd.automount, which connects when accessed. The exact scope of the option is described in the systemd.mount manual .
After making backups and candidate files, verify
Rather than editing the original directly, separate the backup and candidates. The following backup directory is dedicated to this practice session. If it already exists, it may contain materials from past sessions or recovery data, so do not overwrite existing files and check the contents to determine where to resume.
sudo bash <<'BASH'
set -eu
backup=/root/lf-course22-before
test ! -e "$backup"
mkdir -m 700 "$backup"
cp -a /etc/fstab "$backup/fstab"
cp -a /etc/fstab "$backup/good.fstab"
BASH
sudoedit /root/lf-course22-before/good.fstab
Add one line from the previous example to the end of the candidate file. Do not delete existing entries or register the same mount point twice. sudoedit uses the configured editor, so you need to know how to save and exit the editor. Once changes are complete, run the verification below.
sudo findmnt --verify --verbose --tab-file /root/lf-course22-before/good.fstab
sudo diff -u /root/lf-course22-before/fstab /root/lf-course22-before/good.fstab
Check that only the success status of the verification and the items you intended to add have changed. diff returns exit code 1 if there are differences, so do not confuse this value itself with a failed configuration check. The current valid candidate passed without errors or warnings, while the candidate with a UUID that does not exist was detected with unreachable ... source error and exit code 1.
Successful verification checks syntax and current device access, but does not guarantee future booting or writing service data. If there are errors, do not apply them to the original; modify the candidate. In the application step below, also compare to ensure that the current fstab has not changed since the backup.
sudo cmp /etc/fstab /root/lf-course22-before/fstab &&
sudo cp -a /root/lf-course22-before/good.fstab /etc/fstab
sudo systemctl daemon-reload
sudo findmnt --verify --verbose
If cmp shows a difference, it means there has been another change, so do not copy it. Verify by reflecting only one necessary item in the latest fstab. Since systemd converts fstab into mount units, after a change, daemon-reload will reread the configuration. Simply rereading does not complete the actual mount.
Mount using the fstab entry and check after reboot.
Unlike manual mounting where two arguments for device and path were specified, this time only the path is specified so that information is read from fstab. This is a method to verify a single new entry before mount -a, which can affect the entire entry.
sudo mount /mnt/lf-data22
findmnt --mountpoint /mnt/lf-data22 -o TARGET,SOURCE,FSTYPE,OPTIONS
cat /mnt/lf-data22/work/probe.txt
sha256sum /mnt/lf-data22/work/probe.txt
UNIT=$(systemd-escape --path --suffix=mount /mnt/lf-data22)
systemctl show "$UNIT" -p ActiveState -p FragmentPath -p Before -p After
The actual source was confirmed as /dev/sdb1, the format as xfs, and read the disk21-ok file from lecture 21. The unit path generated by systemd was under /run/systemd/generator/. Since hyphens in mount paths are escaped in unit names, systemd-escape is used instead of estimating the name by hand.
Only reboot if both the normal mount and console access are confirmed. Finish any other tasks that are running first. Check separately whether the boot ID changes before and after reboot, and whether the disk is attached on the new boot.
cat /proc/sys/kernel/random/boot_id
sudo systemctl reboot
After reconnecting, check the following.
cat /proc/sys/kernel/random/boot_id
findmnt --mountpoint /mnt/lf-data22 -o TARGET,SOURCE,FSTYPE,UUID
cat /mnt/lf-data22/work/probe.txt
sha256sum /mnt/lf-data22/work/probe.txt
systemctl show local-fs.target -p ActiveState -p Wants -p Requires
In the source lab reboot, the boot ID changed and the XFS disk was automatically mounted. The SHA-256 of the files was d6d494b0eaf4b2f36b92e4b855581ec6158195e180a4592bcd3b59482daed896 both before and after the reboot. local-fs.target was active, and the additional mount appeared on Wants, while the existing root and boot mounts appeared on Requires. This was confirmed by successful server login and normal connection of the data disk.
Failure with incorrect UUID and console recovery practice
This section is optionally performed only on a dedicated VM where the recovery console can be used. You make only one line of a normally functioning additional disk item incorrect and recover it before reboot. This is not a procedure that corrupts root or boot items or causes actual boot failure.
Copy the normal candidate to a separate error candidate and change only the UUID of the additional item to 22222222-2222-4222-8222-222222222222. Also, check that the UUID is not used on an actual device. Wait 5 seconds with nofail, and keep the rest of the existing items.
sudo cp -a /root/lf-course22-before/good.fstab /root/lf-course22-before/bad.fstab
sudoedit /root/lf-course22-before/bad.fstab
sudo findmnt --verify --verbose --tab-file /root/lf-course22-before/bad.fstab
Here, the intended error should be detected. Under normal operation settings, you would stop and fix at this step. The next command is used only in the VM practice that seeks to observe that failure at the actual mount start. Make sure there are no other differences in the error candidate and close all programs using the additional disk.
cd /
sudo umount /mnt/lf-data22
sudo cmp /etc/fstab /root/lf-course22-before/good.fstab &&
sudo cp -a /root/lf-course22-before/bad.fstab /etc/fstab
sudo systemctl daemon-reload
UNIT=$(systemd-escape --path --suffix=mount /mnt/lf-data22)
sudo systemctl start "$UNIT"
findmnt --mountpoint /mnt/lf-data22
systemctl show "$UNIT" -p ActiveState -p SubState -p Result -p What -p Where
sudo journalctl -b -u "$UNIT" --no-pager -n 20
The actual result was that the start command failed with exit code 1 after 5 seconds, and the mount was absent. The journal recorded Dependency failed and the start job result 'dependency'. At this time, the unit was inactive/dead, but Result=success was also displayed. Since the mount operation itself may not start due to device dependencies, you should consider not only this one property but also the exit status of the start command, the journal, and the actual mount together.
Now, open the console of the corresponding VM in VirtualBox and log in with the practice administrator account. After checking whether the current file matches the error candidate as follows, restore it to the normal candidate, and then verify and mount it again. If the pre-recovery state is different from expected, do not overwrite all files but compare with the latest content.
sudo cmp /etc/fstab /root/lf-course22-before/bad.fstab &&
sudo cp -a /root/lf-course22-before/good.fstab /etc/fstab
sudo systemctl daemon-reload
sudo findmnt --verify
sudo mount /mnt/lf-data22
findmnt --mountpoint /mnt/lf-data22
cat /mnt/lf-data22/work/probe.txt
In the source verification, a recovery script performing both comparison with the current state and restoration of the normal candidate was executed on the actual VM console. Afterwards, using SSH, the matching of the fstab normal candidate, as well as reading from the mount source and test files, was independently confirmed. These results represent the configuration recovery in a normally booted VM console. It is not extended to verification in an emergency environment where root authentication is locked or recovery via installation ISO.
Start conditions for operations writing to a nofail disk
nofail Even if the server boots, if there is no disk, the mount point may remain as a regular directory on the root file system. If a program continues to write there, it will fill up the root space instead of an additional disk. In the source lab as well, after unmounting, findmnt --target showed the root XFS, and mount point verification failed.
After checking separately whether it is mounted and the actual UUID as shown below, start the write operation. You can save it as ~/lf-data22-check.sh and run it as bash ~/lf-data22-check.sh. This example is intended to immediately check the status and is not a locking mechanism that handles all situations where the device disappears afterward.
#!/usr/bin/env bash
set -euo pipefail
MOUNT=/mnt/lf-data22
EXPECTED_UUID=278b7913-3bf0-433e-a8f1-6de4d3027b76
if ! mountpoint -q "$MOUNT"; then
echo 'Data disk is not mounted; refusing to write' >&2
exit 1
fi
ACTUAL_UUID=$(findmnt -nro UUID --mountpoint "$MOUNT")
if test "$ACTUAL_UUID" != "$EXPECTED_UUID"; then
echo 'Unexpected filesystem; refusing to write' >&2
exit 1
fi
cat "$MOUNT/work/probe.txt"
If a systemd service requires this disk, you can review dependencies like RequiresMountsFor=/mnt/lf-data22 in that service's [Unit]. This configuration creates requirements and ordering relationships for the mounts needed in the path. You need to design it together with service-specific application/failure behavior and write program verification. For detailed meaning, see Systemd.unit's mount dependency documentation . In this practice, the settings of existing services were not changed.
Remove practice items and preserve existing settings
If you plan to continue using normal automatic mounting, keep the entries and disks, and prepare for backup and monitoring. To return to the state before the exercise, finish using the additional disks and unmount them, then compare whether the current fstab is still a valid candidate. If there are no other changes, you can restore the original as shown below.
cd /
sudo umount /mnt/lf-data22
sudo cmp /etc/fstab /root/lf-course22-before/good.fstab &&
sudo cp -a /root/lf-course22-before/fstab /etc/fstab
sudo systemctl daemon-reload
sudo findmnt --verify
findmnt --mountpoint /mnt/lf-data22
sudo rmdir /mnt/lf-data22
lsblk -o NAME,TYPE,SIZE,FSTYPE,LABEL,MOUNTPOINTS
If there are other edits, do not overwrite with a full backup, but remove only the newly added entries and check again. If they are not unmounted or there are unexpected files under the mount point, first check rmdir for the cause of failure and do not force delete. After cleanup in the source verification, the existing fstab and system disk partitions returned to the pre-work state, and only the mount of the additional disks’ XFS and test files was unmounted. Therefore, you can distinguish between removing automatic mount settings and deleting disk data.




