Repairing a corrupt btrfs filesystem

There are some reasons:

  • File corruption is not the same as filesystem corruption:

    • If only specific files are corrupted but the filesystem itself (including metadata) works properly (i.e., It can be mounted and read), this is usually not an error at the Btrfs level.
    • File corruption can happen due to checksum mismatches, often caused by bit failures in hardware, it doesn’t mean the whole filesystem needs to be repaired. This is why it’s recommended to use btrfs scrub instead of btrfs check --repair
  • btrfs check --repair is designed to repair critical filesystem corruption, especially when the filesystem cannot be mounted or is severely damaged. However, sometimes it succeeds (luckily), while other times it can lead to data loss after running the repair option.

  • Running btrfs check --repair on the working filesystem can be risky, as it might inadvertently cause more harm to the metadata or data structure.

From the Btrfs repair manpage:

WARNING:
Do not use –repair unless you are advised to do so by a developer or an experienced user, and then only after having accepted that no fsck successfully repair all types of filesystem corruption. E.g. some other software or hardware bugs can fatally damage a volume.

6 Likes