e2fsck
Check and repair ext2/3/4 filesystems
TLDR
Check filesystem, reporting any damaged blocks
Check filesystem and automatically repair ([p]reen) any damaged blocks
Check filesystem in read only mode
[f]orce checking even if the filesystem seems clean
Perform an exhaustive, non-destructive read-write test for bad blocks and blacklist them
SYNOPSIS
e2fsck [options] device
PARAMETERS
-a
Preen: auto-fix minor errors without prompts (boot default)
-b superblock
Use alternate superblock location
-B blocksize
Filesystem block size (usually auto)
-c [interval] [blocks]
Check for bad blocks with badblocks(8)
-C fd
Progress info to file descriptor fd (0=stdout)
-d
Debug: print verbose debug info
-D
Optimize directories (htree rebuild)
-E extended_options
Ext4 extended opts (e.g., ^extended_options)
-f
Force check even if marked clean
-F
Flush FS buffers before checking
-I inode_size
Set expected inode size
-l badblocks_file
Add bad blocks from file to list
-L badblocks_file
Replace bad blocks list from file
-m reserved_blocks_percent
Set reserved blocks percentage
-n
Read-only: check without changes
-p
Auto-repair like -a, but fix more aggressively
-r repair_fd
Display repair list to fd (deprecated)
-t fsck_time
Set last fsck time
-v
Verbose output
-y
Answer 'yes' to all prompts
-z undo_file
Create undo file for replay
DESCRIPTION
e2fsck is the primary tool for checking and repairing ext2, ext3, and ext4 filesystems on Linux. It verifies the integrity of critical structures including superblocks, inodes, block and inode bitmaps, directories, and journals (for ext3/4). Errors are classified by severity, with options for read-only verification, automatic fixes, or interactive prompts.
Invoked automatically during boot via fsck (as /sbin/fsck.ext2, etc.) if the filesystem isn't marked clean. Manual runs require an unmounted device to prevent corruption. Key features include bad block detection via badblocks(8), alternate superblock usage for damaged primaries, directory optimization, and progress reporting.
In preen mode (-a or -p), it fixes non-critical issues silently, ideal for boot-time use. Force mode (-f) checks clean filesystems. For disasters, interactive mode lists fixes; -y assumes yes to all. Large filesystems may take hours; monitor with -C 0 for stdout progress.
Essential for maintenance, but improper use risks data loss. Pair with tune2fs for features like lazy_itable_init to speed checks.
CAVEATS
Always unmount filesystem first (except boot/root).
Can cause data loss on severe corruption.
Time-intensive on large drives (>1TB).
Online resize2fs may allow mounted checks, but risky.
FINDING SUPERBLOCKS
dumpe2fs -h device | grep superblock
Lists backups; use with -b if primary damaged.
EXAMPLES
e2fsck -f -y /dev/sda1
Force check, auto-yes repair.
e2fsck -n -C 0 /dev/sda1
Read-only check with progress.
JOURNAL HANDLING
Replay journal first with tune2fs -n or debugfs; e2fsck -E journal_only checks only journal.
HISTORY
Part of e2fsprogs suite, created 1993 by Remy Card for ext2fs. Enhanced by Theodore Ts'o for ext3 (2001 journaling) and ext4 (2008 extents/large fs). Widely used in Linux distros; active development continues for modern features like metadata checksums.


