Wiki: Hd Powersave

Setting the Standby Spindown Timeout for ATA Disks with the hdparm utility.

If you have a linux based fileserver that is always powered it is a good idea to set the standby timeouts on the disks so as to reduce wasteful power consumption during periods of inactivity.

The following scripts set the standby timeout to 30 minutes. The comments (from the hdparm man page ) detail what figures to use for other timeout settings.


#!/bin/bash
# set standby timeout on disks , see hdparm man page for details 

#find our installed disks.
disks="`/sbin/fdisk -l 2>/dev/null|grep '^Disk\ */'|awk '{print $2}'|sed -e 's/\/dev\///' -e 's/:$//'|grep -v '^md'`"

#define a logfile.
logfile=/var/log/hd_powersave.log


#Define a timeout   (from the man page)
#
#A value of zero means  "timeouts  are  dis‐abled":  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, and the value 254 is reserved.255 is interpreted as 21 minutes plus 15  seconds.
timeout=241		#30 minutes

echo "setting disk standby timeout at `date`" >> ${logfile}

for d in ${disks}
do
  /sbin/hdparm -S ${timeout} /dev/${d} >>${logfile} 2>>&1
done