Linux "fsck.ext2" Command Line Options and Examples
check a Linux ext2/ext3/ext4 file system

e2fsck is used to check the ext2/ext3/ext4 family of file systems. For ext3 and ext4 filesystems that use a journal, if the system has been shut down uncleanly without any errors, normally, after replaying the committed transactions in the journal, the file sys‐ tem should be marked as clean.


Usage:

e2fsck [ -pacnyrdfkvtDFV ] [ -b superblock ] [ -B blocksize ] [ -l|-L bad_blocks_file ] [ -C fd ] [ -j external-journal ] [ -E
    extended_options ] [ -z undo_file ] device






Command Line Options:

-b
Instead of using the normal superblock, use an alternative superblock specified by superblock. This option is normally usedwhen the primary superblock has been corrupted. The location of backup superblocks is dependent on the filesystem's block‐size, the number of blocks per group, and features such as sparse_super.Additional backup superblocks can be determined by using the mke2fs program using the -n option to print out where thesuperblocks exist, supposing mke2fs is supplied with arguments that are consistent with the filesystem's layout (e.g. block‐size, blocks per group, sparse_super, etc.).If an alternative superblock is specified and the filesystem is not opened read-only, e2fsck will make sure that the primarysuperblock is updated appropriately upon completion of the filesystem check.
fsck.ext2 -b ...
-B
Normally, e2fsck will search for the superblock at various different block sizes in an attempt to find the appropriate blocksize. This search can be fooled in some cases. This option forces e2fsck to only try locating the superblock at a particularblocksize. If the superblock is not found, e2fsck will terminate with a fatal error.
fsck.ext2 -B ...
-d
Print debugging output (useless unless you are debugging e2fsck).
fsck.ext2 -d ...
-E
Set e2fsck extended options. Extended options are comma separated, and may take an argument using the equals ('=') sign. Thefollowing options are supported:ea_ver=extended_attribute_versionSet the version of the extended attribute blocks which e2fsck will require while checking the filesystem. Theversion number may be 1 or 2. The default extended attribute version format is 2.journal_onlyOnly replay the journal if required, but do not perform any further checks or repairs.fragcheckDuring pass 1, print a detailed report of any discontiguous blocks for files in the filesystem.discardAttempt to discard free blocks and unused inode blocks after the full filesystem check (discarding blocks is use‐ful on solid state devices and sparse / thin-provisioned storage). Note that discard is done in pass 5 AFTER thefilesystem has been fully checked and only if it does not contain recognizable errors. However there might becases where e2fsck does not fully recognize a problem and hence in this case this option may prevent you from fur‐ther manual data recovery.nodiscardDo not attempt to discard free blocks and unused inode blocks. This option is exactly the opposite of discardoption. This is set as default.no_optimize_extentsDo not offer to optimize the extent tree by eliminating unnecessary width or depth. This can also be enabled inthe options section of /etc/e2fsck.conf.optimize_extentsOffer to optimize the extent tree by eliminating unnecessary width or depth. This is the default unless otherwisespecified in /etc/e2fsck.conf.inode_count_fullmapTrade off using memory for speed when checking a file system with a large number of hard-linked files. The amountof memory required is proportional to the number of inodes in the file system. For large file systems, this canbe gigabytes of memory. (For example, a 40TB file system with 2.8 billion inodes will consume an additional 5.7GB memory if this optimization is enabled.) This optimization can also be enabled in the options section of/etc/e2fsck.conf.no_inode_count_fullmapDisable the inode_count_fullmap optimization. This is the default unless otherwise specified in /etc/e2fsck.conf.readahead_kbUse this many KiB of memory to pre-fetch metadata in the hopes of reducing e2fsck runtime. By default, this isset to the size of two block groups' inode tables (typically 4MiB on a regular ext4 filesystem); if this amount ismore than 1/50th of total physical memory, readahead is disabled. Set this to zero to disable readahead entirely.bmap2extentConvert block-mapped files to extent-mapped files.fixes_onlyOnly fix damaged metadata; do not optimize htree directories or compress extent trees. This option is incompati‐ble with the -D and -E bmap2extent options.
fsck.ext2 -E ...
-f
Force checking even if the file system seems clean.
fsck.ext2 -f ...
-F
Flush the filesystem device's buffer caches before beginning. Only really useful for doing e2fsck time trials.
fsck.ext2 -F ...
-j
Set the pathname where the external-journal for this filesystem can be found.
fsck.ext2 -j ...
-l
Add the block numbers listed in the file specified by filename to the list of bad blocks. The format of this file is the sameas the one generated by the badblocks(8) program. Note that the block numbers are based on the blocksize of the filesystem.Hence, badblocks(8) must be given the blocksize of the filesystem in order to obtain correct results. As a result, it is muchsimpler and safer to use the -c option to e2fsck, since it will assure that the correct parameters are passed to the badblocksprogram.
fsck.ext2 -l ...
-L
Set the bad blocks list to be the list of blocks specified by filename. (This option is the same as the -l option, except thebad blocks list is cleared before the blocks listed in the file are added to the bad blocks list.)
fsck.ext2 -L ...
-r
This option does nothing at all; it is provided only for backwards compatibility.
fsck.ext2 -r ...
-V
Print version information and exit.
fsck.ext2 -V ...
-z
Before overwriting a file system block, write the old contents of the block to an undo file. This undo file can be used withe2undo(8) to restore the old contents of the file system should something go wrong. If the empty string is passed as theundo_file argument, the undo file will be written to a file named e2fsck-device.e2undo in the directory specified via theE2FSPROGS_UNDO_DIR environment variable.WARNING: The undo file cannot be used to recover from a power or system crash.EXIT CODEThe exit code returned by e2fsck is the sum of the following conditions:
fsck.ext2 -z ...
-
File system errors corrected
fsck.ext2 - ...