Operations 5 min read

How to Force a Filesystem Check on Linux Root Partition (forcefsck)

This tutorial explains why running fsck on a mounted root filesystem fails, shows how to inspect the last check time with tune2fs, and provides step‑by‑step commands to create a forcefsck file, reboot, and verify that the root filesystem check was performed.

Raymond Ops
Raymond Ops
Raymond Ops
How to Force a Filesystem Check on Linux Root Partition (forcefsck)

Root Filesystem

In this example /dev/sda1 is the root filesystem mounted as /.

<code># df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       63G   41G   19G  69% /
</code>

Running

fsck /dev/sda1

on a mounted root filesystem fails with an error because the filesystem is in use.

<code># fsck /dev/sda1
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sda1 is mounted.
e2fsck: Cannot continue, aborting.
</code>

For non‑root filesystems you can simply unmount the partition and run

fsck

. To force a check on the root filesystem, we use

tune2fs

to see when it was last checked.

tune2fs output before reboot

<code># tune2fs -l /dev/sda1 | grep -i check
Last checked:            Mon Nov 24 12:39:44 2015
Check interval:          15552000 (6 months)
Next check after:        Sun May 22 13:39:44 2016
</code>

The output shows the last check date, the interval, and the next scheduled check.

Create /forcefsck to force a root check

Create an empty file named

forcefsck

in the root directory, then reboot.

<code># cd /
# touch forcefsck
# ls -l /forcefsck
-rw-r--r-- 1 root root 0 Mar 9 20:15 /forcefsck
</code>
<code># reboot
</code>

tune2fs output after reboot

After reboot,

fsck

runs on the root filesystem and the

forcefsck

file is removed.

<code># ls -l /forcefsck
ls: cannot access /forcefsck: No such file or directory
</code>
<code># tune2fs -l /dev/sda1 | grep -i check
Last checked:            Wed Mar 09 20:30:04 2016
Check interval:          15552000 (6 months)
Next check after:        Mon Sep 05 21:30:04 2016
</code>

This confirms that the forced filesystem check was performed and the schedule has been updated.

LinuxSystem Administrationfscktune2fsforcefsckroot filesystem
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.