Check Disk State
Luke Hebert
- 2 minutes read - 254 wordsWhen a server comes back online after a crash or an unclean shutdown, one of the first things you want to confirm is whether each ext3 or ext4 filesystem is in a clean state. The commands below walk every mounted partition, pull its label, and print the Filesystem state line from tune2fs so you can spot dirty or error flags without digging through logs.
ext3 only
grep ext3 /proc/mounts | gawk '{ print $1 }' | sort | uniq | while read part; do
echo "$part - $(e2label $part) - $(tune2fs -l $part | grep state)"
done | column -text3 and ext4
egrep '(ext3|ext4)' /proc/mounts | gawk '{ print $1 }' | sort | uniq | while read part; do
echo "$part - $(e2label $part) - $(tune2fs -l $part | grep state)"
done | column -tWhat to look for
- Filesystem state: clean – the partition was unmounted properly.
- Filesystem state: error – the kernel detected a problem; run
fsckon that device before trusting the data. - Filesystem state: dirty – the filesystem was not cleanly unmounted. A read-only remount followed by
fsckwill usually resolve it.
Note
tune2fs -l reads the superblock directly, so it works even when the partition is mounted read-only. If a partition is mounted read-write and you need to run fsck, unmount it first or boot into single-user mode.
The column -t at the end lines everything up into a tidy table, which makes it easy to scan a box with a dozen or more disks.