fsck command is used to check perform consistency and repair Linux file systems. It is useful to repair corrupted file systems when system fails to boot, or a partition cannot be mounted. We will discuss about the fsck command in this article.
Make sure you are logged in with root or user with sudo privileges.
How to Use fsck
Following is the basic syntax of fsck command:
fsck [OPTIONS] [FILESYSTEM]
If you run the fsck command without any options, it will check the devices listed in the
It’s recommended to always unmount the mounted partitions before attempting to check or repair file systems. It may damage your mounted file systems.
fsck command accepts different options depending on the file system’s type. For example, to view the options available for
Repair Corrupted File System
It is a common use of the
fsck command to repair a non-root corrupted
ext4 file system.
1. Find the device name using
df or any other tool to find.
2. Unmount the device:
sudo umount /dev/sdc1
fsck to repair the file system:
sudo fsck -p /dev/sdc1
-p option is used to repair the problems automatically safely without user intervention.
4. When the file system is repaired, again mount the partition:
sudo mount /dev/sdc1
Repair Root File System
In the current running system
fsck command cannot check the root file system. You can set the
fsck to run on boot, or use a live disk.
You also can run
fsck command in recovery mode:
- Go to the boot menu and choose Advanced Options
- Select the Recovery mode and then “fsck”.
- Choose “Yes” when it prompt to remount the root file system.
- Once done, resume the normal boot.
fsck from a live distribution:
1. Boot the live distribution.
parted to find the root partition name.
3. Open the terminal and run:
sudo fsck -p /dev/sda1
4. Once done, reboot the live distribution and boot your system.
Check File Systems on Boot
Generally, all Linux distributions runs
fsck at boot time, if a file system is marked as dirty.
tune2fs tool to get the current mount count, check frequency number, check interval, and the time of the last check for a specific partition:
sudo tune2fs -l /dev/sdc1 | grep -i 'last checked|mount count'
Mount count: 392 Maximum mount count: -1 Last checked: Tue Oct 01 10:11:08 2019 Check interval: 0 (<none>)
Maximum mount count shows the number of mounts after which the filesystem will be checked. If the value is
-1 that means
fsck will never run.
Check interval is the maximal time between two filesystem checks.
For example, you want to run
fsck after every
15 boots or mounts, you would type:
sudo tune2fs -c 15 /dev/sdc1
You also can set the maximal time between two checks. For instance, to set two month run:
sudo tune2fs -i 2m /dev/sdc1
fsck to run at boot time on SystemD distributions pass the following kernel boot parameters:
fsck is a command-line tool for checking and repairing Linux file systems. Visit the fsck man page or type man
fsck in your terminal, to learn more about the
If you have any questions or feedback, feel free to leave a comment.