Interview Prep/Linux/Storage, disks and filesystems

You need to check and repair an ext4 filesystem that reported errors. How do you do it safely?

IntermediateScenarioStorage, disks and filesystems
Answer

Situation read → Never run fsck on a mounted read-write filesystem.

What I'd do →

  1. Unmount the filesystem (for root, boot into rescue mode or schedule a check at boot).
  2. Take a snapshot or image first if the data matters (dd or a cloud snapshot).
  3. Run:
sudo e2fsck -f -y /dev/vg0/data
  1. For XFS use xfs_repair /dev/vg0/data (use -n first for a dry run).
  2. Check lost+found for recovered files afterwards.

Why → Repairing a mounted filesystem can corrupt it further.

Interview tip → Mention that tune2fs -l shows the last check time and mount count.

All Linux questions Roadmap: Linux

More on Storage, disks and filesystems