Linux file systems are generally robust and work very well. But it can happen errors rarely. How can we check and fix these file system errors? Fsck is a check and repair utility for Linux file systems. Fsck can check and repair one or more file system. The file system can be a device or a mount point. If no file system is specified
/etc/fstab entries are checked serially.
List Mounts And File Systems
First, we will start by listing mounts and partitions. We can use different commands but in this case, we will use the
mount command without any options.
Check Device With Fsck
We will check a block device another name a disk with fsck
$ fsck.xfs /dev/vda1 If you wish to check the consistency of an XFS filesystem or repair a damaged filesystem, see xfs_repair(8).
Our file system in this example is xfs so there is another tool named xfs_repair.
$ sudo fsck.ext4 /dev/vda1 e2fsck 1.43.3 (04-Sep-2016) /dev/vda1 is mounted. e2fsck: Cannot continue, aborting.
As we see in this example we can not check the mounted file system. So we need to unmount and check the file system.
$ sudo fsck.ext4 /dev/vdb1 e2fsck 1.43.3 (04-Sep-2016) /dev/vdb1: clean, 11/65536 files, 8859/261888 blocks
We have check an unmounted file system like above named vdb1. It seems it is clean and no problem
Provide File System As Parameter
We can provide a file system as a parameter like below
$ fsck -t ext3 /dev/sa1
Accept All Question While Check
If there are a lot of errors fsck will ask you a lot of questions whether you want to correct the error. And every time we have to press yes to accept. We can provide -y to accept all questions.
$ fsck -y -t ext3 /dev/sa1