Fsck Quick Reference
Luke Hebert
- 2 minutes read - 277 wordsWhen a disk reports I/O errors or a system fails to mount a partition cleanly, running a forced filesystem check is often the fastest way to identify and repair corruption. The command below checks an ext2/3/4 partition, assumes “yes” to every repair prompt, and writes the full output to a timestamped log file for later review.
Command
/sbin/e2fsck -C 0 -fvy /dev/sdb1 2>&1 | tee -a /root/`hostname`.`date +%s`.fsck.logFlag Breakdown
| Flag | Purpose |
|---|---|
-C 0 | Disable the progress bar (useful in scripts or when piping output) |
-f | Force a check even if the filesystem is marked clean |
-v | Verbose output, showing each pass and repair action |
-y | Automatically answer “yes” to every repair prompt |
Notes
Run e2fsck only on an unmounted filesystem. If the partition is mounted, unmount it first or boot into single-user / rescue mode. Running the check on a live, mounted volume can cause further corruption.
The log file name uses the current hostname and a Unix epoch timestamp, so repeated runs on the same host will not overwrite previous logs. Adjust the path if you prefer a different location.
Typical Use Cases
- Post-hardware-failure recovery (bad sectors, unexpected power loss)
- Pre-migration integrity check before moving a volume to new storage
- Scheduled maintenance on non-critical partitions
Verifying the Result
After the check completes, confirm the exit code:
echo $?
# 0 = no errors
# 1 = errors corrected
# 2 = errors corrected, system should be rebooted
# 4+ = uncorrected errors remainIf the exit code is 4 or higher, review the log file for the specific blocks or inodes that could not be repaired and consider restoring from backup.