Recovering Failed Filesystems

How do you know a filesystem is failing? Typically the certain clue is very slow writes, although you may also see errors at the command line and failures to mount. If your partition table is good but you can’t mount a particular partition, you may have a small write error, or you may have a disk flaw. If the latter, it’s all over for that partition; but if the former, it’s time for a disk check.

Back up the partition first. You’re likely to need to mount a spare hard drive or an external USB hard drive. We’ll assume you’ve mounted it to /mnt/rescue. Command:

dd if=/dev/hda1 of=/mnt/rescue/hda1.img

This assumes the first partition is the bad one; adjust as necessary. If you have to restore, you can command:

dd if=/mnt/rescue/hda1.img of=/dev/hda1

Now run the filesystem check program fsck. Command:

fsck /dev/hda1

You can force a filesystem-type check by specifying it like this:

fsck -t ext3 /dev/hda1 #assuming it’s an ext3 partition

or:

fsck /dev/hda1 — -f #to force filesystem-specific checks
# — passes subsequent arguments to the fs-specific check
# -f forces

Other options:

-c searches for bad blocks on the disk

-p forces automatic repair without asking for confirmation.

 

Time to boot from your distro installation CD. Then, in Red Hat/Fedora, when you get to the Welcome screen, command:

linux rescue

Then it’s time to make a filesystem on your hard disk, and restore a backup of your system’s contents. You did make backups, right?