FSCK - check and repair a Linux file system
fsck must only be run on unmounted filesystems, never on mounted filesystems (with the exception of the read-only root during startup). This is because it accesses the raw disk, and can therefore modify the filesystem without the operating system realizing it. There will be trouble, if the operating system is confused. On a badly corrupted partition, you may need to run fsck several times to fix all the problems.
Copying the entire partition's data with dd as a backup prior to running fsck. For instance, typing dd if=/dev/sda5 of=/dev/ hda7 backs up the /dev/sda5 partition to /dev/hda7. You can then restore that image and try other options if fsck doesn't wo rk properly
if=FILE read from FILE instead of stdin of=FILE write to FILE instead of stdout
`noerror' Continue after read errors.
Method of file recovery is to use grep to search for text contained in the file.
# grep -a -B5 -A100 "The home journery" /dev/sda4 > recover.txt
the five lines before (-B5) and the 100 lines after (-A100) that string.
# grep -a -B5 -A100 "The home journery" /dev/sda4
Emergency recovery procedures.
# tar -xvf /dev/st0 home/al/election.txt^M
This command recovers the file home/al/election.txt from the /dev/st0 tape device.
During system startup, Linux examines the filesystem entry in /etc/fstab to determine whether to run fsck automatically. Specifically, the final field for a filesystem entry is a code specifying when to check the filesystem. A value of 0 means not to run fsck on startup. This setting is appropriate for non-Linux filesystems. The root (/) filesystem should normally have a value of 1, meaning that it's checked first. All other Linux native filesystems should normally have values of 2, meaning that they're checked after the root filesystem. Filesystem checks at boot time can cause problems in some distributions and with some journaling filesystems, though. Specifically, the filesystem check tool may slow down the bootup process because it unnecessarily forces a thorough disk check.
Journaling filesystems are designed to minimize filesystem check times after a crash or other severe error.
Improve rm's safety considerably by forcing it to confirm each deletion by using the -i option.For instance, the following line in ~/.bashrc or /etc/profile will set up such an alias for bash:
alias rm='rm -i'
Checking for disk errors with badblocks
It can be a good idea to periodically check for bad blocks. This is done with the badblocks command. It outputs a list of the numbers of all bad blocks it can find. This list can be fed to fsck to be recorded in the filesystem data structures so that the operating system won't try to use the bad blocks for storing data. The following example will show how this could be done.
$ badblocks /dev/fd0H1440 1440 >bad-blocks $ fsck -t ext2 -l bad-blocks /dev/fd0H1440 Parallelizing fsck version 0.5a (5-Apr-94) e2fsck 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10 Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Check reference counts. Pass 5: Checking group summary information. /dev/fd0H1440: ***** FILE SYSTEM WAS MODIFIED ***** /dev/fd0H1440: 11/360 files, 63/1440 blocks