e2fsck
Linux Commands - Troubleshooting

e2fsck

The e2fsck program is much the same as fsck; it is used to check a file system on a partition for consistency. When you format a disk partition in Linux, you set aside part of the disk for storing pointers that are used to locate the actual disk blocks that make up the files; these pointers are called inodes. The inodes and other important information about the files system including: the size of the files system, file system label and the number of inodes is stored in what is called the superblock. The superblock is so important that if it gets corrupted the rest of the files system is unavailable. However, because it is so valuable the superblock is duplicated every 8192 blocks. The first copy is at 8193, the second copy is at 16385. Now, if your first superblock is completely toast, you can still repair the file system by going to the second block.

 

Example: E2fsck -b -y 8193 /dev/hdc5

-b tells the program to use an alternative superblock.

-p Automatic repair with no questions.

-n Make no changes to the file system

-y Answer yes to all questions.

-c Check for bad blocks.

-f Force checking even if the file system is marked clean.

-v Give a lot of information, verbose.

 

fsck

The file system in Linux can become corrupted by many things including; turning the power off your computer before you shutdown Linux, a driver error, or even when the electricity goes off. When these things happen, the fsck program reports file inconsistencies.

 

fsck can only repair structural problems of the file system. When the fsck program finds errors it prompts you to repair them. With fsck you have the following options:

-p Preen - this performs automatic repairs that do not change the contents of files. Lost files are placed in the lost+found directory, files that are actually zero length are deleted, and missing blocks are placed back on the list of free blocks (blocks that data can be placed on).

-n This only lists the problems, and answers no to all prompts.

-y This answers yes to all prompts and repairs the damage regardless of severity.

-f This forces a file system check.