About Linux FSCK ( FILE SYSTEM CONSISTENCY CHECK )

Posted at November 11, 2016 at 1:00 pm by Jithin

The FSCK is a system utility. It is a tool that is used to check the consistency of a file system in the Unix-like operating systems. It is a tool that will check and repair inconsistencies in Unix-like systems including Linux. The tool can be used with the help of ‘fsck’ command in Linux. This is equivalent to the ‘CHKDSK’ in the Microsoft Windows. In this article, we are going to see the fsck tool in detail.

 

File Inconsistency

We’ve already seen that the fsck will repair the inconsistencies.  File inconsistency is a state that represents structural inconsistency within a certain group of a file. These are actually exceptions. The file inconsistencies can be usually caused by the following situations.

1) An unexpected system shutdown.

2) Clearing group locks improperly.

3) Overriding the built-in file protection mechanisms.

4) System debugger when used incorrectly.

These are the common causes of the file inconsistency. Let’s see each one in detail.

 

Unexpected System Shutdown

There can be cases that the computer will be shut down unexpectedly. Suppose there was a system crash or unexpected power outage and your system has been shut down unexpectedly, then file inconsistency may occur.

 

Clearing group locks improperly

Suppose there are two process that modifying internal structures simultaneously and each process is unaware of other. Such a situation will bring  file inconsistency. If you clear the group locks indiscriminately, this situation can be occurr.

 

Overriding the built-in file protection mechanisms

Overriding built in file protections when using delete-file is problematic. Normally the system traps a condition of attempting to delete a file that is already opened by another process but for compatibility with older releases, you have option of overriding this warning condition.

 

System Debugger

Incorrect use of the system debugger could also cause file inconsistency. The system debugger gives the user total control of all the virtual file space and internal control tables used by the system. You should be careful when examining or changing spaces containing critical structures. These are the common reasons of the file system inconsistency. However, inconsistencies can also occurr as a result of defective hardware or problems with the disk. Also, a damaged block on a disk drive and malfunctioning a disk controller can be the cause.

 

FSCK – Use

The fsck can be run in two ways. Automatically and manually. The automatic run is happening at the time of booting. A system administrator can run the utility manually. The operations by this command will work on the data structures stored on the disk directly. This data is internal and specific to the particular file system in use. There are various fsck. The exact behavior of various implementation can vary, but there is a common order of internal operations and a command line interface. There are both interactive and non-interactive fixing of errors. In interactive mode, the user can choose how to fix an error, but in non-interactive mode, the system will make a decision on the operations to do. A system administrator can also run fsck manually if they believe there is a problem with the file system. The file system is normally checked while unmounted, mounted read-only, or with the system in a special maintenance mode. Modern journaling file systems are designed so that tools such as fsck do not need to be run after an unclean shutdown (i.e. crash). The UFS2 Filesystem in FreeBSD has a background fsck, so it is usually not necessary to wait for fsck to finish before accessing the disk.

 

FSCK Uses

Now we are going to see some common usages of fsck command.

# fsck /usr

This will check file-system configured to be mounted on the /usr partition. Here, the file system needs to be unmounted first.

# fsck -t jfs /dev/md0

The above is an example that will check the Linux JFS file system on a mdadm software RAID device:

# parted /dev/sda ‘print’

This command will print the available partitions on your system.

# parted /dev/sda ‘print’

It will give an output like following.

Number  Start     End      Size       Type      File system   Flags

1      1049kB   106MB    105MB    primary    fat16       diag

2      106MB   15.8GB    15.7GB    primary    ntfs        boot

3      15.8GB   266GB    251GB     primary    ntfs

4      266GB    500GB    234GB     extended

5      266GB    466GB    200GB     logical    ext4

6      467GB   486GB    18.3GB   logical     ext2

7      487GB   499GB    12.0GB   logical     fat32        lba

There are a number of possible fsck checker commands. To view the possible fsck checker commands, you need to run the following commands.

# cd /sbin

# ls fsck*

fsck  fsck.cramfs  fsck.ext2  fsck.ext3  fsck.ext4  fsck.ext4dev  fsck.minix  fsck.msdos  fsck.nfs  fsck.vfat

There are exit codes for the fsck commands. The exit codes for the fsck command are listed below.

0 – No errors

1 – Filesystem errors corrected

2 – System should be rebooted

4 – Filesystem errors left uncorrected

8 – Operational error

16 – Usage or syntax error

32 – Fsck canceled by user request

128 – Shared-library error

This is an overview of the fsck utility in the Linux system.

 

If you need any further assistance please contact our support department.

 

 

0.00 avg. rating (0% score) - 0 votes

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply