Linux e2fsck Command
The Linux e2fsck command is used to check if a partition using the Linux ext2 file system is functioning correctly.
Syntax
e2fsck [-pacnydfvFV] [-b superblock] [-B blocksize] [-l|-L bad_blocks_file] [-C fd] device
Parameter Description:
device: The hard disk partition to be checked, for example: /dev/sda1
-a: Checks the partition and automatically repairs it if there are issues, equivalent to the -p function
-b: Sets the location where the superblock is stored
-B: Sets the size of the block unit
-c: Checks if the partition has bad sectors
-C file: Saves the check results to a file for later review
-d: Prints the debug results of e2fsck
-f: Forces the check
-F: Clears the device's buffer cache before starting the check to avoid errors
-l bad_blocks_file: Adds bad block data to the bad_blocks_file
-L bad_blocks_file: Sets the bad block data to be stored in the bad_blocks_file; if the file does not exist, it will be created automatically
-n: Opens the file system in read-only mode
-p: Checks the partition and automatically repairs it if there are issues
-v: Verbose mode
-V: Displays the current version of e2fsck
-y: Pre-sets all questions during the check to be answered with "yes"
Example
Checks if /dev/hda5 is functioning correctly, automatically repairs it if there are any issues, and sets all questions to be answered with "yes":
e2fsck -a -y /dev/hda5
Note:
When using e2fsck to check hard disk partitions, it is usually for special circumstances. Therefore, it is best to unmount the partition first and then execute e2fsck for the check. If it is necessary to check the root partition, enter single-user mode before executing.