Fsck (File System Consistency Check) is an essential tool on Unix and Linux systems used to check and repair file system integrity. This utility finds and fixes file system problems, such as damaged blocks, incorrect inodes, and other errors that could arise from power outages, improper restarts, or other issues.
Many modern Linux distributions now use systemd. The traditional way of using tune2fs only works on sysvinit or upstart systems. Therefore, creating the file touch /forcefsck under the root directory will not work on current distributions. (From Ubuntu 15.04/CentOS 7 onward.)
Important Information
We recommend taking a snapshot of the server before modifying the grub configuration.
To force fsck at boot, edit the grub configuration file
# nano /etc/default/grub
We will add fsck.mode=force and fsck.repair=yes to GRUB_CMDLINE_LINUX_DEFAULT (A GRUB_CMDLINE_LINUX_DEFAULT parameter already exists; you can add it to the same line or create a new one exactly as shown in the following image.) so that it looks like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force fsck.repair=yes"
Save the configuration with control+o (If you are using nano.)
Then run update-grub and perform a reboot.
# update-grub && reboot
To verify that it worked correctly, run
# tune2fs -l /dev/sda1 | grep "Last checked"
If the current date appears, it was completed successfully. To disable it again, remove:
fsck.mode=force fsck.repair=yes
run again
# update-grub
Configuration for CentOS/RHEL/Fedora/Rocky/Alma Linux:
To force fsck at boot, edit the grub configuration file
# vi /etc/sysconfig/grub
We will add fsck.mode=force and fsck.repair=yes to GRUB_CMDLINE_LINUX_DEFAULT (If a GRUB_CMDLINE_LINUX_DEFAULT parameter already exists, you can add it to the same line or create a new one exactly as shown in the following image.) so that it looks like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force fsck.repair=yes"
Save the configuration.
Then run grub2-mkconfig and perform a reboot.
# grub2-mkconfig -o /boot/grub2/grub.cfg && reboot
To verify that it worked correctly, run
# tune2fs -l /dev/sda1 | grep "Last checked"
If the current date appears, it was completed successfully. To disable it again, remove:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force fsck.repair=yes"
run again
# grub2-mkconfig -o /boot/grub2/grub.cfg
Remember, if you have questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We are here for whatever you need!