File System Checking with fsck

The system utility fsck (for “file system check” or “file system consistency check”) is a tool for checking the consistency of a file system in the Unix system and clones thereof.

Generally, fsck is run automatically at boot time when the system detects that a file system is in an inconsistent state, indicating a non-graceful shutdown, such as a crash or power loss. Typically, fsck utilities provide options for either interactively repairing damaged file systems (the user must decide how to fix specific problems), automatically deciding how to fix specific problems (so the user doesn’t have to answer any questions), or reviewing the problems that need to be resolved on a file system without actually fixing them.

Fsck can also be run manually by the root account if there is believed to be a problem with the file system. However, running fsck on a mounted file system can potentially cause severe data corruption/loss.

If you have a corrupt file system ( Ext2/3 ) and you have to do a manual check and repair on it here are several ways to accomplish that. First thing first the drive should not be mounted so you’ll need to do one of several things, you can boot into single user mode (init 1), you can access your discs with a live disc (I suggest Knoppix), or if it’s just a secondary hard-drive just umount the drive or make sure it’s mounted in read-only mode (mount -o remount,ro /dev/hdb1 /mnt/point/ ).

Now you simply run:

fsck /dev/hdb1

Where hdb1 is the drive/partition you need to repair.

Then remount the drive normally and boot back into the computer and you’re drive should be repaired but there is no guarantee.
The chance that you will have to do this are much slimmer on an Ext3 file system then on Ext2. So there is one more reason you always choose an Ext3 format

AUTO FSCK

Auto fsck is only relevant to the Ext2 file system and not meant for journaled filesystems such as Ext3.

You probably know already that every 20 to 30 times you reboot your system, or after each un-clean shutdown, you will get a check of the integrity of your file system.

Also you might have seen on the screen as the system files are checked that you have to hit the Y button within 5 seconds . . . . now, 5 seconds is very short and the chances are you will be just too late. The system will continue booting, but if there are problems with the integrity, you have a problem. So most of the time at a file check I had my finger close to the Y button, not anymore.
I did a few little tweaks:

Open the file ¨/etc/sysconfig/autofsck¨ in the text editor of your choice (as root):

you will see two lines, the first one we’re looking for:

AUTOFSCK_TIMEOUT=5

Here you can change the length of the timeout seconds.

AUTOFSCK_DEF_CHECK=no

change the value to yes and it will hit the Y for you

Save the file

If there is no such file as ¨/etc/sysconfig/autofsck¨, just make it.

Also See: Howto check disk drive for errors and badblocks

Related Posts

Tags: ,

Leave a Reply

You must be logged in to post a comment.