Prior warning about Ubuntu’s disk checks

By ændrük

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.

mountcount

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.

#!/bin/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 sudo tune2fs -l /dev/disk/by-label/UBUNTU line:

  • My Ubuntu partition is labeled UBUNTU. Others will probably have to change this.
  • As far as I know, sudo is required to get the status report via tune2fs. To enable the script to run by itself, I gave permission to my account to run the command without a password.

Tags: ,

Leave a Reply