Spin Down Idle Hard Disks

Necessary tools:

 sudo apt-get install hdparm

Now, you need to edit your hdparm.conf to add entries for each of your drives.

 nano /etc/hdparm.conf

Here’s an example of my setup.

/dev/disk/by-id/ata-Hitachi_HDS5C3030ALA630_MJ1313YNG1LMJC {
        apm = 127
        keep_features_over_reset = on
        spindown_time = 242
}

/dev/disk/by-id/ata-TOSHIBA_DT01ACA300_44LY9ENGS {
        apm = 127
        keep_features_over_reset = on
        spindown_time = 242
}

/dev/disk/by-id/ata-ST3000DM001-1ER166_Z7P0027C {
        apm = 127
        keep_features_over_reset = on
        spindown_time = 242
}

You will note that I’m identifying the drives by their unique ID rather than simply using /dev/hdX or /dev/sdX, as device assignments can change between reboots. You can determine these values by looking at the output of this command.

ls -l /dev/disk/by-id

It will give you output like this…

lrwxrwxrwx 1 root root  9 Mar  3 15:31 ata-HGST_HDN724040ALE640_PK1334PCGXGYYS -> ../../sdi
lrwxrwxrwx 1 root root 10 Mar  3 15:31 ata-HGST_HDN724040ALE640_PK1334PCGXGYYS-part1 -> ../../sdi1
lrwxrwxrwx 1 root root  9 Mar  3 15:31 ata-HGST_HDS5C4040ALE630_PL2331LAG9056J -> ../../sdb
lrwxrwxrwx 1 root root 10 Mar  3 15:31 ata-HGST_HDS5C4040ALE630_PL2331LAG9056J-part1 -> ../../sdb1
...

/dev/sdb would be identified by this in your /etc/hdparm.conf file.

ata-HGST_HDS5C4040ALE630_PL2331LAG9056J

You may also noticed that I have set Advanced Power Management to 127. This is the setting with the highest performance which still allows spindown, I’ve also told the drive to keep features over reset, in order to preserve the settings on a soft restart, and spindown delay has been set to 242 (1 hour).

Here’s the manpage description for more info.

The Time (in seconds) after which the Drive spins down is the value of your x multiplied with 5 From the manpage:

A value of zero means "timeouts are disabled": the device will not automatically enter standby mode.
Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes.
Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours.
A value of 252 signifies a  timeout  of  21  minutes.
A value of 253 sets a vendor-defined timeout period between 8 and 12 hours.
A value of 255 is interpreted as 21 minutes plus 15 seconds.
The value 254 is reserved.
Note that some older drives may have very different interpretations of these values.

NOTE: If you see an error like this, or some of your disks aren’t spinning down, it’s because your disk doesn’t support Advanced Power Management (APM). You can still spin them down with the hdparm -y, but this isn’t a viable solution, unless you want to roll a script to spin it down after a period of inactivity. Edit: I have created a script that will do just that. You can view it here.

setting Advanced Power Management level to 0xfe (254)
HDIO_DRIVE_CMD failed: Input/output error
setting standby to 1 (5 seconds)
APM_level = not supported

Reboot for this to go into effect.

reboot

The above does put your disks to sleep, but I was having issues in that smartd (SMART monitor was checking the drives every 30 minutes. When this was happened, it would wake the disks up, basically never allowing them to go into standby. I have changed it to check every 2 hours, and to not spin the drive up if it is in standby. You can do so by making the following changes.

nano /etc/default/smartmontools

and add this to the options…

smartd_opts="-q never -i 7200"

And, finally, if you don’t want to spin up idle hard drives, there’s one more file you need to edit.

nano +22 /etc/smartd.conf

Comment this line out

DEVICESCAN -m root -M exec /usr/share/smartmontools/smartd-runner

And add this below the commented out line.

DEVICESCAN -S on -o on -a -I 194 -m username@gmail.com -s (S/../.././02|L/../../6/03) -n standby,q

One more reboot, and you should be on your way to drives that spin down, and all the energy savings associated with that.

If you’d like to check the status of your disks, you can view the current status like this.

hdparm -C /dev/sde

It should output something like this if the disk is spun down.

/dev/sde:
 drive state is:  standby

Or, all of them at once like this where x is the starting disk and y is the end.

hdparm -C /dev/sd[b-z]

Here’s example output…

root@fileserver:~# hdparm -C /dev/sd[b-k]

/dev/sdb:
 drive state is:  standby

/dev/sdc:
 drive state is:  standby

/dev/sdd:
 drive state is:  standby

/dev/sde:
 drive state is:  standby

/dev/sdf:
 drive state is:  standby

/dev/sdg:
 drive state is:  standby

/dev/sdh:
 drive state is:  standby

/dev/sdi:
 drive state is:  standby

/dev/sdj:
 drive state is:  standby

 

Zack

I love learning new things and trying out the latest technology.

You may also like...

Leave a Reply

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