Wednesday, January 31, 2018

Check Linux filesystem for errors: FSCK command with examples

FSCK is a very important Linux/Unix utility, it is
used to check & repair the errors in the file system. It is similar
to ‘chkdsk’ utility in Windows operating systems. It is available for
Linux, MacOS, FreeBSD operating systems.

FSCK
stands for File System Consistency Check & most of the times, it
runs at boot time but can also be started manually by super user, if
need arises.

It can be used with 3 modes of operation,

1- Check for errors & let the user decide what should be done with each error,

2- Check for errors & make repairs automatically, or,

3- Check for errors & display the error but does not perform any repairs.

We
can use any of the following options, depending on the operation we
need to perform. Let’s discuss some of the options of fsck command with
examples.

Fsck command with examples

Note:- Before
we discuss any examples, please read this. We should not be using FSCK
on mounted drives, as there will be high chances that fsck on mounted
drive wll damage the drive permanently. So before performing fsck, we
must un-mount the drive with the following command,

$ umount drivename

For example,

$ umount /dev/sdb1

You can check the partition number with the following command,

$ fdisk -l

Also
while running the fsck, we might get some error codes. Below mentioned
is the list of error codes that we might get along with their meanings,