fsck is a Unix utility for checking and repairing file system inconsistencies . File system can become inconsistent due to several reasons and the most common is abnormal shutdown due to hardware failure , power failure or switching off the system without proper shutdown . Due to these reasons the superblock in a file system is not updated and has mismatched information relating to system data blocks, free blocks and inodes .
Modes of operation :
fsck operates in two modes interactive and non interactive :
interactive : the fsck examines the file system and stops at each error it finds in the file system and gives the problem description and ask for user response usually whether to correct the problem or continue without making any change to the file system.
noninteractive :fsck tries to repair all the problems it finds in a file system without stopping for user response useful in case of a large number of inconsistencies in a file system but has the disadvantage of removing some useful files which are detected to be corrupt .
If file system is found to have problem at the booting time non interactive fsck fsck is run and all errors which are considered safe to correct are corrected. But if still file system has problems the system boots in single user mode asking for user to manually run the fsck to correct the problems in file system
Running fsck :
fsck should always be run in a single user mode which ensures proper repair of file system . If it is run in a busy system where the file system is changing constantly fsck may see the changes as inconsistencies and may corrupt the file system .
if the system can not be brought in a single user mode fsck should be run on the partitions ,other than root & usr , after unmounting them . Root & usr partitions can not be unmounted . If the system fails to come up due to root/usr files system corruption the system can booted with CD and root/usr partitions can be repaired using fsck.
command syntax:
fsck [ -F fstype] [-V] [-yY] [-o options] special
-F fstype type of file system to be repaired ( ufs , vxfs etc)
-V verify the command line syntax but do not run the command
-y or -Y Run the command in non interactive mode - repair all errors encountered without waiting for user response.
-o options Three options can be specified with -o flag
b=n where n is the number of next super block if primary super block is corrupted in a file system .
p option used to make safe repair options during the booting process.
f force the file system check regardless of its clean flag.
special - Block or character device name of the file system to be checked/repaired - for example /dev/rdsk/c0t3d0s4 .Character device should be used for consistencies check & repair
phases:
fsck checks the file system in a series of 5 pages and checks a specific functionality of file system in each phase.
** phase 1 - Check Blocks and Sizes
** phase 2 - Check Pathnames
** phase 3 - Check Connectivity
** phase 4 - Check Reference Counts
** phase 5 - Check Cylinder Groups
2fsck
e2fsck [options] device fsck.ext2 [options] device
System administration command. Checks and repairs a disk, as does fsck, but specifically designed for ext2 (Linux Second Extended) and ext3 (Third Extended, a journaling version of ext2) filesystems. fsck actually uses this command when checking ext2 and ext3 filesystems. Most often used after a sudden shutdown, such as from a power outage, or when damage to the disk is suspected.
Options
-b superblock
Use superblock instead of the default superblock.
-c
Find bad blocks using the badblocks command. Specify this option twice to perform the scan with a nondestructive read-write test.
-d
Debugging mode.
-f
Force checking, even if kernel has already marked the filesystem as valid. e2fsck will normally exit without checking if the system appears to be clean.
-j file
Use the specified external journal file.
-k
Preserve all previously marked bad blocks when using the -c option.
-l file
Consult file for a list of bad blocks, in addition to checking for others.
-n
Ensure that no changes are made to the filesystem. When queried, answer “no.”
-p
“Preen.” Repair all bad blocks noninteractively.
-s
Byte-swap the filesystem if necessary to standard (little-endian) byte-order.
-t
Display timing statistics.
-v
Verbose.
-y
When queried, answer “yes.”
-B size
Expect to find the superblock at size; if it’s not there, exit.
-C filedescriptor
Write completion information to the specified filedescriptor. If 0, print a completion bar.
-D
Optimize directories by reindexing, sorting, and compressing them where possible.
-F
Flush buffer caches before checking.
-L file
Consult file for list of bad blocks instead of checking filesystem for them.
-S
Byte-swap the filesystem.