Skip to content

Linux Filesystem Corrupt — fsck Recovery Guide

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Linux Filesystem Corrupt. We cover key concepts, practical examples, and best practices.

Filesystem corruption prevents Linux from booting or accessing files, showing errors like "unexpected inconsistency", "fsck failed", or "superblock last mount time is in the future". The primary recovery tool is fsck (filesystem check).

The Problem

On boot:

/dev/sda1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY

Or:

FATAL: Could not read superblock
mount: /dev/sda1: can't read superblock

Wrong Approach

# WRONG — running fsck on a mounted filesystem
sudo fsck /dev/sda1  # Causes further corruption

Right Approach

# Boot from recovery media or single-user mode
# Unmount the filesystem first
sudo umount /dev/sda1

# Run fsck interactively
sudo fsck -f /dev/sda1

Expected output:

fsck from util-linux 2.34
e2fsck 1.45.6
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda1: ***** REBOOT LINUX *****
/dev/sda1: 123456/1000000 files (0.1% non-contiguous)

Step-by-Step Fix

Step 1: Boot into recovery mode

Restart the system and hold Shift (BIOS) or Esc (UEFI) to access GRUB. Select "Advanced options" then "Recovery mode" and choose "Drop to root shell prompt".

Step 2: Remount the root filesystem as read-only

mount -o remount,ro /

Step 3: Run fsck on the affected partition

fsck -f /dev/sda1

Answer "yes" to all prompts, or use -y:

fsck -yf /dev/sda1

Step 4: Recover from backup superblock

# List backup superblocks
mke2fs -n /dev/sda1

# Use a backup superblock (e.g., 32768)
fsck -b 32768 /dev/sda1

Step 5: Check filesystem type

# For XFS
xfs_repair /dev/sda1

# For Btrfs
btrfs check /dev/sda1

Step 6: Reboot after successful repair

reboot

Step 7: Verify filesystem health

dmesg | grep -i "corrupt\|error\|fail"
sudo smartctl -H /dev/sda

Prevention Tips

  • Always shut down Linux cleanly with shutdown -h now
  • Use a UPS to prevent power-loss corruption
  • Monitor disk health with smartctl and replace failing drives
  • Schedule regular fsck checks with tune2fs -c 30 /dev/sda1
  • Use a journaling filesystem (ext4, XFS) for faster crash recovery

Common Mistakes with filesystem corrupt

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Can I run fsck on a mounted filesystem?

Never run fsck on a mounted filesystem. It can cause catastrophic corruption because the kernel may modify the filesystem while fsck is repairing it. Boot into recovery mode or use a live USB to unmount the partition first.

What does "superblock" mean in filesystem errors?

The superblock is the filesystem's primary metadata structure containing information about size, block count, inode count, and mount state. If it is corrupted, the kernel cannot read the filesystem. Backup superblocks are stored every 32768 blocks for recovery.

How do I prevent filesystem corruption?

Use a UPS for clean shutdowns, enable the filesystem journal, monitor SMART disk health, and schedule periodic fsck checks. Replace drives showing reallocated sectors or pending sector errors immediately to prevent data loss.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro