How to prevent sleeping disks from spinning up at SSH login (Ubuntu 20.04)

17. August 2020 - Reading time: 2 minutes

My home server running Ubuntu 20.04 acts as a NAS besides several other roles. Most of the time (as long as no one is accessing data) the associated hard drives are sleeping, spun down by hd-idle after 10 minutes of inactivity. What annoys me really bad is that they spin up most of the times I only login to the server via SSH: Every spin-up wears out the drive and every unnecessary spin-up wears out the drive unnecessarily. Since all OS data is located on a SSD, none of the NAS hard drives should be touched during SSH login. After some internet research I found the reason for this behavior and a solution that is working for me:

The script /usr/lib/update-notifier/update-motd-fsck-at-reboot is scanning all installed drives at user login for which drives should be checked for errors at the next reboot, and shows that information on your motd login page. To prevent that scan and, as a consequence, prevent disk spin up at login, an askubuntu thread suggests to deactivate this check forever by replacing the the variable assignation to : in the script. Since this did not work for me, I've commented out the whole section of the script below

# check time when we did the last check

and below

# check time when we last booted

Given that this script performs the scan only once every defined amount of seconds (default 3600 s), you can alternatively increase this defined amount of seconds to a much higher value, for instance to a week (25200 s). The result will be one disk spin up at login once a week. The relevant part of the script is then modified to:

if [ $(($stampt + 25200)) -lt $now ] || [ $stampt -gt $now ] \
   || [ $stampt -lt $last_boot ]
then
    #echo $stampt $now need update
        NEEDS_FSCK_CHECK=yes
fi

In my case, that worked very straightforward, no reboot was required. I decided to take the first approach, but to include the disk check into a regular cron job which is running the script manually once a week by calling:

/usr/lib/update-notifier/update-motd-fsck-at-reboot --force

Currently there are no comments, so be the first!