A file system consistency check (FSCK) is created to identify and check the errors and issues occurring in any file system of the operating system. This utility is mainly for Linux. It rectifies the errors and then delivers the reports. On the operating system, FSCK can be operated either automatically or normally. This tool is installed on Linux by default.
This article will explain the working of FSCK along with the tune2fs tool that is necessary to display the present state of the file system.
Why is a Health Checker Required?
An FSCK command is applied to a particular area of the folders or directory. So, we cannot rush for the consistency value without having any knowledge about the file system of the Linux operating system. It means before applying FSCK, one must have information regarding the directory or that file area that is facing a problem to maintain data inside it.
This information is provided by a filesystem health checker that is capable of maintaining the history of files and their issues. The health of the filesystem is checked through various tools that are utilized for numerous purposes respectively. A ‘tune2fs’ is used as a health tool.
Working of tune2fs
On Linux, the tune2fs tool allows the administrator to maintain the adjustment of various parameters of the filesystem on Linux having ext/ext3 filesystems. To change the default or the present value, we use the tune 2fs command with ‘-I’m in the command. Here, in this instance, we have a filesystem /dev/sda5/. The tool tune2fs will describe the time when the filesystem was checked the last time. The command will follow a sudo keyword and is accompanied by the grep keyword that will tell the last time the folder is opened, for the file system.
$ sudo tune2fs –l /dev/sda5 | grep Last\ c
First, the system will ask for the user’s password for verification. Then, the date and time combo according to the location will be displayed.
As in any operating system, a variety of file systems are working at a time. We have used a specific file system to be checked. To see all the list of file systems, we will use a simple command.
$ sudo fdisk -l
At the start, it will show the following description having several bytes, sectors, and units of the file system. Then, it will display the list of devices as file systems.
Besides providing the time the file system opened recently, the tool tune2fs is also used to provide information on how many times the file system is mounted or accessed.
$ sudo tune2fs -l /dev/sda5 | grep Mount
The resultant value shows that the file was mounted 7 times. Similarly, we can also check the number of times we are allowed to check the maximum number of mounts of a file system before we apply the forced FSCK.
$ sudo tune2fs -l /dev/sda5 | grep Max
In the directory, all the information regarding the root directory and also other important files are present. We can’t apply the reboot-forced FSCK directly on the desired folder. For instance, /dev/sda5 is the targeted folder. We need to create a partition to filter out the user-defined data from it.
The very first step that we are going to use is fetching the UUID of the partitioned file system by using a bkid command.
$ sudo blkid | grep sda5
By doing this, PARTUUID is obtained. The partitioned information is present in the folder /etc//fstab. So, the UUID will help ignore the other data and fetch the portioned information only.
$ sudo grep 097942b2-6c89-489f-9d54-1461c9ddcd23 /etc/fstab
This information is in the form of columns. The 6th column from the left in the output of the command is the pass column of FSCK. The value of this pass shows the order of the checking of the file system partitions. Let us describe the notations of the FSCK value and what they mean.
- If the FSCK pass column has 0 values, then it means that the check for the file system is disabled.
- FSCK pass column with 1 value implies the check has a higher priority for the file system it is associated with.
- Whereas, the FSCK pass column with 2 provides the checks of lowest priority for the file system they belong to. These types of file systems are checked last to save time for further processes.
To apply the FSCK check on the specified part of the portioned file system, we will create an empty file under a root directory of /forcefsck, so that it can perform the check on the root partition.
$ sudo touch /forcefsck
First, provide the user password. After authentication, a file will be created. You can verify the file created by using another command that will show the file names created under the directory /forcefsck.
$ sudo ls /forcefsck
Once the check is done, this file is removed. And after the removal, no check will be accomplished the next time the system is rebooted.
The below command will continue to execute the on-boot check of FSCK for the specified file system check.
$ sudo tune2fs –c 1 /dev/sda5
For the execution after every 10 system reboots, we use the below command of FSCK.
$ sudo tune2fs -c 10 /dev/sda5
This article aimed to explain the FSCK working on the file system on Linux operating system. First, we need to use a specific tool to check the health of a file system to identify all the errors the file system is facing. The whole process consists of several steps. The health tool tune2fs displays the number of times the folder is accessed and the last time it was opened. Furthermore, we have also explained the partition phenomenon to fetch the information, and the data related to the root directory remain intact.