16.6. Practical Lab: Recovering a Data Volume
The lab brings the chapter together on a data volume rather than the root
filesystem. The volume holds an application database, a configuration file
with an ACL and an extended attribute, and a report. It is backed up to a
separate disk, resized, made temporarily unavailable, given a wrong fstab
entry, and finally stripped of its files and restored. The point is not the
individual commands, which were covered above, but the order: establish a
known state, make an independent copy, change one thing, observe the failure,
repair it, and verify both the data and the metadata.
The practice volume is the datavg/appdata logical volume introduced in
Section 16.2.1. Its filesystem is mounted at /srv/appdata, and the backup
disk /dev/vde is mounted at /mnt/backup. The volume is small enough to
copy quickly. If you are following on a different machine, create an
equivalent volume with the LVM and ext4 procedures in Chapter
13 and Chapter 12, and use its
device path in place of /dev/datavg/appdata. Do not use a production volume
for the destructive steps.
16.6.1. Preparing Disposable Storage, Known Files, and an Independent Backup
Start by confirming the volume and its mount:
$ sudo lvs datavg
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
appdata datavg -wi-ao---- 1.00g
The volume is active and open; 1.00g is its current size. Mount it if it is
not already mounted, using the entry that the recovery repaired in Section
16.3.1:
$ sudo mount /srv/appdata
The command is silent on success. Confirm the actual source, not just the mount point:
$ findmnt /srv/appdata
TARGET SOURCE FSTYPE OPTIONS
/srv/appdata /dev/mapper/datavg-appdata ext4 rw,relatime
findmnt reads the kernel mount table; it shows that /srv/appdata is the
logical volume, not a directory on the root filesystem. This check matters
because a missing mount can leave an empty directory at the same path, and an
application that writes there will fill the root filesystem instead of the
data volume. Create the known files as john, the application's ordinary user:
$ mkdir -p /srv/appdata/reports /srv/appdata/config /srv/appdata/logs
The command is silent. The report is a small text file:
$ printf "quarterly report\n" > /srv/appdata/reports/quarterly.txt
The command writes the file and prints nothing. The configuration file belongs to the web server account and has a restrictive mode, an ACL for john, and an extended attribute that records the chapter:
$ sudo install -o www-data -g www-data -m 0640 /dev/null /srv/appdata/config/app.conf
$ sudo -i
# printf 'listen_addresses = localhost\n' > /srv/appdata/config/app.conf
# exit
$ sudo setfacl -m u:john:r-- /srv/appdata/config/app.conf
$ sudo setfattr -n user.handbook -v chapter16 /srv/appdata/config/app.conf
The first command creates an empty file with the desired owner, group, and
mode; the second writes its contents from a root shell while preserving those
attributes. The install form avoids a window in which the file has the wrong
owner. setfacl
adds a named-user read permission without changing the file's group or other
bits; setfattr stores the chapter marker in the user. namespace, which is
preserved by tar --xattrs and by the backup. The ACL and attribute are
metadata that a plain cp or a tar without the right options would lose.
The application database is SQLite, stored as a single file:
$ sqlite3 /srv/appdata/inventory.db "CREATE TABLE parts (id INTEGER PRIMARY KEY, name TEXT NOT NULL, quantity INTEGER NOT NULL); INSERT INTO parts VALUES (1, \"bolt\", 120), (2, \"nut\", 300), (3, \"washer\", 500);"
The command is silent on success. Read it back:
$ sqlite3 /srv/appdata/inventory.db "SELECT name, quantity FROM parts ORDER BY id;"
bolt|120
nut|300
washer|500
The | separator is SQLite's default for the command-line shell. The database
file is owned by john because john created it; the web server account can read
it through the directory and file modes, as the final access check will show.
A production database would use its own dump tool rather than a live file copy,
as Chapter 15 explains.
The independent backup goes to /dev/vde, a separate disk. The following
command removes any existing signature from that disk; confirm it is the
disposable device before running it:
$ sudo wipefs -a /dev/vde
The command is silent when the disk has no signatures to remove; it prints the signatures it erases when it finds them. Then create the filesystem and mount it:
$ sudo mkfs.ext4 -q -L textbook-backup /dev/vde
$ sudo mkdir -p /mnt/backup
$ sudo mount /dev/vde /mnt/backup
The mkfs is quiet and the mount is silent. Never run that wipefs on a disk
whose contents you need. The backup archive preserves ownership, ACLs, and
extended attributes:
$ sudo tar --acls --xattrs --numeric-owner -cpf /mnt/backup/appdata-before-repair.tar -C /srv appdata
The command is silent. -C /srv makes the archive paths relative to /srv, so
the archive contains appdata/... rather than an absolute path; extracting it
under /srv restores the original layout. The options are the same ones used
for the configuration archive in Section 16.2.4. List the first entries to
verify the structure:
$ sudo tar --acls --xattrs --numeric-owner -tvf /mnt/backup/appdata-before-repair.tar | head -8
drwxr-xr-x 1001/1001 0 2026-11-21 03:25 appdata/
drwxrwxr-x 1001/1001 0 2026-11-21 03:25 appdata/logs/
-rw-r--r-- 1001/1001 8192 2026-11-21 03:25 appdata/inventory.db
drwxrwxr-x 1001/1001 0 2026-11-21 03:25 appdata/config/
-rw-r-----+ 33/33 29 2026-11-21 03:25 appdata/config/app.conf
drwxrwxr-x 1001/1001 0 2026-11-21 03:25 appdata/reports/
-rw-rw-r-- 1001/1001 17 2026-11-21 03:25 appdata/reports/quarterly.txt
drwx------ 0/0 0 2026-11-21 03:17 appdata/lost+found/
The numeric owners are the user and group IDs, not names; 1001 is john on
this system and 33 is www-data. The + after the mode on app.conf
indicates an ACL. The lost+found directory is included because it is part of
the filesystem; restoring it over an existing lost+found is harmless when
the directory is empty, but a filesystem with recovered orphaned files would
need a more careful merge. The tar listing is selected to the first eight
entries; the archive contains the rest of the tree.
Write a checksum in the workspace and verify it. The archive is readable by john, so the redirection runs in john's shell and the checksum file stays with the incident notes:
$ sha256sum /mnt/backup/appdata-before-repair.tar > appdata-before-repair.sha256
The command writes the checksum file and prints nothing. Read it, then ask
sha256sum -c to check the named archive:
$ cat appdata-before-repair.sha256
f4d048c8eec3e91d3a75952e60f95bec9f91f6a97531d18e6006ca7f615a0c13 /mnt/backup/appdata-before-repair.tar
$ sha256sum -c appdata-before-repair.sha256
/mnt/backup/appdata-before-repair.tar: OK
The OK means the archive's current bytes match the checksum recorded moments
earlier; it does not prove that the archive contains the application's
consistent state. The SQLite file was not being written during the copy, so
the file copy is consistent for this lab. For a live database, use the dump
procedure from Chapter 15 and verify the dump by
restoring it into a scratch database.
16.6.2. Changing Capacity and Recovering from a Missing or Failed Mount
The volume has 1 GiB and is mounted. Grow it by 512 MiB and resize the filesystem in one operation:
$ sudo lvextend -L +512M -r /dev/datavg/appdata
File system ext4 found on datavg/appdata mounted at /srv/appdata.
Size of logical volume datavg/appdata changed from 1.00 GiB (256 extents) to 1.50 GiB (384 extents).
Extending file system ext4 to 1.50 GiB (1610612736 bytes) on datavg/appdata...
resize2fs /dev/datavg/appdata
resize2fs 1.47.2 (1-Jan-2025)
Filesystem at /dev/datavg/appdata is mounted on /srv/appdata; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/datavg/appdata is now 393216 (4k) blocks long.
resize2fs done
Extended file system ext4 on datavg/appdata.
Logical volume datavg/appdata successfully resized.
The -L +512M grows the logical volume by 512 MiB; -r runs resize2fs
after the device is resized, and the resize2fs 1.47.2 line is that tool's
version banner. The exact block count and extent count depend on
the volume group's extent size; the important lines are the old and new sizes
and the successful resize2fs. The filesystem is mounted, so ext4 performs an
online resize; that is supported for growing, not for shrinking. Confirm both
layers:
$ df -h /srv/appdata
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/datavg-appdata 1.5G 308K 1.4G 1% /srv/appdata
$ sudo lvs datavg
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
appdata datavg -wi-ao---- 1.50g
df reports the filesystem's view, lvs the logical volume's view. If they
disagree, the volume was extended but the filesystem was not resized; run
resize2fs /dev/datavg/appdata or repeat lvextend -r. A filesystem that is
smaller than its volume wastes space; a volume that is smaller than its
filesystem is impossible and indicates a serious inconsistency.
Now simulate a missing volume. Unmount it, deactivate the logical volume, and try to mount the fstab entry:
$ sudo umount /srv/appdata
$ sudo lvchange -an datavg/appdata
Both commands are silent. The logical volume's device node disappears; the fstab entry still names its UUID. The mount fails:
$ sudo mount /srv/appdata
mount: /srv/appdata: can't find UUID=ebee9a29-b855-4af5-a623-e9b4010ac3ee.
The error names the UUID rather than the device because the fstab entry uses the UUID. The data is intact; the volume is not active. Activate the group and mount again:
$ sudo vgchange -ay datavg
1 logical volume(s) in volume group "datavg" now active
$ sudo mount /srv/appdata
The mount is silent on success. Confirm it:
$ findmnt /srv/appdata
TARGET SOURCE FSTYPE OPTIONS
/srv/appdata /dev/mapper/datavg-appdata ext4 rw,relatime
vgchange -ay activates all logical volumes in the group; use lvchange -ay
datavg/appdata when only one volume should be active. An inactive volume at
boot is often caused by a missing physical volume, a failed RAID array, or a
LUKS mapping that was not opened; the fstab error names the missing UUID, but
the cause is one layer below. Check pvs, vgs, lvs, and cryptsetup
status before assuming the filesystem is damaged.
The second mount failure is a wrong fstab UUID. Unmount the volume, change the entry to a UUID that does not exist, reload systemd, and try the mount:
$ sudo umount /srv/appdata
The edit itself is made with an editor or with sed; the resulting line is:
UUID=deadbeef-0000-0000-0000-000000000000 /srv/appdata ext4 defaults 0 2
$ sudo systemctl daemon-reload
$ sudo mount /srv/appdata
mount: /srv/appdata: can't find UUID=deadbeef-0000-0000-0000-000000000000.
Restore the correct UUID and mount all entries:
$ sudo systemctl daemon-reload
$ sudo mount -a
The mount -a mounts every entry in /etc/fstab that is not already mounted.
It is silent on success. Verify the target:
$ findmnt /srv/appdata
TARGET SOURCE FSTYPE OPTIONS
/srv/appdata /dev/mapper/datavg-appdata ext4 rw,relatime
The data is still there. Check the database through the application's query before the destructive restore:
$ sqlite3 /srv/appdata/inventory.db "SELECT count(*) FROM parts;"
3
The count proves that the volume, the mount, and the database survived the capacity change and the two mount failures. The metadata is not checked yet; the final restore will verify it.
16.6.3. Restoring Data and Metadata and Verifying Application Access
The destructive step removes the application's files from the mounted volume.
The archive on /dev/vde is the only copy used for the restore, so verify that
sha256sum -c passed before continuing. The lost+found directory remains
because it belongs to the filesystem, not the application. The following
command deletes the report, the configuration, and the database:
$ sudo rm -rf /srv/appdata/reports /srv/appdata/config /srv/appdata/inventory.db
The command is silent. List what remains:
$ ls -A /srv/appdata
logs
lost+found
The logs directory is empty because the application had not written a log
during the lab; lost+found is the ext4 recovery directory. The report, the
configuration, and the database are gone from the volume, but the archive on
/dev/vde is untouched. Restore it with the same metadata options used to
create it:
$ sudo tar --acls --xattrs --numeric-owner -xpf /mnt/backup/appdata-before-repair.tar -C /srv
The command is silent. -x extracts, -p preserves permissions and
timestamps, -f names the archive, and -C /srv places the archived
appdata/... paths under /srv. The extraction runs as root, so it can restore
the www-data ownership and the numeric IDs even when the rescue environment's
name service does not know those accounts. Verify ownership and mode:
$ sudo stat -c "%U:%G %a %n" /srv/appdata/config/app.conf /srv/appdata/reports/quarterly.txt
www-data:www-data 640 /srv/appdata/config/app.conf
john:john 664 /srv/appdata/reports/quarterly.txt
The configuration is back to www-data:www-data with mode 0640; the report
is john's with mode 0664. The numeric owner in the archive was restored to
the names that those IDs resolve to on this system. Verify the ACL:
$ getfacl -p /srv/appdata/config/app.conf
# file: /srv/appdata/config/app.conf
# owner: www-data
# group: www-data
user::rw-
user:john:r--
group::r--
mask::r--
other::---
The named-user entry user:john:r-- and the mask are present; a restore
without --acls would have produced only the traditional mode bits. Verify the
extended attribute:
$ getfattr -d /srv/appdata/config/app.conf
# file: srv/appdata/config/app.conf
user.handbook="chapter16"
getfattr strips the leading slash in its comment and prints the user.
attribute. A restore without --xattrs would have lost this marker even though
the file contents and mode were correct.
Verify the application's own data through its normal query path:
$ sqlite3 /srv/appdata/inventory.db "SELECT name, quantity FROM parts ORDER BY id;"
bolt|120
nut|300
washer|500
The rows match the pre-loss state. Check access as the service account, not only as the owner:
$ sudo -u www-data sqlite3 /srv/appdata/inventory.db "SELECT count(*) FROM parts;"
3
sudo -u www-data runs the query with the web server's identity; a permission
problem on the directory, the database file, or the ACL would fail here even
though root could read the file. The count of 3 confirms that the application
can see all rows. In a real service, restart the application and make a
request through its own health endpoint or a test client; the database query
is a direct check of the data path, not of the application's network path.
Run a final filesystem check and usage check. Unmount the volume first, because
e2fsck on a mounted filesystem is not a valid check:
$ sudo umount /srv/appdata
$ sudo e2fsck -fn /dev/datavg/appdata
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
appdata: 18/98304 files (0.0% non-contiguous), 15211/393216 blocks
The filesystem is clean, with 18 inodes in use and 15,211 blocks allocated. The file count is larger than the pre-loss check because the restore recreated the directories and the database; the exact numbers are not the test, the exit status and the absence of errors are. Mount it again for service and check the usage:
$ sudo mount /srv/appdata
$ df -h /srv/appdata
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/datavg-appdata 1.5G 308K 1.4G 1% /srv/appdata
The volume is mounted, the filesystem is clean, the database is queryable, and the metadata is restored. The recovery is complete for this volume. The final actions are to unmount it and the backup disk:
$ sudo umount /srv/appdata
$ sudo umount /mnt/backup
The recovery copy is still mounted under /mnt/recovery; unmount its ESP and
root when no further chroot work is needed:
$ sudo umount /mnt/recovery/boot/efi
$ sudo umount /mnt/recovery
All four unmounts are silent. Confirm that no mount remains at the recovery directory:
$ findmnt --mountpoint /mnt/recovery || printf 'no mount at /mnt/recovery\n'
no mount at /mnt/recovery
The || operator runs printf only when findmnt exits nonzero, which it
does when no mount exists at the path. --mountpoint requires an exact mount
point; without it, findmnt treats its argument as an ordinary path and
reports the root filesystem that now contains the empty directory. Keep the
backup archive until the application has run long enough to prove that the
restored database and configuration are the ones it needs. Record the restore
source, the checksum, the verification queries, and the time the volume
returned to service. If the same volume fails again,
the record distinguishes a recurrence of the original fault from a problem in
the new storage.
A recovery is complete when the machine starts, the data is readable by its own application identity, the package database is consistent, the services that should be running are running, and the administrator has a tested path back in. Anything less is an interim state; label it as such in the incident record rather than closing the ticket because the login prompt returned.