The system utility
fsck
(''file system check'') is a tool for checking the consistency of a
file system in
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems, such as
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
,
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, and
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
.
[ "In actuality, fsck is simply a front-end for the various filesystem checkers (fsck.fstype) available under Linux."] The equivalent programs on
MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
and
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
are
CHKDSK
In computing, CHKDSK (short for "check disk") is a system software, system tool and command (computing), command in DOS and Microsoft Windows (and related operating systems), as well as Digital Research FlexOS, IBM/Toshiba 4690 Operating System, 4 ...
,
SFC, and
SCANDISK.
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.
[ "It was reimplemented as a filesystem independent wrapper in NetBSD 1.3 and first appeared in FreeBSD 5.0."]
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
An IT administrator, system administrator, sysadmin, or admin is a person who is responsible for the upkeep, configuration, and reliable operation of computer systems, especially multi-user computers, such as Server (computing), servers. The ...
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 at 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
XFS is a high-performance 64-bit journaling file system created by Silicon Graphics, Inc (SGI) in 1993. It was the default file system in SGI's IRIX operating system starting with its version 5.3. XFS was ported to the Linux kernel in 2001; a ...
, a journaling file system
A journaling file system is a file system that keeps track of changes not yet committed to the file system's main part by recording the goal of such changes in a data structure known as a " journal", which is usually a circular log. In the ev ...
. 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
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
, which can delay the check to background if soft updates
Soft updates is an approach to maintaining file system metadata integrity in the event of a crash or power outage. Soft updates work by tracking and enforcing dependencies among updates to file system metadata. Soft updates are an alternative t ...
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
ZFS (previously Zettabyte File System) is a file system with Volume manager, volume management capabilities. It began as part of the Sun Microsystems Solaris (operating system), Solaris operating system in 2001. Large parts of Solaris, includin ...
and Btrfs
Btrfs (pronounced as "better F S", "butter F S", "b-tree F S", or "B.T.R.F.S.") is a computer storage format that combines a file system based on the copy-on-write (COW) principle with a logical volume manager (distinct from Linux's LVM), d ...
, two full copy-on-write
Copy-on-write (COW), also called implicit sharing or shadowing, is a resource-management technique used in programming to manage shared data efficiently. Instead of copying data right away when multiple programs use it, the same data is shared ...
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
Data scrubbing is an error correction technique that uses a background task to periodically inspect main memory or storage for errors, then corrects detected errors using redundant data in the form of different checksums or copies of data. Data ...
tool to check for silent corruption in stored data against a mirror or a checksum
A checksum is a small-sized block of data derived from another block of digital data for the purpose of detecting errors that may have been introduced during its transmission or storage. By themselves, checksums are often used to verify dat ...
. 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 the Bell Labs "V7 addendum tape" 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 X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of info ...
.
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
A minced oath is a euphemistic expression formed by deliberately misspelling, mispronouncing, or replacing a part of a profane, blasphemous, or taboo word or phrase to reduce the original term's objectionable characteristics. An example is "gosh ...
for "fuck
''Fuck'' () is profanity in the English language that often refers to the act of sexual intercourse, but is also commonly used as an intensifier or to convey disdain. While its origin is obscure, it is usually considered to be first attested ...
" and "fucked". It is unclear whether this usage was cause or effect, as a report from a question and answer session at USENIX
USENIX is an American 501(c)(3) nonprofit membership organization based in Berkeley, California and founded in 1975 that supports advanced computing systems, operating system (OS), and computer networking research. It organizes several confe ...
1998 claims that "fsck" originally had a different name:
:Dennis Ritchie
Dennis MacAlistair Ritchie (September 9, 1941 – October 12, 2011) was an American computer scientist. He created the C programming language and the Unix operating system and B language with long-time colleague Ken Thompson. Ritchie and Thomp ...
: ''"So fsck was originally called something else"''
:Question: ''"What was it called?"''
:Dennis Ritchie: ''"Well, the second letter was different"''
That story has been confirmed by Rob Pike
Robert Pike (born 1956) is a Canadian programmer and author.
He is best known for his work on the Go programming language while working at Google
and the Plan 9 operating system while working at Bell Labs, where he was a member of the Unix t ...
on the Mastodon social network on December 17, 2023:
"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
RAID (; redundant array of inexpensive disks or redundant array of independent disks) is a data storage virtualization technology that combines multiple physical Computer data storage, data storage components into one or more logical units for th ...
device:
fsck -t jfs /dev/md0
See also
*List of Unix commands
This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...
* 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
The many faces of fsck
{{Unix commands
Computer file systems
Hard disk software
Unix file system-related software