e2fsck

From RaySoft

e2fsck is used to check a Linux second extended file system (ext2fs). e2fsck also supports ext2 filesystems containing a journal, which are also sometimes known as ext3 filesystems, by first applying the journal to the filesystem before continuing with normal e2fsck processing. After the journal has been applied, a filesystem will normally be marked as clean. Hence, for ext3 filesystem, e2fsck will normally run the journal and exit, unless its superblock indicates that further checking is required.[1]

Documentation

Syntax

e2fsck [PARAMETER ...] [DEVICE]

Parameters

-b SUPERBLOCK
Instead of using the normal superblock, use an alternative superblock specified by SUPERBLOCK. This option is normally 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.
-c
This option causes e2fsck to use badblocks program to do a read-only scan of the device in order to find any bad blocks. 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 this option is specified twice, then the bad block scan will be done using a non-destructive read-write test.
-l FILE
Add the block numbers listed in the file specified by FILE to the list of bad blocks. The format of this file is the same as the one generated by the badblocks program.
NOTE:
The block numbers are based on the blocksize of the filesystem. Hence, badblocks must be given the blocksize of the filesystem in order to obtain correct results. As a result, it is much simpler and safer to use the -c option to e2fsck, since it will assure that the correct parameters are passed to the badblocks program.
-p
Automatically repair ("preen") the file system. This option will case e2fsck to automatically fix any filesystem problems that can be safely fixed without human intervention. If e2fsck discovers a problem which may require the system administrator to take additional corrective action, e2fsck will print a description of the problem and then exit with the value 4 logically or'ed into the exit code.
-y
Assume an answer of 'yes' to all questions; allows e2fsck to be used non-interactively. This option may not be specified at the same time as the -n or -p options.

Examples

Backup the superblock
dumpe2fs '/dev/sda1' | grep 'Backup superblock'

Output:

dumpe2fs 1.41.9 (22-Aug-2009)
  Backup superblock at 8193, Group descriptors at 8194-8194
e2fsck -b 8193 '/dev/sda1'

References

  1. man 8 'e2fsck'