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 /.

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

Running fsck /dev/sda1 on a mounted root filesystem fails with an error because the filesystem is in use.

# 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.

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

# 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

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.

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

tune2fs output after reboot

After reboot, fsck runs on the root filesystem and the forcefsck file is removed.

# ls -l /forcefsck
ls: cannot access /forcefsck: No such file or directory
# 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

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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxfscktune2fsforcefsckRoot 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

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.