Home Ubuntu How to Force “FSCK” File System Check on Ubuntu

How to Force “FSCK” File System Check on Ubuntu

As Linux users, we can never undervalue the importance of the FSCK (File System Consistency Check) command, as it scans and troubleshoots your Linux filesystem for performance issues or errors and then tries to fix them if it can.

FSCK is a default pre-installation on all Linux operating system distributions. Therefore, if you had yourself worried about mastering the steps for installing, configuring, and using this Linux filesystem tool.

[ You might also like: How to Repair a Damaged Filesystem in Ubuntu ]

Your requirements for mastering FSCK have been reduced to the following three bullet points:

  • You are working under a UNIX-like/Linux operating system environment.
  • You have access to your Linux operating system terminal or command-line interface.
  • You are a Linux user with root or Sudoer privileges.

Forcing FSCK File System Checks in Ubuntu

This article aims to give us a walk-through on forcing fsck to execute consistent filesystem checks on upcoming/scheduled system reboots on Ubuntu. The mount point for these system reboots can be root or non-root.

Obtaining Ubuntu Filesystem Information

We cannot run blindly into force-executing the FSCK command without knowing which area of our filesystem has a problem. The first step is to run a filesystem health check through a tool like tune2fs.

For example, to determine the most recent and successful filesystem check, we would run a command similar to the following:

$ sudo tune2fs -l /dev/sda5 | grep Last\ c
Find Ubuntu Filesystem Checks
Find Ubuntu Filesystem Checks

The command portion /dev/sda5 is the targeted filesystem partition. You can find a list of all your active filesystem partitions by running the command:

$ sudo fdisk -l
Find Ubuntu Partitions
Find Ubuntu Partitions

With the tune2fs tool, we can also determine the number of times a filesystem partition (/dev/sdbx) got mounted.

 
$ sudo tune2fs -l /dev/sda5 | grep Mount
Find Partition Mounts
Find Partition Mounts

Finally, you can also determine the maximum permissible mounts before any forced filesystem check routine is executed.

$ sudo tune2fs -l /dev/sda5 | grep Max
Check Partitions Mounts
Check Partitions Mounts

Based on the above tune2fs sampled command outputs, we can conclude the following /dev/sda5 filesystem information summary:

  • This filesystem’s most recent check was on Mon Oct 25 16:48:10 2021.
  • The attained number of filesystem mounts since its most recent check is 7.
  • The Maximum mount count output of -1 implies force fsck is inactive/disabled.

Find Partition UUID in Ubuntu

The /etc/fstab file holds all on-boot mountable partitions information and their associated mount options. The first step is to fetch the UUID of a targeted partition using the blkid command.

$ sudo blkid | grep sda5
Find Partitions UUID in Ubuntu
Find Partitions UUID in Ubuntu

Since the partition info is in /etc/fstab file, the retrieved UUID helps fetch other useful information related to the targeted filesystem partition.

$ sudo grep 097942b2-6c89-489f-9d54-1461c9ddcd23 /etc/fstab
Find Partitions Info in Ubuntu
Find Partitions Info in Ubuntu

The 6th column from the above command output is the fsck PASS column. Its value denotes the order in which a filesystem partition check; in reference to the /etc/fstab file, should take place.

  • fsck PASS column 0 entry implies filesystem check is disabled.
  • fsck PASS column 1 entry gives higher priority filesystem checks to filesystems associated with it (usually /).
  • fsck PASS column 2 entry gives the lowest priority filesystem checks to filesystems associated with it. Such filesystems are checked last.

Forcing FSCK on Root Partition in Ubuntu

Creating the following empty file on your targeted filesystem root partition e.g /dev/sda1 will force fsck filesystem check.

$ sudo touch /forcefsck

Creating empty file schedules fsck filesystem check on the next system reboot. However, after the filesystem check is done, this file (forcefsck) is removed/deleted by the system and the check will not happen during the next system reboot.

A permanent solution to this temporary fsck check is manipulating the Maximum mount count parameter (assigning it a positive integer value) associated with the targeted filesystem.

The following command achieves continuous on-boot fsck check for filesystem partition /dev/sda5.

 
$ sudo tune2fs -c 1 /dev/sda5
Set FileSystem Checks on Boot
Set FileSystem Checks on Boot

To force fsck to execute after every 10 system reboots, reference the following command.

$ sudo tune2fs -c 10 /dev/sda5
Set FileSystem Checks Count on Boot
Set FileSystem Checks Count on Boot

Forcing FSCK on Non-Root Partitions in Ubuntu

The empty /forcefsck file is not applicable on non-root partitions. However, manipulating the PASS value or Maximum mount count parameter within the /etc/fstab configuration file does the trick.

To force fsck on a non-root /dev/sdb1 partition after every system reboot:

$ sudo tune2fs -c 1 /dev/sdb1

To force fsck on /dev/sdb2 after every 5 system reboots:

$ sudo tune2fs -c 5 /dev/sdb1

To disable force fsck on /dev/sdb1:

$ sudo  tune2fs -c 0 /dev/sdb1

Alternatively, we can disable it with the command:

$ sudo tune2fs -c -1 /dev/sdb1

On rebooting your Ubuntu system, the forced fsck filesystem check should take place.

Ubuntu Filesystem Checks on Boot
Ubuntu Filesystem Checks on Boot

Being able to force fsck on a root or non-root filesystem partition ensures that your Ubuntu OS remains healthy and performant. You get to check and fix small filesystem issues or errors before they pile up and cost you a lot of OS time because of prolonged system diagnosis.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

1 thought on “How to Force “FSCK” File System Check on Ubuntu”

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.