Filesystem Check Options

The main fsck program supports several options, which it passes on to the filesystem-specific programs as necessary. Table 12.2 summarizes these options. You use these options in the following syntax:

fsck [options] [-t fstype] [device] [extra-options]

Table 12.2: Common fsck Options

fsck Option

Effect

-t fslist

Specify the type(s) of filesystem to be checked. You can check multiple filesystems with one command, so fslist can be a comma-separated list of filesystem types.

-A

Check every filesystem specified as one to be checked in /etc/fstab.

-R

Skip checking the root filesystem (used in conjunction with-A).

-C

Display a progress indicator for filesystems that support this option (currently only ext2fs and ext3fs).

extra-options

Options not recognized by fsck are passed on to the filesystem-specific programs.

Most of the interesting options are filesystem-specific. Some of the things you can specify for particular filesystems include:

Backup Superblocks The ext2 and ext3 filesystems use superblocks, which contain many vital filesystem details. Because the superblocks are so important, these filesystems store backup superblocks on the disk. If the main superblock is damaged, fsck.ext2 can use a backup whose location you specify with -b. You can learn the location of the backup superblocks by typing mke2fs -n /dev/f//e, where /dev/ff/e is the device file for the partition. Be sure to include the -n option or mke2fs will create a new filesystem, destroying the old one!

Detecting Bad Blocks You can have fsck.ext2 scan for physically bad sectors on the disk and mark them as such by passing it the -c option. Doubling up this option (that is, using -cc) performs a non-destructive read/write test, which may catch problems that a read-only test will miss.

Forcing a Check Normally, most fsck utilities perform only minimal checks if the filesystem is marked as clean. You can force a check with the fsck.ext2 and fsck.jfs utilities by passing them the -f option. In reiserfsck, the -check option causes it to check for errors but not correct them, while -fix-fixable causes it to automatically fix certain types of errors.

Journal Location To tell fsck.ext2, fsck.jfs, or reiserfsck where an external journal is located, pass the location with the -j journal-location parameter.

Minimizing User Interaction The -p option to fsck.ext2 and fsck.jfs minimizes the questions they ask. The -n and -y options tofsck.ext2 cause it to assume answers of no or yes, respectively, to all questions. (A no response causes fsck to not make changes to the filesystem.) The -s option to xfs_check causes it to report only serious errors. This option can make it easier to spot a problem that prevents mounting the filesystem when the filesystem also has less important problems.

Rebuilding the Superblock The reiserfsck program supports rebuilding the superblock by using the -rebuild-sb option.

Rebuilding the Filesystem Tree You can rebuild the entire tree of directories and files by using the -rebuild-tree option to reiserfsck. This option is potentially very risky, but it can fix major problems. Back up the partition using dd before using this option.

Omit Replaying the Journal The -o option to fsck.jfs causes the program to omit replaying the journal. This option is most useful when the journal itself has been corrupted.

You don't normally need to use fsck except when it runs into problems after a reboot. In that case, Linux may drop you into a maintenance shell and advise you to run fsck manually. Of course, you can run this utility at your discretion, as well, and doing so may be advisable if your disk access is acting up—if files are disappearing or if the disk appears to have too much or too little free space, for instance.

Warning Never run fsck on a filesystem that's mounted for read/write access. Doing so can confuse Linux and lead to more filesystem corruption. If necessary, shut down the system and boot from an emergency system to run fsck on an unmounted filesystem or to run on one that's mounted for read-only access.

Journaling Filesystems: Nota Panacea

Many people seem to think of journaling filesystems as protection against filesystem errors. This isn't their primary purpose, though. Journaling filesystems are designed to minimize filesystem check times after a crash or other severe error. Ext2fs has a good reputation as a reliable filesystem. Linux's journaling filesystems also have good reputations, but you shouldn't assume they're any safer than ext2fs.

Because journaling filesystems minimize system startup time after power outages, some people have taken to shutting off Linux systems that use journaling filesystems without shutting Linux down properly. This practice is risky at best. Linux still caches accesses to journaling filesystems, so data from recently written files may be lost if you power off the computer without shutting it down first. Always shut down the computer with the shutdown utility (or a program that calls it, such as a GUI login screen) before turning off the power.

Team LiB

Team LIB

^ previous

Was this article helpful?

0 0

Post a comment