How to Use fsck to Check and Repair Linux Filesystem Errors

lvdisplay

Here are the most common scenarios where running fsck is necessary or recommended:
umount /dev/sdb1

fsck [options] [filesystem]

tune2fs -C 1 /dev/sda1

fsck -f /dev/sdb1

If the filesystem was marked as clean, but you still suspect issues:
fsck is a built-in Linux utility used to check and repair filesystem inconsistencies. It works similarly to chkdsk on Windows. The tool can be run automatically during system boot or manually by the system administrator.
tune2fs -i 6m /dev/sda1

Running fsck on a mounted partition can cause severe data corruption, so always unmount the partition first.
umount -l /dev/sdb1

Running fsck to Check and Repair a Partition

fsck -AR -y

Set a time-based check interval (e.g., every 6 months):
fsck -y /dev/sdb1

fsck -y /dev/md0

The key rules to remember:
fsck -C -V /dev/sdb1

tune2fs -c 30 /dev/sda1

Depending on the filesystem type (ext2, ext3, ext4, xfs, etc.), fsck calls the appropriate backend checker, for example, e2fsck for ext-family filesystems.
fsck -t ext4 /dev/sdb1

# On RHEL/CentOS/Rocky Linux
grep -i fsck /var/log/messages

# On Ubuntu/Debian
grep -i fsck /var/log/syslog

# Systemd journal
journalctl -b | grep -i fsck

Quick Reference: fsck Command Examples

fsck /dev/sdb1

lsblk -f
Or
blkid /dev/sdb1

reboot

After running fsck, it returns an exit code that tells you what happened. You can check it with echo $? right after running the command.

Understanding fsck Exit Codes

tune2fs -l /dev/sda1 | grep -i “mount count|check interval”

View Filesystem Health Summary

fsck Command Syntax:
ls /forcefsck
rm /forcefsck

Before running fsck, confirm the filesystem type of your partition:

Method 1: Force fsck on Next Boot

On production servers, it’s good practice to schedule periodic fsck runs rather than waiting for problems to occur.
fsck -N /dev/sdb1

mount | grep /dev/sdb

For ext4 filesystems, you can force an fsck on the next reboot using tune2fs, which will sets the mount count to 1, which triggers fsck at next boot. After the check, the mount count resets automatically.

Method 2: Force fsck via tune2fs (ext4)

In this article, we’ll cover everything you need to know about fsck from basic usage to running it safely on root and production partitions.
If you have any questions about using fsck or ran into a specific error, feel free to share it in the comments below.
Production Tip: Always check /var/log/syslog or run dmesg | grep -i error before scheduling an fsck, which helps you understand the scope of the problem before diving in.

  • Step 1: Reboot the system and during boot, hold the Shift key to bring up the GRUB menu.
  • Step 2: Select “Advanced options” from the GRUB menu.
  • Step 3: Choose “Recovery mode” for your kernel version.
  • Step 4: In the recovery menu, select “fsck“.
  • Step 5: When prompted to remount the root filesystem, select “Yes“.
  • Step 6: Once fsck completes, select “Resume” to continue normal boot.

How to Run fsck on LVM and Software RAID Volumes

Linux filesystems are responsible for organizing how data is stored and retrieved. Over time – due to sudden power failures, forced shutdowns, hardware issues, or software bugs – a filesystem can become corrupted, and certain parts of it may become inaccessible.
The simplest approach is to create a forcefsck flag file in the root:
When that happens, you need a reliable way to detect and fix those inconsistencies before they cause data loss or system instability. This is where fsck (File System Consistency Check) comes in.
0 – No errors detected
1 – Filesystem errors were corrected
2 – System should be rebooted
4 – Filesystem errors left uncorrected
8 – Operational error
16 – Usage or syntax error
32 – Checking was canceled by user request
128 – Shared library error

fsck -y /dev/sdb1
EXIT_CODE=$?

if [ $EXIT_CODE -ge 4 ]; then
echo “ALERT: Filesystem errors could not be corrected on /dev/sdb1” | mail -s “fsck Alert” [email protected]
fi

How to Run fsck on the Root Partition (/)

touch /forcefsck

tune2fs -c 30 /dev/sda1

Method 3: Run fsck in Rescue/Recovery Mode

lvchange -an /dev/vg_data/lv_data
fsck -y /dev/vg_data/lv_data
lvchange -ay /dev/vg_data/lv_data

To check if a partition is mounted:
lsof /dev/sdb1

Production Tip: In scripts and cron jobs, always capture and evaluate the fsck exit code to trigger alerts or automatic reboots when needed.

  • Never run fsck on a mounted partition.
  • Always do a dry run (-N) first on critical systems.
  • Capture exit codes in scripts to automate alerts and reboots.
  • Schedule periodic checks using tune2fs on important filesystems.

For LVM logical volumes, first identify the volume:

Similar Posts