XFS metadata consistency limits after LVM snapshot restoration
0 reputation · 18 Jan 2020, 23:25 UTC
0 reputation · 18 Jan 2020, 23:25 UTC
Rocky Linux uses LVM for snapshot-based backups and XFS as the primary filesystem, with metadata journaling intended to preserve consistency across volume group operations.
Restoring a snapshot via block-level copy to a logical volume raises uncertainty about deep metadata alignment between the LVM point-in-time state and the XFS on-disk structures after the volume is reactivated. SELinux extended attributes are a documented behavior concern when restoration does not explicitly preserve them.
What limits exist for verifying XFS metadata integrity beyond standard repair tools after an LVM snapshot restore? How is SELinux context reapplication handled when extended attributes are not preserved in the snapshot metadata?
29775 reputation · 19 Jan 2020, 01:49 UTC
What limits exist for verifying XFS metadata integrity beyond standard repair tools after an LVM snapshot restore?
xfs_repair cannot recover uncommitted changes, and the filesystem may refuse to mount.xfs_repair with the -L option truncates the journal; any uncommitted data is lost. Use it only when you have a full backup of the data or are willing to accept that loss.How is SELinux context reapplication handled when extended attributes are not preserved in the snapshot metadata?
restorecon -Rv / to walk the tree and reapply the correct contexts according to the policy. This will set the proper SELinux labels based on file names and paths.restorecon, check semanage fcontext -l to ensure all file types have the expected contexts.When a snapshot is taken while the filesystem is mounted, the kernel flushes dirty pages to disk, which reduces the chance of incomplete metadata. However, if the snapshot is taken on an unmounted or partially mounted volume, the metadata area may be left in a half‑written state. In such cases, xfs_repair with the -n flag will often report inconsistencies that require a full repair. If the snapshot was created with lvcreate --snapshot while the filesystem was busy, the journal may not have been fully written, and the repair process will truncate it if you use -L.
Verify the snapshot contains the entire metadata region:
xfs_info /dev/<device> | grep "metadata size"
Compare the reported size to the snapshot size. If the snapshot is smaller, you risk unrecoverable corruption.
Unmount the target logical volume (if not already unmounted):
umount /dev/<device>
Run a dry‑run repair to detect inconsistencies:
xfs_repair -n /dev/<device>
Review the output. If no errors are reported, proceed to remount.
If errors are found, perform a full repair. Use -L only if you are prepared to lose uncommitted data:
xfs_repair -L /dev/<device>
Remount the filesystem:
mount /dev/<device> /mount/point
Reapply SELinux contexts if extended attributes were not preserved:
restorecon -Rv /mount/point
Verify context restoration:
ls -Z /mount/point | head
Was the snapshot taken while the XFS filesystem was mounted?
Answering this will help determine whether a full xfs_repair -L is necessary or if a simple dry‑run will suffice.
Use comments to ask for clarification. Post a solution as an answer.
29,775 reputation · 19 Jan 2020, 11:02 UTC
To clarify the metadata state after restoration, it is important to distinguish between crash-consistency and application-consistency. Because LVM snapshots capture the block device at a specific instant, the restored XFS volume typically enters a "crash-consistent" state, mimicking a sudden power loss.
When the restored volume is first mounted, XFS automatically initiates log recovery to replay pending metadata transactions from the journal. You can verify this behavior by checking dmesg or system logs for XFS recovery messages during the mount process. If the log is intact, this ensures structural metadata integrity without needing xfs_repair.
For deeper verification beyond standard repair tools, the xfs_metadump utility can be used to extract the metadata into a separate file for offline analysis, allowing you to inspect the structural integrity of the filesystem without risking further corruption on the live block device.