#!/bin/bash # Check for idle disks and spin them down # Some Harddrives not working to spindwon with hdparm -B oder -S commands. # But hdparm -y direct work. So that a script for that Harddrives. # http://linuxwiki.de/hdparm # # Installation: # --------------- # For this script hdparm must be installed, but not configured! # Only a apm=255 is maybe needed in the hdparm.conf for the Drive. # # Installation: # Put it to /usr/local/bin/disk_spindown.sh # Set the Permissons sudo chmod 744 /usr/local/bin/disk_spindown.sh # Startup: we put a new line in /etc/rc.local for systemwide start. # /usr/local/bin/disk_spindown.sh & >/dev/null # exit 0 # # Now you can reboot the pc, for activate or to activate a change. # # Western Digital Green Harddrives (mostly not suitable with hdparm -S or -B) # --------------------------------------------------------------------------- # Modern Western Digital "Green" Drives include the Intellipark feature that stops the disk when not in use. # Unfortunately, the default timer setting is not perfect on linux/unix systems, including many NAS, # and leads to a dramatic increase of the Load Cycle Count value (SMART attribute #193). # Please deactivat it with http://idle3-tools.sourceforge.net/ (normally in the Distro) # # get the Info: idle3ctl -g /dev/sd(x) # disabling : idle3ctl -d /dev/sd(x) # The idle3 timer seems to be a power on only setting. That means that the drive needs to be powered OFF and then ON to use the new setting. # I turn off the Computer, plug the power off and push the start button, for a short while the fan go's on. All power it out. # Or turn off for few minutes to take the effect. # Where is your Ramdrive? # Check it out with df -h or mount command. # Possible Values Examples: /dev/shm , /run/shm ramdrive=/run/shm # The Spindwon Time in Seconds # The Raktion done in $spindowntime maximum of 2 times. Depending build by the script. Protects for the cpu load. spindowntime=1200 # Wich disk are handled diskvolumes="b c d e f g h i j k" # Build onece the tempfiles if [ ! -f $ramdrive/diskstate1 ]; then touch $ramdrive/diskstate1;fi if [ ! -f $ramdrive/diskstate2 ]; then touch $ramdrive/diskstate2;fi # Here we go... while [ true ] ; do # cycle it to test for activity mv $ramdrive/diskstate1 $ramdrive/diskstate2 cat /proc/diskstats > $ramdrive/diskstate1 # Loop through all array disks and spin down idle disks. for disk in $diskvolumes do if [ "$(diff $ramdrive/diskstate1 $ramdrive/diskstate2 | grep sd$disk )" = "" ] ; then hdparm -y /dev/sd$disk >/dev/null 2>&1; fi done # Wait sleep $spindowntime done exit 0