e2fsck
Check and repair ext2/3/4 filesystems
TLDR
Check filesystem, reporting any damaged blocks
Check filesystem and automatically repair any damaged blocks
Check filesystem in read only mode
Perform an exhaustive, non-destructive read-write test for bad blocks and blacklist them
SYNOPSIS
e2fsck [-pacnyrdfkvtDFV] [-b superblock] [-B blocksize] [-l|-L bad_blocks_file] [-C fd] [-j external-journal] [-E extended_options] device
PARAMETERS
-p
Automatically repair the filesystem without user intervention. Equivalent to -a
.-a
Same as -p
; automatically repair the filesystem.-c
Check for bad blocks by doing a read-only scan.-n
Open the filesystem read-only and answer 'no' to all questions.-y
Assume an answer of 'yes' to all questions; use with caution.-r
Interactive repair; ask questions even if using -p
or -a
.-d
Print debugging output (for developers).-f
Force checking even if the filesystem appears clean.-k
Keep the bad blocks list when using -c
or -l
.-v
Verbose mode.-t
Print timing statistics.-D
Detect bad blocks by doing a destructive write test. USE WITH EXTREME CAUTION!-F
Flush the filesystem device's buffers before beginning.-V
Print version information and exit.-b superblock
Use the specified superblock number instead of the default.-B blocksize
Use the specified blocksize when examining the filesystem.-l bad_blocks_file
Add the blocks listed in bad_blocks_file to the bad blocks list.-L bad_blocks_file
Set the bad blocks list to be only the blocks listed in bad_blocks_file.-C fd
Output progress information to the specified file descriptor.-j external-journal
Locate the external journal device.-E extended_options
Set extended options. See man page for specific extended options.device
The device file to be checked (e.g., /dev/sda1).
DESCRIPTION
e2fsck
is an essential command-line utility in Linux systems used to check and repair ext2, ext3, and ext4 filesystems. Filesystem corruption can occur due to power outages, hardware failures, or software bugs. e2fsck
scans the filesystem for inconsistencies and attempts to fix them. It operates directly on the disk partition, analyzing the filesystem metadata (such as inodes, superblock, and group descriptors) to identify errors.
The program operates in several phases, including checking inodes, blocks, directories, and filesystem connectivity. e2fsck
can be run in read-only mode to check for errors without making any changes. In repair mode, it prompts the user for confirmation before making significant changes, although an auto-repair mode (-y
or -a
) can be used to automatically fix issues. Regularly running e2fsck
on important filesystems is critical to maintaining data integrity and system stability. It's crucial to unmount the filesystem before running e2fsck
in repair mode to avoid further corruption.
CAVEATS
Running e2fsck
on a mounted filesystem can lead to severe data corruption. Always unmount the filesystem before running e2fsck
in repair mode.
EXIT CODES
The exit code returned by e2fsck
is the sum of the following conditions:
0 - No errors
1 - Filesystem errors corrected
2 - System should be rebooted
4 - Filesystem errors left uncorrected
8 - Operational error
16 - Usage or syntax error
128 - Shared library error
WHEN TO RUN
It's recommended to run e2fsck
after a system crash, power outage, or any other event that might have interrupted disk writes. It can also be run proactively as part of a routine system maintenance schedule to detect and fix potential issues before they cause data loss.
HISTORY
e2fsck
was originally designed as part of the extended file system tools (e2fsprogs) created by Theodore Ts'o. It has evolved alongside the ext2, ext3, and ext4 filesystem formats. Its development closely followed the needs of journaling and advanced filesystem features. Over time, performance enhancements and features like online checking (with limitations) have been added. It remains a critical tool for system administrators to diagnose and resolve filesystem issues, ensuring data integrity.