How to Check Last fsck Execution Time and Mount Count in Linux Filesystems


1 views

Filesystem consistency checks (fsck) are crucial maintenance operations in Linux systems. While modern filesystems are quite resilient, knowing when your system last performed a check can help diagnose potential issues.

The most reliable way to check fsck history is using the tune2fs utility, which works with ext2/3/4 filesystems:

$ sudo tune2fs -l /dev/sda1 | grep -i "last checked\|mount count"
Last checked:             Mon Jul 10 09:15:23 2023
Mount count:              15
Maximum mount count:      30

For non-ext filesystems or additional verification:

Using dumpe2fs

$ sudo dumpe2fs /dev/sda1 | grep -i "last checked"
Last checked:             Mon Jul 10 09:15:23 2023

Checking System Logs

System logs often contain fsck records:

$ journalctl -b | grep fsck
$ grep -i fsck /var/log/messages

Create a simple monitoring script:

#!/bin/bash
DEVICE="/dev/sda1"
LAST_CHECKED=$(sudo tune2fs -l $DEVICE | grep "Last checked" | cut -d":" -f2-)
MOUNT_COUNT=$(sudo tune2fs -l $DEVICE | grep "Mount count" | awk '{print $3}')

echo "Last fsck: $LAST_CHECKED"
echo "Mounts since last check: $MOUNT_COUNT"

Different filesystems handle this differently:

  • XFS: Uses xfs_admin and xfs_info
  • Btrfs: Doesn't use traditional fsck but has btrfs scrub
  • ZFS: Has zpool status for health checks

Regular filesystem checks prevent:

  • Silent corruption accumulation
  • Unexpected downtime
  • Data integrity issues

When troubleshooting Linux systems, knowing the last filesystem check (fsck) timestamp can be crucial for diagnosing potential filesystem corruption issues. While this information isn't directly exposed through standard tools, we can extract it using several methods.

The most reliable method uses the tune2fs utility, which displays extensive filesystem metadata:

# tune2fs -l /dev/sda1 | grep -E "Last checked|Mount count"
Last checked:             Mon Jul 10 14:32:45 2023
Mount count:              27

For XFS, btrfs, or other filesystems, we need different approaches:

# xfs_admin -l /dev/sdb1
(Shows last mount time and other metadata)

System logs often contain fsck records. Search journald or syslog:

# journalctl -b | grep fsck
# grep -i fsck /var/log/messages

For regular monitoring, create a simple bash script:

#!/bin/bash
DEVICE="/dev/sda1"
LAST_CHECK=$(tune2fs -l $DEVICE | grep "Last checked" | cut -d":" -f2-)
MOUNT_COUNT=$(tune2fs -l $DEVICE | grep "Mount count" | awk '{print $3}')

echo "Filesystem $DEVICE"
echo "Last checked: $LAST_CHECK"
echo "Mounts since last check: $MOUNT_COUNT"

Modern Linux systems typically run fsck automatically after a certain number of mounts (usually every 30 mounts) or after a specific time period. If your mount count is approaching the maximum set in your filesystem parameters (visible in tune2fs -l output), consider scheduling a manual fsck.

To ensure your filesystem gets checked soon:

# touch /forcefsck
# shutdown -r now

Or for specific filesystems:

# tune2fs -C 40 /dev/sda1