e2fsck

check a Linux ext2/ext3/ext4 file system

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

This is terse version without explainations, see the man page for the truth.(ed)

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) after replaying the committed transactions in the journal, the file system is marked as clean.

For filesystems that use journalling, replay the journal and exit, unless its superblock indicates that further checking is required.

device is a block device (e.g., /dev/sdc1) or file containing the file system.

It is not safe to run on mounted filesystems unless -n(no changes) is specified, ,and -c, -l, or -L are not specified.

If run in interactive mode (meaning that none of -y, -n, or -p are specified), asks the user to fix each problem found in the filesystem.
A response of 'a' will fix the problem and all subsequent problems;
Enter will proceed with the default response, which is output before the question mark.
Control-C terminates immediately.

-n No changes. Open the filesystem read-only, and assume an answer of `no' to all questions.
May not be specified with -p or -y
-v Verbose mode.
-f Force checking even if the file system seems clean.
-b superblock use an alternative superblock . used when the primary superblock has been corrupted.
The location of the backup superblock is dependent on the filesystem's blocksize.
For filesystems with 1k blocksizes, a backup superblock can be found at block 8193;
for filesystems with 2k blocksizes, at block 16384; and for 4k blocksizes, at block 32768.
Additional backup superblocks can be determined by using mke2fs using -n to display where the superblocks were created.
The -b option to mke2fs, which specifies blocksize of the filesystem must be specified in order for the superblock locations that are printed out to be accurate.

If an alternative superblock is specified and the filesystem is not opened read-only, e2fsck will make sure that the primary superblock is updated appropriately upon completion of the filesystem check.

-B blocksize only locate the superblock at a particular blocksize.
-c check for BadBlocks. use badblocks(8) program to scan the device .
If any bad blocks are found, they are added to the bad block inode to prevent them from being allocated to a file or directory.
If specified twice, then the bad block scan will be done using a non-destructive read-write test.
-C fd write information to the specified file descriptor so that the progress of the filesystem check can be monitored. used by programs which call e2fsck.
If the fd is negative, the absolute value is used and the progress information will be suppressed initially.
It can be enabled by sending e2fsck SIGUSR1 .
If the 0, outputs a completion bar
-D Optimize directories Not very useful
-E extended_options extended options are comma separated, and may take an argument using the equals ('=') sign.
ea_ver= 1|2 Set the version of the extended attribute blocks which required while checking the filesystem. default 2.
journal_only Only replay the journal if required, but do not perform any further checks or repairs.
fragcheck Output detailed report of discontiguous blocks for files
discard discard free blocks and unused inode blocks after the full filesystem check
nodiscard Do not attempt to discard free blocks and unused inode blocks. default.
readahead kb pre-fetch metadata to reducing runtime. By default, two block groups inode tables (typically 4MiB on a regular ext4 filesystem);
if this amount is more than 2% of total physical memory, readahead is disabled.
zero to disable readahead
bmap2extent Convert block-mapped files to extent-mapped files.
fixes_only Only fix damaged metadata; do not optimize htree directories or compress extent trees, incompatible with the -D and -E bmap2extent options.
-j external-journal pathname of the external-journal
-k with -c existing bad blocks in the bad blocks list are preserved and new bad blocks from badblocks(8) are added
-l filename Add the block numbers filename to the list of bad blocks.
The format is the same as the one generated by badblocks(8) .
-L filename Set the bad blocks list to be the list specified by filename
-p Automatically repair ("preen") the file system. fix any filesystem problems that can be safely fixed without intervention.
If a problem which may require additional action is envcountered, print a description of the problem and then exit with the value 4 logically or'ed into the exit code. (See the EXIT CODE section.) normally used by the system's boot scripts. It may not be specified at the same time as the -n or -y options.
-t timing statistics If used twice, additional timing statistics are output
-V Print version information and exit.
-y Assume an answer of `yes' to all questions; allows e2fsck to be used non-interactively. may not be specified at the same time as the -n or -p options.
-z undo_file Before overwriting a file system block, write the old contents of the block to an undo file. This undo file can be used with e2undo(8) to restore the old contents of the file system should something go wrong. If the empty string is passed as the undo_file argument, the undo file will be written to a file named e2fsck-device.e2undo in the directory specified via the E2FSPROGS_UNDO_DIR environment variable. WARNING: The undo file cannot be used to recover from a power or system crash. OPTIONS

EXIT CODE

0 No errors
1 File system errors corrected
2 File system errors corrected, system should be rebooted
4 File system errors left uncorrected
8 Operational error
16 Usage or syntax error
32 E2fsck canceled by user request
128 Shared library error

Example from Raspberry pi buster 2/11/20:

sudo fsck -n /dev/mmcblk0p2
fsck from util-linux 2.33.1
e2fsck 1.44.5 (15-Dec-2018)
Warning!  /dev/mmcblk0p2 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
rootfs: clean, 61291/346064 files, 639971/1408000 blocks

SIGNALS

Cause e2fsck to start displaying a completion bar or emitting progress information. (See discussion of the -C option.) SIGUSR1 Cause e2fsck to stop displaying a completion bar or emitting progress information. SIGUSR2

See

e2fsck.conf(5), badblocks(8), dumpe2fs, debugfs(8), e2image(8), mke2fs(8), tune2fs(8)