This utility checks an ext2/ext3 file system. Most often used after a sudden shutdown, such as from a power outage, or when damage to the disk is suspected. Some useful arguments taken from man e2fsck are as follows:
- -c: Checks for bad blocks and then marks them as bad.
- -f: Forces checking on a clean file system.
- -v: Verbose mode.
If you encounter the below error while running the command e2fsck:
e2fsck: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install e2fsprogs |
Ubuntu | apt-get install e2fsprogs |
Alpine | apk add e2fsprogs |
Arch Linux | pacman -S e2fsprogs |
Kali Linux | apt-get install e2fsprogs |
CentOS | yum install e2fsprogs |
Fedora | dnf install e2fsprogs |
OS X | brew install e2fsprogs |
Raspbian | apt-get install e2fsprogs |
e2fsck Command Examples
1. To check a file system:
# e2fsck /dev/sda1 # e2fsck /dev/mapper/VG00-LV00
2. To check the file system and repair it if found any:
# e2fsck -p /dev/sda1
3. To check the file system and repair it if found any error (with backward compatibility):
# e2fsck -a /dev/sda1
4. To force e2fsck to only try locating the super-block at a particular blocksize:
# e2fsck -B 1024 /dev/sda1
5. To to do a read-only scan of the device:
# e2fsck -c /dev/sda1
6. To to write completion information to the specified file descriptor:
# e2fsck -C fd /dev/sda1
7. To print debugging output:
# e2fsck -d /dev/sda1
8. To Optimize directories in file system:
# e2fsck -D /dev/sda1
9. To set the e2fsck extended options:
# e2fsck -E ea_ver=extended_attribute_version # e2fsck -E fragcheck
10. To Force checking even if the file system seems clean:
# e2fsck -f
11. To Set the path name where the external-journal for this file system can be found:
# e2fsck -j external-journal
12. To preserve the existing bad blocks:
# e2fsck -kc /dev/sda1
13. To add the block numbers specified in the file:
# e2fsck -l /tmp/file.txt /dev/sda1
14. To set the bad blocks list specified in the file:
# e2fsck -L /tmp/file.txt /dev/sda1
15. To open the file system read-only:
# e2fsck -n /dev/sda1
16. To have the backward compatibility:
# e2fsck -r /dev/sda1
17. To have the time stats:
# e2fsck -t /dev/sda1
18. To set the verbose mode:
# e2fsck -v /dev/sda1
19. To get the version information:
# e2fsck -V
20. To set the answer to “yes”:
# e2fsck -y /dev/sda1