17.7 Checking and Repairing a File System

17.7.1 Changing the Frequency of File System Checking

The fsck utility checks and repairs file systems. For file systems other than / (root) and /boot, mount invokes file system checking if more than a certain number of mounts have occurred or more than 180 days have elapsed without checking having being performed. You might want to run fsck manually if a file system has not been checked for several months.

Warning

Running fsck on a mounted file system can corrupt the file system and cause data loss.

To check and repair a file system:

  1. Unmount the file system:

    # umount filesystem
  2. Use the fsck command to check the file system:

    # fsck [-y] filesystem

    filesystem be a device name, a mount point, or a label or UUID specifier, for example:

    # fsck UUID=ad8113d7-b279-4da8-b6e4-cfba045f66ff

    By default, fsck prompts you to choose whether it should apply a suggested repair to the file system. If you specify the -y option, fsck assumes a yes response to all such questions.

For the ext2, ext3, and ext4 file system types, other commands that are used to perform file system maintenance include dumpe2fs and debugfs. dumpe2fs prints super block and block group information for the file system on a specified device. debugfs is an interactive file system debugger that requires expert knowledge of the file system architecture. Similar commands exist for most file system types and also require expert knowledge.

For more information, see the fsck(8) manual page.

17.7.1 Changing the Frequency of File System Checking

To change the number of mounts before the system automatically checks the file system for consistency:

# tune2fs -c mount_count device

where device specifies the block device corresponding to the file system.

A mount_count of 0 or -1 disables automatic checking based on the number of mounts.

Tip

Specifying a different value of mount_count for each file system reduces the probability that the system checks all the file systems at the same time.

To specify the maximum interval between file system checks:

# tune2fs -i interval[unit] device

The unit can be d, w, or m for days, weeks, or months. The default unit is d for days. An interval of 0 disables checking that is based on the time that has elapsed since the last check. Even if the interval is exceeded, the file system is not checked until it is next mounted.

For more information, see the tune2fs(8) manual page.