fsck command

Purpose

Checks file system consistency and interactively repairs the file system.

Syntax

fsck [ FileSystem ... ]

Description

The fsck command checks and interactively repairs inconsistent file systems. Normally, the file system is consistent, and the fsck command merely reports on the number of files, used blocks, and free blocks in the file system. If the file system is inconsistent, the fsck command displays information about the inconsistencies found and prompts you for permission to repair them. If no FileSystem is specified, all file systems are checked.

The fsck command checks for the following inconsistencies:
  • Blocks or fragments allocated to multiple files.
  • inodes containing block or fragment numbers that overlap.
  • inodes containing block or fragment numbers out of range.
  • Discrepancies between the number of directory references to a file and the link count of the file.
  • Illegally allocated blocks or fragments.
  • inodes containing block or fragment numbers that are marked free in the disk map.
  • inodes containing corrupt block or fragment numbers.
  • A fragment that is not the last disk address in an inode. This check does not apply to compressed file systems.
  • Files larger than 32KB containing a fragment. This check does not apply to compressed file systems.
  • Size checks:
    • Incorrect number of blocks.
    • Directory size not a multiple of 512 bytes.
    Note: These checks do not apply to compressed file systems.
  • Directory checks:
    • Directory entry containing an inode number marked free in the inode map.
    • inode number out of range.
    • Dot (.) link missing or not pointing to itself.
    • Dot dot (..) link missing or not pointing to the parent directory.
    • Files that are not referenced or directories that are not reachable.
  • Inconsistent disk map.
  • Inconsistent inode map.
In addition to its messages, the fsck command records the outcome of its checks and repairs through its exit value. This exit value can be any sum of the following conditions:
Value Description
0 All checked file systems are now okay.
2 The fsck command was interrupted before it could complete checks or repairs.
4 The fsck command changed the file system; the user must restart the system immediately.
8 The file system contains unrepaired damage.

Examples

  1. To check a file system, enter:
    fsck /dev/hd1
    This command checks the unmounted file system located on the /dev/hd1 device.



Last updated: Wed, November 18, 2020