The fsck
command is a file system utility that checks the integrity of a file system and attempts to repair any errors it finds. It can be used to check and repair a file system on a hard disk, USB drive, or any other storage device that uses a file system that is supported by Linux. fsck
can be run on a mounted file system, but it is recommended to run it on an unmounted file system to minimize the risk of data loss.
Syntax
fsck [options] [device]
Examples
To check and repair a file system on the /dev/sda1
partition, run the following command:
fsck /dev/sda1
To automatically repair any errors found during the file system check, use the -a
option:
fsck -a /dev/sda1
To force a file system check even if it appears clean, use the -f
option:
fsck -f /dev/sda1
Options
The following table lists the available options for the fsck
command:
Option | Description |
---|---|
-a |
Automatically repair any errors found during the file system check. |
-V |
Display verbose output. |
-f |
Force a file system check even if it appears clean. |
-n |
Do not make any changes to the file system. |
-p |
Automatically repair any errors found during the file system check without prompting the user. |
-r |
Interactively repair any errors found during the file system check. |
-t |
Specify the file system type. |
Troubleshooting Tips
- If
fsck
reports errors that it cannot repair, it may be necessary to manually repair the file system or restore data from a backup. - Running
fsck
on a mounted file system can cause data loss or corruption. Always unmount the file system before runningfsck
. - If
fsck
reports that it cannot repair a file system, it may be necessary to run it in rescue mode or from a live CD to repair the file system.
Notes
- The
fsck
command is usually run automatically during system boot to check and repair any errors in the file system. fsck
can be used to check and repair a variety of file systems, including ext2, ext3, ext4, XFS, and ReiserFS.