Disk spindown in linux, specifeying spindown idle time

Update/2025: The old info below (Startiong with the title spindown) no longer works as what used to be expected back then, the new expected behavior changed, today, if you try this on your drives, it may or may not work due to a bug-fix that fixes a bug that is 15 years old !

So there are 2 conditions

  • the device is not attached via USB or Firewire
  • supports APM

For the impatient, a workaround is to use udev rules, you start by checking that the following command “grep . /sys/class/block/sdb/device/power/*” to find out what’s currently set for autosuspend control, if it returns either “control:on” or “autosuspend_delay_ms as empty”, proceed, So let us get down to business

So, to test this out, try it without making it perminent, the following line should spin down your disk after 1 minute

echo 5000 | sudo tee /sys/class/block/sdc/device/power/autosuspend_delay_ms
echo auto | sudo tee /sys/class/block/sdc/device/power/control

If the above worked for you, you can simply add the following rules file to make those settings permanent

Create the file “/etc/udev/rules.d/99-spindown-disks.rules” and put the following contents in it

ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]", TEST=="device/power/autosuspend_delay_ms", ATTR{device/power/autosuspend_delay_ms}="15000"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z]", TEST=="device/power/control", ATTR{device/power/control}="auto"

A different work around is using the package “https://github.com/adelolmo/hd-idle” 😉

Spinning the disks down manually (hdparm -Y /dev/sdc) works instantly, no problems there !

Setting this directly with the “hdparm -S 240 /dev/sdb” for example should work (need to check), but not through hdparm.conf !

So how do i know this criteria is what is stopping me from using the config file to spin things down ? i tried this command

hdparm -B /dev/sda

/dev/sda:
APM_level = not supported

Disk Spin down (Tested with Bullseye 2022)

Even though everything concerning block devices in linux has shifted to unique identifiers, hdparm has not, and will still use the old /dev/sdx system

To control disk spindown, and to manually issue commands, you will need to have the package installed

apt-get install hdparm

There is a probelm with disk spindown via hdparm, the problem is that you must address a disk as /dev/sdc , which changes in the case of USB media and other disks, even when you add slaves,

hdparm -Y /dev/sdb will spin a disk down instantly
hdparm -S 240 /dev/sdb will set this disk to sleep when idle for 20 minutes (5 second units here)

or adding at the bottom of the file /etc/hdparm.conf a section such as

/dev/sdc {
spindown_time = 240
}

to make those changes persistent across reboots.

The new way of doing this is using the disk ID, to find the disk ID, run the command

ls -l /dev/disk/by-id

once you know your disk ID, the block should look like this

# My 3TB WD green 
/dev/disk/by-id/ata-WDC_WD30EZRX-00MMMB0_WD-WMAWZ0299541 {
spindown_time = 240
}

To check the status of a disk, here is what you do

hdparm -C /dev/sde

You could get one of the following results
When spun down…
drive state is: standby
When active
drive state is: active/idle

Don’t make your disks spin-down too often, 20 minutes is good for me almost in all circumstances.

If the disks don’t spin down, chances are that selftest is enabled…

Check if it is enabled with

smartctl -a /dev/sdb
if it reads
Auto Offline Data Collection: Enabled.
then you need to disable it with
smartctl --offlineauto=off /dev/sdb

then wait for them to finish (if a test is running) then spin down.

Leave a Reply

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