How to run fsck forcibly on next reboot in linux

How to force fsck on next reboot in linux

What is fsck ?

“fsck” stands for File System Consistency Check . “fsck” is a command line utility tool to perform file system check and fix if any error encountered during checking to maintain consistency and integrity of file system. This makes fsck really important utility as linux is collection of files and folders.This is one of the core functionality provided by all the operating systems either server level or desktop level operating system so as in case of Red Hat Enterprise Linux as well. Few file system types in RHEL are ext2, ext3, ext4 etc.

Why fsck ?

Inconsistencies in file system may be due to many reason unexpected reboots due to malfunctioning of any programs terminations or abnormal shutdowns  or hard reboots in case it it gets hung in case of physical servers etc.

When fsck needs to be ran ?

There might be many situation when you need to run fsck manually .For instance

1. I/O error in FS while accessing files.

2. File Read Error.

3. Server is not able to boot due to corruption in any file system and it gets placed in maintenance mode.

4. Slowness in accessing file system.

OS Provision to overcome FS inconsistencies ?

“fsck” is expected to run on every boot. It run in six phases and in some cases if file system journal indicates file system is clean. It gets terminated assuming all OK or it shows message to run full fsck manually. fsck sets tables for storing inodes and comparisons, verifies validity of fsck options, then runs through the 6 phases. After initializing it’s tables fsck performs operations in below sequence.

1: Check Blocks and SizesIn this stage fsck validates inodes for any inconsistencies.

2: Check Path-NamesIn this stage fsck validates directory.

3: Check ConnectivityIn this stage fsck validates all directories association with file system.

4: Check Reference CountsIn this stage fsck compares link count from Phases 2 & 3, correcting if any discrepancies.

5: Check Cylinder GroupsIn this stage fsck checks free blocks and the used inode maps for consistency of file system.

6: Salvage Cylinder Groups : In this stage fsck updates the tables to reflect any changes made in earlier phases.

Understanding Exit Codes

After running fsck, it will return an exit code. These cods can be seen in fsck’s manual by running.: # man fsckfsck_man_page_output

Things to Note : Running fsck needs root level privilege and fsck  operations time depends on fs size.In case if Fs size is bigger fsck may long time.So take downtime appropriately.

So now we understand what is fsck and how it works and why it is important. It is normal assumption that before running fsck i/o operations must be stopped in other terms it is always better to run fsck after unmounting file system.

How to run fsck on live systems

Basically it is quite easy to run it by unmounting file system and run fsck. Log in as root or login and take super user permission.

  1. # umount /usr/ctc/opt
  2. # fsck -y /dev/ctc/opt

“-y” option is answer yes if any question prompted while performing fsck operations.Most of the cases it runs successfully and return 0 error code but in some cases you may get error . That is the case when you need to force system to run full fsck. See  error displayed  below.fsck command output


How to Force “fsck” on Next Reboot – Red Hat Enterprise Linux

You can force server automatic full fsck on next reboot .There is option where you can set system to perform full fsck on every reboot using “tunefs” command.Be careful it may increase boot time of server depending upon FS sizes configured on it.

# tune2fs -c 1 /dev/sdc            //It tells to init scripts to run fsck on sdc at every reboot.//

# tune2fs -i 1d /dev/sdc            //It tells init script to run fsck on sdc after 1 day.//





Some times due to inconsistency it is also not working .Please see the above snap.In that case you need to force system to run full fsck only on next reboot.This you can achieve this by creating a file in root (/) directory with name forcefsck followed by reboot.forcing-fsck-on-reboot-output




This will force full “fsck” on next reboot. “forcefsck” file gets deleted automatically after fsck completion.You can monitor activity on console depending on server type. ILO for physical linux servers,vSphere Web Console for VMWare RHEL VM or you can connect to Azure Web Portal for linux virtual machine console access taking VM Contributor role access if your RHEL VM is hosted on AZURE. You will see console output like below.Need to wait till completion .It will depend on size of file system.Once completed you are done.


Let me share one of my experience related to this.For One of our production VM in AZURE backup was failing and error code returned in backup log was “File read error“.

We went through all possible troubleshooting option with no success.We went ahead with full fsck on file system after taking downtime.After completion of full fsck using above method to run fsck on next reboot. We restarted backup job from policy manually and it works.

That,s all about fsck magic as of now.Keep Learning.If you like our contents please subscribe our news letter and like and comment our social media pages and express your support which means a lot to us and keep motivating us to share more .



Leave a Reply

Your email address will not be published. Required fields are marked *