2009-05-02

The default configuration in Ubuntu is to perform a disk check every 35 times the hard disk is mounted. When using a laptop on the go, there are times during which it can be a great inconvenience to have to wait for a disk check at boot.

While it’s possible to change or even disable this completely, I personally find it most helpful to just have a little forewarning about when it’s going to happen.

Prior warning about Ubuntu’s disk checks

I run the following script at startup to query how many times the disk has been mounted and notify me if a disk check will happen soon.

#!/usr/bin/env bash

# Get current status report of the disk
tune2fs_output="$(sudo tune2fs -l /dev/disk/by-label/UBUNTU)"

# Scrape for values
mountcount="$(echo "$tune2fs_output" | grep "Mount count:" | awk '{print $3}')"
maxmountcount="$(echo "$tune2fs_output" | grep "Maximum mount count:" | awk '{print $4}')"
deltamountcount=$((${maxmountcount}-${mountcount}))

# Notify
echo "Disk check in $deltamountcount boots. Mount count is $mountcount of $maxmountcount."
if [ "$deltamountcount" -le "3" ]; then
if [ "$deltamountcount" -le "1" ]; then
notify-send --icon /usr/share/icons/Human/scalable/devices/drive-harddisk.svg "Disk check on next boot" "Mount count is $mountcount of $maxmountcount."
else
notify-send --icon /usr/share/icons/Human/scalable/devices/drive-harddisk.svg "Disk check in $deltamountcount boots" "Mount count is $mountcount of $maxmountcount."
fi
fi

exit

Two notes about the tune2fs line: