How to Repair Corrupted XFS Filesystem with xfs_repair

Our partition is now successfully mounted as an xfs partition. Next, we are going to simulate filesystem corruption by trashing random filesystem metadata blocks using the xfs_db command.

~]$ sudo mount | grep /dev/sdb1
~]$ sudo umount /dev/sdb1

~]$ sudo xfs_db -x -c blockget -c "blocktrash -s 512109 -n 1000" /dev/sdb1

Before we embark on repairing the filesystem, we can perform a dry run using the -n flag as shown. A dry run provides a peek into the actions that will be performed by the command when is it executed.

~]$ sudo xfs_repair -n /dev/sdb1
~]$ sudo xfs_repair /dev/sdb1