LinuxCommandLibrary

xfs_repair

Repair a corrupted XFS filesystem

TLDR

Repair a partition

$ sudo xfs_repair [path/to/partition]
copy

SYNOPSIS

xfs_repair [ options ] device

PARAMETERS

device
    The special file (e.g., /dev/sda1) or volume name of the XFS filesystem to be repaired.

-f
    Specifies that the device is a file image, not a block device. Useful for repairing filesystems stored in regular files.

-L
    Forces the filesystem log to be zeroed out. This is a dangerous option and should only be used as a last resort if the filesystem cannot be mounted due to a corrupt log. It can result in data loss.

-n
    Performs a 'dry run' or 'no action' check. The command will simulate the repair process and report what would have been done without actually modifying the filesystem. Useful for assessing damage.

-v
    Enables verbose output. Provides more detailed information about the repair process and any errors found.

-c cmd
    Runs a specific repair command or sequence of commands during the repair process. This is for advanced use and allows for targeted fixes.

-P
    Prints progress messages periodically during the repair process, indicating which stage of the repair is currently active.

-o option
    Allows specifying various repair options, such as 'force_geometry' or 'nohashcheck'. Consult the man page for a full list.

-m max_mem_bytes
    Specifies the maximum amount of memory (in bytes) to be used by xfs_repair. Useful for limiting memory consumption on systems with limited RAM.

-s
    Specifies that the filesystem is a 'single volume' and disables multi-volume specific checks. Useful for filesystems created before multi-volume support was robust.

DESCRIPTION

The xfs_repair command is a utility designed to repair corrupted XFS filesystems. It examines an XFS filesystem on a specified device, looking for and attempting to correct inconsistencies. This tool is typically used when an XFS filesystem cannot be mounted, or when an administrator suspects data corruption.

It operates by analyzing the filesystem's metadata structures, such as allocation groups, inodes, and directories, to identify errors that might have occurred due to power failures, hardware issues, or software bugs. While xfs_repair aims to restore the filesystem to a consistent state, it's crucial to understand that it can sometimes lead to data loss, especially if severe corruption is present or if the `-L` (clear log) option is used carelessly. For this reason, it is always recommended to back up critical data before attempting a repair.

The command should only be run on an unmounted XFS filesystem to prevent further damage or inconsistencies. If the filesystem cannot be unmounted (e.g., it's the root filesystem), a rescue or live environment might be necessary.

CAVEATS

  • ALWAYS UNMOUNT FIRST: Running xfs_repair on a mounted filesystem can cause severe data corruption and loss.
  • BACKUP DATA: Before attempting any repair, especially with the -L option, ensure you have a complete backup of your data. xfs_repair can cause data loss.
  • NOT FOR ONLINE USE: This tool is designed for offline repair. For online consistency checks or defragmentation, use other XFS utilities like xfs_check or xfs_fsr.
  • RESCUE MODE: If the root filesystem is XFS and corrupted, you will likely need to boot into a rescue disk or live environment to run xfs_repair.

HISTORY

XFS was originally developed by Silicon Graphics, Inc. (SGI) in the early 1990s for their IRIX operating system, designed for high-performance computing and large filesystems. It was one of the first 64-bit journaling filesystems. When XFS was ported to Linux around 2001, xfs_repair became an essential component of the XFS tools suite, providing the necessary capability to maintain filesystem integrity. Its development has continued as part of the Linux kernel's XFS support, adapting to new features and addressing identified vulnerabilities or corruption scenarios, solidifying its role as the primary utility for offline XFS filesystem recovery.

SEE ALSO

mount(8), umount(8), xfs_check(8), xfs_info(8), xfs_admin(8), xfs_fsr(8)

Copied to clipboard