Automatically spin down USB hard drives after period of inactivity

You can use hdparm to set a value between 1 and 255 for spindown.

The command for this is hdparm -S255 /dev/sdX with X of course applied to your devices.

You can use blkid to find the correct device.

The device then spins up when accessed.

Use hdparm -C /dev/sdX to check for the device's status (idle/active/standby with standby meaning spun down).

Please handle with care: You can also make the device spin down manually with hdparm -y /dev/sdX. This might be usefull to identify if it spins down at all (see below).


I want to add that this now works with my setup:

  • Raspberry Pi
  • HGST 10TB HDD
  • Connected via USB3

But it did not work all the time. Upon first connection it did not spin down manually and it did not spin down automatically. I am not sure what changed the behaviour of the disk. The two things I did in between where:

  • Disconnect the disk and connect it with a Win10 Laptop and run a checkup program from the disc manufacturer. This just did a short SMART test. I was searching for a setting to change the spindown or APM there but that was not possible.
  • I installed hd-idle on the Raspberry. But hd-idle did not spin the disk down. So I was searching for clues on how hd-idle actually works. While searching for it I re-tried spinning down manually and it worked suddenly.

Btw. my Advanced Power Management-level is 254. (hdparm -B /dev/sdX). I am not sure how APM is related to the spindown time. Normally, a value of 254 should prevent any spindowns. I also read that to enable spindown it should be set to 127 or lower.

I was thinking that maybe HDDs that are manufactured for NAS purposes might suppress spindowns. I posted this answer with additional questionable details to get more insight into the subject from other contributors. I will be glad to update the answer later.

EDIT: It does not work all the time. The disk in standby gets woken up without anyone accessing it. Also, since I removed hd-idle the automatic standby with -S does not work any more.


hd-idle utility should be helpful

Please look at the source given below, read carefully and see if it helps:

  1. Download source code with CVS using these commands:

  2. Debians systems:

    • Run: dpkg-buildpackage -rfakeroot
    • And to install the package run: 'dpkg -i ../hd-idle_*.deb'
  3. Usage:

    hd-idle
    
    # This will start hd-idle with the default options, 
    # causing all SCSI (read: USB, Firewire, SCSI, ...) hard disks 
    # to spin down after 10 minutes of inactivity
    

Note: Please note that hd-idle uses /proc/diskstats to read disk statistics. If this file is not present, hd-idle won't work.

Information:

Running hd-idle

In order to run hd-idle, type "hd-idle". This will start hd-idle with the default options, causing all SCSI (read: USB, Firewire, SCSI, ...) hard disks to spin down after 10 minutes of inactivity.

On a Debian system, after editing /etc/default/hd-idle and enabling it, use "/etc/init.d/hd-idle start" to run hd-idle.

Please note that hd-idle uses /proc/diskstats to read disk statistics. If this file is not present, hd-idle won't work.

Command line options

-a <name>   Set (partial) device name of disks for subsequent idle-time parameters (-i). This parameter is optional in the sense that there's a default entry for all [SCSI] disks which are not named otherwise by using this parameter.
-i <idle_time>  Idle time in seconds for the currently named disk(s) (-a <name>) or for all disks.
-l <logfile>    Name of logfile (written only after a disk has spun up). Please note that this option might cause the disk which holds the logfile to spin up just because another disk had some activity. This option should not be used on systems with more than one disk except for tuning purposes. On single-disk systems, this option should not cause any additional spinups.
-t <disk>   Spin-down the specified disk immediately and exit. Use only the disk name (e.g. sda) without /dev/ prefix
-d  Debug mode. This will prevent hd-idle from becoming a daemon and print debugging info to stdout/stderr
-h  Print brief usage information

Regarding the parameter "-a":

Users of hd-idle have asked for means to set idle-time parameters for individual disks. This makes a lot of sense, not only because some [SCSI] disks may not react well to being stopped. Originally, hd-idle had one idle time for all disks. The parameter "-a" can now be used to set a filter on the disk's device name (omit /dev/) for subsequent idle-time settings.

  1. A "-i" option before the first "-a" option will set the default idle time; hence, compatibility with previous releases of hd-idle is maintained.

  2. In order to disable spin-down of disks per default, and then re-enable spin-down on selected disks, set the default idle time to 0.

Example:

hd-idle -i 0 -a sda -i 300 -a sdb -i 1200

This example sets the default idle time to 0 (meaning hd-idle will never try to spin down a disk), then sets explicit idle times for disks which have the string "sda" or "sdb" in their device name. Stopping hd-idle

Use killall hd-idle to stop hd-idle. On a Debian system, use /etc/init.d/hd-idle stop.

Source:

http://hd-idle.sourceforge.net/


Open programs

Go to tools there you can open discs

On the top bar on the left side of the minimize icon

you will find an icon click this and go to drive settings

there you can change/enable the spin down settings for your usb disc or other discs.