fsck command is used to check and optionally repair one or more Linux file systems. You don’t have to create or alter/modify any file. All you need to do is just create empty file called /forcefsck.
How does fsck force work at every boot on a Linux?
On a Debian or Ubuntu Linux /etc/init.d/checkfs.sh (or /etc/init/mountall.conf on a Ubuntu LTS v14.04+) is used to run fsck command if /forcefsck.
Check the /etc/init/mountall.conf file, for example the file from Ubuntu 14.04 LTS
script . /etc/default/rcS || true [ -f /forcefsck ] && force_fsck="--force-fsck" [ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix" # Doesn not work so well if mountall is responsible for mounting /proc, heh. if [ -e /proc/cmdline ]; then read line < /proc/cmdline for arg in $line; do case $arg in -q|--quiet|-v|--verbose|--debug) debug_arg=$arg ;; esac done < /proc/cmdline fi # set $LANG so that messages appearing in plymouth are translated if [ -r /etc/default/locale ]; then . /etc/default/locale || true export LANG LANGUAGE LC_MESSAGES LC_ALL fi exec mountall --daemon $force_fsck $fsck_fix $debug_arg
On a RHEL/CentOS 6.x /etc/rc.sysinit file is used to run fsck command. If there is a /fsckoptions file, the options are loaded from the /fsckoptions file. If there is a /forcefsck file, -f is added.
Check the /etc/rc.sysinit file, for example the file from RHEL/CentOS Linux 6.x
Force fsck on boot using /forcefsck
By creating /forcefsck file you will force the Linux system (or rc scripts) to perform a full file system check. First, login as the root user:
$ su -
$ sudo -s
Change directory to root (/) directory [optional]:
# cd /
Create a file called forcefsck:
# touch /forcefsck
Now, reboot the system:
Frce fsck on next boot using shutdown command (may not work on many modern distros)
The -F option force fsck on reboot, login as root and type the following command to reboot and run fsck:
# shutdown -rF now
The above will check all the relevant partitions immediately.
A note about systemd based systems
The above mentioned solution only works with the old SysVinit and early versions of Upstart. It won’t work with systemd. systemd-fsck understands one kernel command line parameter:
Share this tutorial on:
One of “auto”, “force”, “skip”. Controls the mode of operation. The default is “auto”, and ensures that file system checks are done when the file system checker deems them necessary. “force” unconditionally results in full file system checks. “skip” skips any file system checks.
One of “preen”, “yes”, “no”. Controls the mode of operation. The default is ” preen”, and will automatically repair problems that can be safely fixed. “yes ” will answer yes to all questions by fsck and “no” will answer no to all questions.