Are you up for looking what is Fsck and how to use Fsck command in Linux? You are on the right spot to know the answer of this question.
Fsck is a very practical tool to check the “health” of your hard disk and also to solve many problems with partitions, with the partition table, etc.
Despite its age, it is a program with a lot of potential, so it is important to know how it is used, since it will be practical for you.
Table of Contents
What is Fsck?
Fsck is a command line program. Fsck stands for File System Check or File System Consistency Check. It is an old utility present in Unix-like operating systems such as Linux, macOS, Solaris, BSD, etc.
See Also: Where does the Hard Drive reliability Depend ON
It is used, as its name suggests, handling some physical errors and recovering information that is still readable from a hard drive or partition.
You can use it manually or automate its execution at the start of the operating system to detect any anomaly and try to solve it.
There is a DOS and Windows equivalent called CHKDSK or Check disk. This other command line program is also used to check the integrity of hard drives, and repair logical file system errors.
On Windows NT-based systems, you can also physically verify the integrity of bad disks, partitions, and sectors and try to recover information that is still readable.
How to Use Fsck Command in Linux
If you use the –help option of Fsck, you can see in the console the options that this command has and the basic syntax of use, which corresponds to:
-
Fsck -option /dev/sdXx
-Option being one or more of the available Fsck options and /dev/sdXx being the name of the hard drive or file system to check. As for the most used available options are:
- -A: Is the automatic option, checking all file systems, although it is not the recommended option.
- -C: Will show the progress bar.
- –l: Locks the device you are working with to guarantee exclusive access and avoid file corruption by other simultaneous uses.
- -M: Will not check mounted file systems, only unmounted ones.
- -N: Fsck is not run, it is just a simulation, showing what would happen if it were run. It can be a good test to see what happens when you are not very sure.
- -P: check file systems in parallel, also include the /o root.
- -r: Can be used with -A to skip checking the root or / file system.
- -s: will serialize the check operations.
- -T: Will not show the title during boot.
- -t: Followed by the type of file systems or FS you want to check.
- -V: It is the verbose mode, so that it shows on the screen information about what it is doing.
- –help: Show the help menu so you have it in mind.
- –version: Show the version of
In many cases, it is run without options, simply indicating the drive to check. Regarding the exit or exit code, you will see that a series of numbers appear that have the following meaning:
- 0 – No errors found.
- 1 – The bugs found have been fixed.
- 2 – The system should reboot.
- 4 – The errors found have been left uncorrected.
- 8 – Operational error.
- 16 – Usage or syntax error.
- 32 – Fsck canceled by user request.
- 128 – Shared library error.
Finally, also add that in Linux, Fsck can be used as is for any file system or a specific tool can be used for a specific one.
For example: fsck. ext2, fsck. ext3, fsck. ext4, … You can use the following command to list all the ones you have at your disposal:
cd /sbin
ls fsck*
If for some reason it is not available for the FS you want to use, Fsck will show an error like ” fsck: fsck. ntfs not found “.
Practical Examples of Use
If you prefer to see some practical examples of use, here are some examples that you can modify according to the name of your disk or file system to operate on it:
To see the names of the partitions and their numbering, you can use any of the following commands:
cat /etc/fstab
sudo fdisk -l
parted /dev/sda ‘print’
The next thing is to unmount the medium that you are going to analyze for security, for this, you can use:
- sudo umount /dev/sdc
Being /dev/sdc the name of the disk to unmount, although it may be the one you need in your case from the lists with the previous commands. Now that you know all this, you can already know how to use them with Fsck.
For example: Check a specific partition with fsck, to see if it has errors of any kind and to see if they can be fixed.
See Also: How to Clone a Hard Drive in Windows 11
You already know that it will give you a series of codes like the one listed above that you can interpret once the process is finished:
- sudo /dev/sda7
If you want to check all file systems that are listed in /etc/fstab, then you can use the -A option like so:
- sudo fsck -A
Same as above, but excluding root / from the test:
- sudo fsck -Ar -y
If you only wanted to parse one type of FS, for example ext4, then you can use this other command:
- sudo fsck -t ext4 -y
You could also parse all but one type of FS:
- sudo fsck -t noext4 -y
It will not check mounted systems:
- sudo fsck -M /dev/sda
Force check:
- sudo fsck -f /dev/sda
Report bugs but don’t fix them:
- sudo fsck -n /dev/sda
Automatically repair what is broken:
- sudo fsck -a /dev/sda8
As you can see, it’s easy to use if you know the basic fsck options. Now, with this tutorial you will be able to apply it in practice to save your file systems and hard drives from logical or physical failures that they may have.
Zahid Khan Jadoon is an Interior Decorator, Designer and a specialized Chef and loves to write about home appliances and food. Right now he is running his interior designing business along with a managing a restaurant. Also in his spare time he loves to write about home and kitchen appliances.