How to Scan and Repair Linux Disk Errors with fsck and xfs_repair
This guide walks you through identifying Linux disk partitions, checking and fixing Ext4 and XFS file systems using fsck and xfs_repair, and configuring automatic checks at boot by adjusting mount counts and GRUB parameters, complete with command examples and output screenshots.
What is fsck? The fsck (file system consistency check) utility verifies the integrity of Linux file systems.
Listing Disk Partitions
First, determine the partitions, their file system types, and mount points using:
# lsblk -o NAME,FSTYPE,MOUNTPOINTGetting the Last Check Time for Ext2/3/4
Use tune2fs -l to find the last check date:
# tune2fs -l /dev/nvme0n1p1 | grep checked
Last checked: Wed Sep 1 15:42:11 2021Scanning and Repairing an Ext4 Partition
Unmount the target partition before running the check: # umount /dev/nvme0n1p1 Run the file‑system‑specific check:
# fsck.ext4 /dev/nvme0n1p1
... /dev/nvme0n1p1: clean, 311/65536 files, 55546/262144 blocksRemount all partitions defined in /etc/fstab:
# mount -aEnabling Automatic Ext4 Checks at Boot
Set the maximal mount count to 1 so the file system is checked on every boot:
# tune2fs -c 1 /dev/nvme0n1p1
Setting maximal mount count to 1Reboot the system; the check will run automatically:
# rebootWhat is xfs_repair?
The xfs_repair utility is designed for large XFS file systems and can run without unmounting if the file system was cleanly unmounted; otherwise, unmount first.
Scanning and Repairing an XFS Partition
Unmount the XFS partition: # umount /dev/sda1 Perform a dry‑run check (no modifications):
# xfs_repair -n /dev/sda1
Phase 1 - find and verify superblock...
Phase 2 - using internal log ...
... (output truncated)Run the full repair (without -n) to fix errors:
# xfs_repair /dev/sda1
Phase 1 - find and verify superblock...
Phase 7 - verify and correct link counts...
DoneMount the repaired partition:
# mount /dev/sda1 /data/Enabling Automatic XFS Checks at Boot
Add the kernel parameters fsck.mode=force fsck.repair=yes to GRUB_CMDLINE_LINUX in /etc/default/grub:
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap fsck.mode=force fsck.repair=yes"Regenerate the GRUB configuration and reboot:
# grub2-mkconfig
# rebootConclusion
Using the steps above, you can successfully scan and repair both Ext4 and XFS file systems on Linux, and configure the system to perform automatic checks at each boot.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
