Using spindown to prolong the life of old hard disks

3437

Author: Ben Martin

Many people leave their computers on around the clock. This usually implies that all the attached hard disks are always spinning. Constantly spinning up a hard disk normally increases the chances of drive failure. When a disk is not powered it should last longer than if it was spinning. There is a delicate balance between having a hard disk spinning down and up too frequently and leaving it spinning around the clock. If you have a filesystem that you want to have near instant access to but do so on an infrequent basis, you might like to use spindown to automatically spin down the disk containing that filesystem after you have finished accessing the drive.

The spindown daemon keeps track of which disks it should try to spin down using their device IDs. Although the project description mentions that this is handy for using spindown on USB disks, I find it to be equally important for permanently attached disks. If you add a new drive and the old 80GB disk moves from being /dev/sdd to /dev/sde, you really don’t want spindown to try to turn off your new 750GB fileserver drive just because it happens to appear at /dev/sdd. These are just the sorts of things that would be likely to happen 18 months after you initially set up spindown and add a new four-port PCIe SATA card, resulting in your drive letters being shuffled around.

I could find no packages for spindown for major distributions. I have made RPMs for Fedora 8 available on SourceForge.net.

spindown uses the sg_start command to start and stop hard disks. sg_start is available in Gutsy universe, via a 1-Click install for openSUSE 10.3, and in the Fedora repository as sg3_utils. Once you’ve installed sg_start from the standard repositories, building spindown follows the standard ./configure; make; sudo make install process. spindown itself does not use the autotools but is set up to accept the normal autotools build process. I used version 0.1.2 of spindown for this article.

After installing spindown you will have to create the configuration file /etc/spindown.conf. A sample configuration file is contained in the spindown tarball. It’s an INI format file and includes a global section and a section for each disk you want to monitor and spindown. The global section has only two parameters: cycle-time is how often to check if a disk is idle, and idle-time is how long a disk must have had no access before it is to be spun down. If you are using spindown to control a rarely used filesystem, you might like to increase these two values from their defaults (60 and 3,600 seconds for cycle-time and idle-time respectively) to, for example, a cycle-time of 3,600 seconds and an idle-time of 64,800 seconds. That way, if you happen to access the filesystem again on the same day, the disk will still be spinning.

For each disk that you want spindown to monitor you need to create a [Disk N] section in the /etc/spindown.conf file. The default action is for spindown not to monitor and spin down any drives. You must specify spindown = 1 in each disk section to instruct spindown to monitor the disk. The other two configuration parameters that are the most important for each disk are its ID and what arguments must be passed to sg_start to spin the disk down. The disk ID can be found by listing /dev/disk/by-id. If you are using LVM, you can use df to see what logical volume a filesystem is on, lvscan to find out which physical volume contains that logical volume, and then pvscan to see what disk(s) contain the logical volume you are interested in. Alternately you can use the graphical tool system-config-lvm to find this information.

Examples for arguments used to spin the disk down include --stop and --pc=2. The pc argument to sg_start is used to specify the “power conditions” to the drive. If the value 2 (idle power condition) does not work, you may have to change the value you pass to --pc depending on what drives you are monitoring. The most important thing is to know that the disk is actually spun down after you issued the command — that is, the disk has not entered an idle state where the platters are still spinning. See the sg_start manual page for details.

For testing purposes I set cycle-time to 15 and idle-time to 60, but you shouldn’t use these values on a regular system, as they would lead to a significant number of disk spin up/down cycles per day. I did not require any special arguments to sg_start for the Seagate 500GB SATA hard disk that I wanted to spin down. The configuration file is shown below:

# cat /etc/spindown.conf [General] cycle-time = 15 idle-time = 60 [Disk 0] id = ata-ST3500630AS_9..... spindown = 1

With the above configuration in place I left the filesystems on ata-ST3500630AS_9... alone for 60 seconds and monitored what spindown was doing by issuing the status command through the init.d service file as shown below. When active=0 was reported I issued an ls command on a filesystem that I knew was stored on the drive. There was a multiple second delay as the disk was spun up before the listing appeared.

If you run the status command again right away to see which disks are spun down, you may see spindown reporting that the disk is still idle, because of the cycle-time interval and spindown not updating its status information until the next cycle starts. As the drive was mounted in an external enclosure I had the luxury of being able to feel the drive transition by placing my hand on the enclosure at about 55 seconds after the last access and waiting for spindown to perform its work.

# /etc/init.d/spindown restart # /etc/init.d/spindown status name watched active idle-time sdb 1 1 3 # /etc/init.d/spindown status name watched active idle-time sdb 1 0 66 # ls /.../filesystem-on-sdb ... wait a moment... ... listing appears... # /etc/init.d/spindown status name watched active idle-time sdb 1 0 119 ... wait a moment... # /etc/init.d/spindown status name watched active idle-time sdb 1 1 3

While hard disks will always fail, you might be able to keep a filesystem around on a RAID a little bit longer by spinning down disks when not in use. If you shuffle your data around to put infrequently accessed data on old disks that are spun down, you might have to spin up the disks only once every 3-6 months. With this approach, you get to have the data available quickly without manual interaction and also keep the disks in their dormant state when you are not interested in the data they contain.

Categories:

  • Storage
  • Tools & Utilities