filesystem consistency check and repair

fsck [-p][-f] [-m mode]

fsck [-b superBlockNumber ] [-c level] [-l maxparallel] [-q] [-y | -n ] [-m mode]

See Disk Utility for running on individual volumes.

During boot, /etc/rc ( launchd on Mac OS ) specifies filesystems to be checked.
In addition the filesystems in /etc/fstab which are not marked clean are checked.
(Filesystems are marked clean when they are unmounted (as in shutdown), have been mounted read-only, or when fsck runs on them successfully).

There is a unique fsck for each type of file system,( example: fsck_hfs ) and the actions and options vary.

Other inconsistencies, cause an exit with abnormal return status and an automatic boot fails.

During processing, the filesystem, the corrective action, and the nature of the correction are displayed.
After successfully correcting a filesystem, fsck displays the number of files on that filesystem, the number of used and free blocks, and the percentage of fragmentation.

If sent a QUIT signal, fsck completes the checks then exits with an abnormal return status which causes boot to fail, prevents starting multiuser mode.

Without -p, fsck audits and interactively repairs inconsistent conditions. The user is prompted for permission before each correction is attempted (unless -y or -n is specified).
Some of the corrective actions , not correctable under -p, will result in some loss of data.
The amount and severity of data lost is displayed .
If the user does not have write permission on the filesystem no action is taken.

-p preen
-f Force ie include clean filesystems when preening.
-m rwxrwxrwx Permissions for lost+found directory if created rather than 1777 which is a security risk, 700 is suggested.
‑b alt‑super‑block  Block 32 is usually an alternate super block.
-l p Limit the number of parallel checks. By default, the limit is the number of disks, one process per disk. If a smaller limit is given, the disks are checked round-robin, one filesystem at a time.
-q quickly determine if filesystem was unmounted cleanly.
-y Supply a yes response to all questions ; this should be used with great caution
-n Supply a no response to all questions except for CONTINUE?, which is assumed to be affirmative;
Do not open the filesystem for writing.
-c level Convert the filesystem to a higher level.
  1. 0 old (static table) format.
  2. 1 new (dynamic table) format.
  3. 2 supports 32-bit uid's and gid's, short symbolic links are stored in the inode, and directories have an added field showing the file type.
  4. 3 If maxcontig is greater than one, build the free segment maps to aid in finding contiguous sets of blocks.
    If maxcontig is equal to one, delete any existing segment maps.
In interactive mode, fsck will list the conversion to be made and ask whether the conversion should be done.
If a negative answer is given, no further operations are done on the filesystem.
In preen mode, the conversion is listed and done if possible without user interaction. Conversion in preen mode is best used when all the filesystems are being converted at once. The format of a filesystem can be determined from the first line of output from dumpfs(8).
If no filesystems are specified filesystems as per /etc/fstab. The raw device should always be used.


/etc/fstab contains default list of filesystems to check.

see fs(5), fstab(5), newfs(8), reboot(8)