rocky linux ·

Fixing XFS Metadata Corruption on Rocky Linux

XFS metadata corruption can prevent your Rocky Linux system from functioning properly. This guide will show you how to identify the issue and repair the corrupted filesystem.

Fixing XFS Metadata Corruption on Rocky Linux

You might encounter an error like this in your system logs:

Oct 08 10:41:52 jeremy-vm.umh.local kernel: XFS (dm-0): Metadata corruption detected at xfs_bmap_validate_extent+0x6e/0x80 [xfs], inode 0x40a090d xfs_iread_extents(2)
Oct 08 10:41:52 jeremy-vm.umh.local kernel: XFS (dm-0): Unmount and run xfs_repair
Oct 08 10:41:52 jeremy-vm.umh.local kernel: XFS (dm-0): First 16 bytes of corrupted metadata buffer:
Oct 08 10:41:52 jeremy-vm.umh.local kernel: 00000000: 00 00 13 f6 80 49 99 d8 00 00 00 00 00 00 24 cc  .....I........$.

Identifying the Affected Partition

The error mentions XFS (dm-0), indicating that the partition /dev/dm-0 is affected. To find out which logical volume this corresponds to, follow these steps:

List Device Mapper Devices

Run:

sudo dmsetup ls --tree

This will display the device mapper names and their corresponding devices.

List the contents of /dev/mapper/:

ls -l /dev/mapper/

Look for a symlink pointing to ../dm-0. For example:

lrwxrwxrwx 1 root root 7 Oct 8 12:00 rl_jeremy--flatcar-root -> ../dm-0

This shows that rl_jeremy--flatcar-root corresponds to /dev/dm-0`. This means it is the root partition (ignore the flatcar here, that is because the VM was previously a flatcar system)

Fixing the Metadata Corruption

Since the affected partition is likely your root filesystem, you cannot unmount it while the system is running normally. You’ll need to boot into emergency mode.

Steps to Repair the Filesystem

Ensure Root Password Is Set

Make sure the root account has a valid password. You’ll need it to log in during the repair process.

Reboot the System

Run:

sudo reboot

Enter GRUB Menu

As the system reboots and the GRUB menu appears:

  • Select the kernel you want to boot.
  • Press e to edit the boot parameters.
  • Modify Boot Parameters
    Find the line that starts with linux or linux16. At the end of this line, add:
systemd.unit=emergency.target

This tells the system to boot into emergency mode.

Boot into Emergency Mode

Press Ctrl+X or F10 to boot with the modified parameters.

Log In as Root

When prompted, enter the root password to log in.

Run xfs_repair


Use the -d option to repair the filesystem even if it’s mounted read-only:

xfs_repair -d /dev/dm-0

Replace /dev/dm-0 with the correct device if different.

Reboot the System

After the repair completes, reboot:

reboot

Additional Notes

  • Using -d with xfs_repair: The -d option allows xfs_repair to work on a mounted filesystem in a read-only state. This is useful when you cannot unmount the partition, such as the root filesystem.
  • Emergency Mode: Booting into emergency.target gives you a minimal environment to perform system repairs without other services running.

Conclusion

By identifying the affected partition and running xfs_repair in emergency mode, you can fix XFS metadata corruption on Rocky Linux. Always proceed carefully and ensure you have backups before performing filesystem repairs.

Source: https://www.vttoth.com/CMS/technical-notes/390-force-xfs-root-filesystem-check-on-centos-rhel-oracle-linux

Read next

Share, Engage, and Contribute!

Discover how you can share your ideas, contribute to our blog, and connect with us on other platforms.