I ran into a problem. My XFS root file system on a CentOS 7 machine was corrupt. It was still working fine by and large, but it reported very little free space, despite the fact that the actual file content amounted to only about 30% of the volume's capacity.

Because it is the always-mounted root file system, it was not possible to run xfs_repair. I could have booted the system from a rescue CD/DVD, but that was not a convenient option: It would have required finding an ancient CentOS DVD and an external DVD drive, messing with BIOS boot options, the usual. I figured that there had to be a better way and indeed, there was. Here are the steps:

  1. Make sure the root account has a valid password. You'll need to be able to log on as root at one point.
  2. Reboot the system.
  3. In the grub menu, select the kernel you want and hit e to edit the boot parameters.
  4. Add the following kernel parameter to the linux or linux16 command:
  5. Hit Ctrl-X to boot the system into emergency mode, and log in using the root password.
  6. Run xfs_repair on the partition in question, using the -d option that allows it to run on a read-only mounted partition. In my case:
    xfs_repair -d /dev/mapper/centos-root
  7. When it's finished, reboot immediately.
  8. You may remove the root password if you wish (e.g., replace its hash with a * character in /etc/shadow).

That was it. After the reboot, I had nearly 70% free space on the root partition. (NB: If you check free space before the reboot, it will still report the old number.)