e2fsck Command: Tutorial & Examples
File System Check and Repair
e2fsck is a command-line tool in Linux systems that checks and
repairs ext2, ext3, and ext4, file systems. It is similar to
fsck command, but specifically designed for ext2/ext3/ext4 file systems, the most commonly
used file systems in Linux. The command works by performing several sequential phases, each addressing certain aspects
of the file system's integrity.
e2fsck command is a crucial tool for maintaining the health of your file system and as such, it should be part of
your Linux toolkit. It is typically used during system boot or maintenance mode, though it can be run manually if a
problem is suspected.
When to Use
It's also helpful in dealing with
inode problems, locating bad blocks, and fixing discrepancies
in directories, block counts, and more.
Basic Usage of
Here's an example of how to use
This command will run
e2fsck on the file system located on the device
Advanced Usage of
e2fsck also provides several options to customize its behavior. Here are some examples:
Check only, no repair (
-noption): This allows you to see what
e2fsckwould fix, without making changes.
e2fsck -n /dev/sda1
Automatically repair (
-aoption): This option automatically repairs any issues it finds without prompting for user intervention.
e2fsck -p /dev/sda1
Force checking even if the system seems clean (
e2fsckskips checking a file system if it seems clean. This option forces it to perform a check anyway.
e2fsck -f /dev/sda1
e2fsck provides feedback on its checks and repairs, such as the number of files and blocks checked, the number of
errors found and fixed, and more.
For example, after running
e2fsck -p /dev/sda1, you might see an output like this:
/dev/sda1: 11/100 files (0.0% non-contiguous), 130/400 blocks
This indicates that
e2fsck has checked 11 out of 100 files and 130 out of 400 blocks, with no files stored
e2fsck command is a powerful tool in a Linux administrator's arsenal for checking and repairing file systems.
While it can be a bit complex to master, understanding its basics can go a long way in maintaining the health and
integrity of your Linux systems.