I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

How to Check and Repair XFS Filesystem in RHEL/Centos

Hello, friends. In this post, we will explain a trick that can save a lot of work and even an entire system. So, today you will learn How to Check and Repair XFS Filesystem in RHEL/RockyLinux/CentOS.

Before we start, we need to talk a little about XFS.

XFS is a high-performance 64-bit journaling file system. Its virtues such as maturity, and debugged code, make it a preferred candidate for use on GNU/Linux servers.

Some main advantages of XFS are:

  • Thanks to journaling, easy and fast recovery from data loss is possible. This feature is vital in a production server.
  • With XFS, there is the possibility to enlarge the partition while it is mounted and active.
  • XFS can execute I/O (Input/Output) operations in parallel.

And so on. That is why many servers with RHEL, RockyLinux and derivatives use it.

However, it is possible that it can fail us, so that is the reason for today’s post.

How to Repair XFS Filesystem in RHEL/RockyLinux/CentOS

Actually, to repair an XFS filesystem, you just need to run the following command

xfs_repair [option] [device]

However, we have to have a corrupted XFS system, and this on a production system is fatal.

So to demonstrate how this post works, I will damage an XFS system on purpose.

Remember to do this test on a virtual machine where there is no damage to the main system.

Let’s suppose that our partition or device or system is mounted in /device first we must unmount it.

umount /device

And now damage the file system by running

xfs_db -x -c blockget -c "blocktrash -s 512109 -n 1000" [device]

For example,

sudo xfs_db -x -c blockget -c "blocktrash -s 512109 -n 1000" /dev/sdb1
1.- XFS corrupted
1.- XFS corrupted

And of course if you try to mount it you should get an error similar to this one

mount: /device: mount(2) system call failed: Structure needs cleaning. 

So, let’s fix it.

For that, the volume has to be unmounted.

And to repair it run the following command

xfs_repair [device]

For example,

xfs_repair /dev/sdb1 

At the end you will see an output screen similar to this one

2.- Repare XFS FileSystem on RHEL / RockyLinux
2.- Repare XFS FileSystem on RHEL / RockyLinux

So, the process has been extensive.Now just mount.

mount /dev/sdb1

Enjoy it.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook