Hack 57 Repair Damaged Filesystems

 < Day Day Up > 

figs/moderate.gif figs/hack57.gif

Benefit from utilities included with Knoppix to repair corrupted filesystems, including ext2, ext3, ReiserFS, and XFS .

Whether it's due to a system that has lost power due to a UPS, a bad IDE cable, an IDE bus error, or some other bug, filesystems are sometimes damaged and must be repaired. Most filesystem-repair utilities require that the partition to be repaired is not mounted, and for repairs to the / partition, it is necessary to use a repair disc such as Knoppix. One advantage to using Knoppix for filesystem repair is that it includes tools to scan and repair all of the major filesystems under Linux on a single CD, in addition to tools to check MSDOS partitions for consistency. Besides, a filesystem check on a 100-GB ext2 partition can take quite some time, and Knoppix has a complete system full of other tools to pass the time while the filesystem check finishes.

The primary tool used to check and repair filesystems under Linux is fsck (short for FileSystem ChecK). If the power goes out while you are running a Linux system on an ext2 filesystem or a system freezes before you can unmount a filesystem, this tool comes up and checks the filesystem on the next boot. If an ext2 filesystem has a lot of corruption or is the root partition, you might be prompted to boot into single- user mode (or boot onto a rescue CD) and run a complete fsck from there on the unmounted filesystem. The fsck tool is actually a frontend to many filesystem-specific repair tools located in /sbin named fsck. filesystem . When you run fsck on a filesystem, it attempts to guess the filesystem and run the appropriate tool. By default, most fsck programs scan through the filesystem for consistency errors, and if any are found, it prompts you before it attempts to repair them.

For all of the following examples, be sure that the filesystem you are scanning is not mounted. You must always run fsck under sudo in Knoppix, because the filesystems require root permissions to modify anything.

6.7.1 Ext2/Ext3

For ext2 and ext3 filesystems, the filesystem repair tool is fsck.ext2 or e2fsck . To scan and repair a filesystem, simply run:

 knoppix@ttyp0[knoppix]$  sudo fsck  /dev/hda    1  

Replace /dev/hda1 with the partition you want to scan. If you want a nifty progress bar, add a -C option. If there are multiple filesystems you want to check, you can list them one after another on the command line.

6.7.2 ReiserFS

ReiserFS filesystems are repaired using the fsck.reiserfs or reiserfsck tools. Reiserfsck performs many levels of filesystem checking and repairing, and reports different error codes based on the problem at hand. First, check the filesystem for errors with the following command:

 knoppix@ttyp0[knoppix]$  sudo reiserfsck --check  /dev/hda1   

Replace /dev/hda1 with the partition you want to scan. By default, reiserfsck outputs all progress to STDERR (you should see the output on the console), but if you want it to output to a file instead, use the --logfile option. If reiserfsck exits with a status of 0, then it hasn't discovered any errors. If it exits with a status of 1 and reports that there are fixable corruptions, then the next step is to fix those corruptions with the following command:

 knoppix@ttyp0[knoppix]$  sudo reiserfsck --fix-fixable  /dev/hda1   

Otherwise, if reiserfsck reports fatal corruptions and exits with a status of 2, then you must make a backup of the complete partition, if possible, with dd or another tool [Hack #48] . Then cross your fingers, and attempt to rebuild the entire filesystem with this command:

 knoppix@ttyp0[knoppix]$  sudo reiserfsck --rebuild-tree  /dev/hda1   

It is important that you do not interrupt the rebuild process. If you do interrupt it, the filesystem remains in an unmountable state until you finish rebuilding the tree.

6.7.3 XFS

Like ReiserFS, XFS comes with its own set of filesystem check and recovery tools. XFS uses xfs_check and xfs_repair for these tasks . To check an XFS filesystem for inconsistency, run:

 knoppix@ttyp0[knoppix]$  sudo xfs_check  /dev/hda1   

Replace /dev/hda1 with your partition. Xfs_check generates output that indicates that it has found inconsistencies on the filesystem that must be repaired. To repair the filesystem, run:

 knoppix@ttyp0[knoppix]$  sudo xfs_repair  /dev/hda1   

The xfs_repair utility outputs information about the repairs it is making, but does not prompt you to approve any of the changes, so be sure you have backed up any important files before running the repair, just in case. The xfs_check manpage also lists xfsdump and xfsrestore to move the filesystem to a newly created XFS partition in lieu of the in-place repair that xfs_repair performs.

While I have listed the primary methods you should use to check and repair a filesystem with Knoppix, there are also many other filesystem-specific options you can pass to these programs to suit a particular error your filesystem might have. Each of these programs has in-depth manpages accessible on the Knoppix CD. To list options and standard usage, run:

 knoppix@ttyp0[knoppix]$  man  programname   

Some of the more sophisticated filesystems, particularly XFS, have many unique options that are worth referencing, as they differ from fsck .

6.7.4 See Also

  • The fsck manpage by typing man fsck in a console.

 < Day Day Up > 


Knoppix Hacks. 100 Tips and Tricks
Knoppix Hacks. 100 Tips and Tricks
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net