How
fsck works:
The fsck utility verifies all the links and blocks. It starts with the superblock, then moves on to the allocated disk blocks, pathnames, directories, link reference counts and the free blocks/inodes. This is usually done in five passes in UNIX. Note that in IRIX machines the xfs utility has replaced the fsck utility.
Every change in the filesystem affects the superblock in RAM. It is periodically written to the hard drive. If the superblock is corrupt, fsck will correct it. The superblock counts the free blocks and inodes.
The fsck utility runs in five passes or phases:
- Check blocks and inodes
The fsck utility checks the inode list for invalid entries. It compares the inode entries to the blocks that the actual files use.
- Check pathnames
The fsck utility removes directory entries discovered from bad inodes and looks for directories that have inode pointers that index out-of-range or point to bad inodes.
- Check connectivity
The fsck utility looks for unreferenced or orphaned directories. Should one be found, it is placed in the lost+found directory.
- Check reference counts
Using information from pass two and three, the fsck utility looks for unreferenced files and bad link counts.
- Check cylinder grouping
The last pass looks at the resulting free blocks and inode maps. It creates an updated map from the corrections made during pass one through four.
The fsck utility cannot fix everything, but it will let you know that there is a problem with any part of the file system. You may (often) need to perform data recovery yourself manually.