Code Done Right!

Spin down for HDD

Unfortunately sometimes no matter what you do you will not be able to set up automatic spin down time for some hard disk drives.

Fortunately you can run a script to spin down the drive periodically. If the drive is in use then the drive will spin down for just a moment. If the drive is in stand-by mode it will just remain so.

The spin down for HDD does

As the name suggests, it spins down an HDD. This script is useless for SSD drives as they do not need to be spanned down.

Additional packages required

  • hdparm

Install hdparm by issuing the following command

sudo apt install hdparm

Spin down script code

#!/bin/bash

sudo hdparm -y /dev/sda

Add a line per HDD.

Amend /dev/sda to reflect each of your devices.

Running script periodically

Add the script to the crontab, for crontab refresher see here

sudo crontab -e

At the bottom put

0 * * * * /path/to/script

This will spin down the drive every hour. It is not an ideal situation, but should all fail, this is your workaround.

NOTE if you are using the HDD at the moment the script is executed (like watching a movie), you will notice a short slowdown when the script is executed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.