Fsck

Fsck
The system utility fsck (file system consistency check) is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux, macOS, and FreeBSD. The equivalent programs on MS-DOS and Microsoft Windows are CHKDSK, SFC, and SCANDISK.
Pronunciation
There is no agreed pronunciation. It can be pronounced "F-S-C-K", "F-S-check", "fizz-check", "F-sack", "fisk", "fizz-k", "fishcake", "fizik", "F-sick", "F-sock", "F-suck", "F-sek", "feshk", the sibilant "fsk", "fix", "farsk", "fosk" or "fusk".
Use
Generally, fsck is run either automatically at boot time, or manually by the system administrator. The command works directly on data structures stored on disk, which are internal and specific to the particular file system in use - so an fsck command tailored to the file system is generally required. The exact behaviors of various fsck implementations vary, but they typically follow a common order of internal operations and provide a common command-line interface to the user. On modern systems, fsck simply detects the type of filesystem and calls the specialized (Linux) or (BSD, macOS) program for each type.
Most fsck utilities provide options for either interactively repairing damaged file systems (the user must decide how to fix specific problems), automatically deciding how to fix specific problems (so the user does not have to answer any questions), or reviewing the problems that need to be resolved on a file system without actually fixing them. Partially recovered files where the original file name cannot be reconstructed are typically recovered to a "lost+found" directory that is stored at the root of the file system.
A system administrator can also run fsck manually if they believe there is a problem with the file system. The file system is normally checked while unmounted, mounted read-only, or with the system in a special maintenance mode.
Boot time
As boot time fsck is expected to run without user intervention, it generally defaults to not perform any destructive operations. This may be in the form of a read-only check (failing whenever issues are found), or more commonly, a "preen" mode that only fixes innocuous issues commonly found after an unclean shutdown (i.e. crash, power fail).
ext2/3/4 offers an option to force a boot-time check after a specified number of mounts, so that periodic checking can be done.
Some modern file systems do not require fsck to be at boot after an unclean shutdown. Some examples are:
XFS, a journaling file system. It has a dummy fsck which does nothing and an actual xfs_repair tool to be run when problems are suspected.
UFS2 file system in FreeBSD, which can delay the check to background if soft updates are enabled. As a result, it is usually not necessary to wait for fsck to finish before accessing the disk. This design is reflected by the flag used at boot.
ZFS and Btrfs, two full copy-on-write file systems. They avoid in-place changes to assure levels of consistency similar to a journal. They also provide a dummy fsck. btrfs-check is still available to check for suspected problems in filesystem structure (e.g. when a software bug or hardware issue is suspected).
Independent of checking the file system structure, modern file systems may offer a data scrubbing tool to check for silent corruption in stored data against a mirror or a checksum. Scrubs tend to be slow as they cover all data on a disk, but periodic runs can defend against data rot and help identify failing drives.
History
fsck first appeared in 4.0BSD of 1980. It turned into its modern wrapper form in NetBSD 1.3 (1998). fsck is not defined by any extant standard, but the primitive non-wrapper form is present in the 1995 draft Systems Management: File System and Scheduling Utilities (FSSU) from X/Open.
As an expletive
The severity of file system corruption led to the terms "fsck" and "fscked" becoming used among Unix system administrators as a minced oath for "fuck" and "fucked". It is unclear whether this usage was cause or effect, as a report from a question and answer session at USENIX 1998 claims that "fsck" originally had a different name:
Dennis Ritchie: "So fsck was originally called something else"
Question: "What was it called?"
Dennis Ritchie: "Well, the second letter was different"
"Go fsck yourself", is occasionally used online as an injunction to a person to go and correct their issue (attitude, ignorance of the subject matter, etc.) - in the same way that running fsck involves fixing fundamental errors.
Examples
The following example checks the file system configured to be mounted on /usr partition; the file system needs to be unmounted first:
fsck /usr
The following example checks the Linux JFS file system on a mdadm software RAID device:
fsck -t jfs /dev/md0
See also
List of Unix commands
List of file systems
e2fsprogs, which includes the e2fsck utility, standard on many Linux distributions
scrub, Oracle Solaris ZFS file system checking utility
References
External links
man fsck
Checking and Repairing File system with fsck
Jargon File entry: fscking
The many faces of fsck
Computer file systems
Hard disk software
Unix file system-related software