Zum Inhalt springen

Raid5 array in standby using hdparm

These days electricity is getting more and more expensive. As my Ubuntu Server (12.04 LTS) is running 24 hours a day, any saving in regard to power consumption is most welcome. So today I decided to set up hdparm to automatically put my 4 drives in a Raid 5 array into standby after 15 minutes idle time using a little program called hdparm. Here the basics of what I did to set it up.

Test and configure hdparm

List drives in array

First we need to get a list of the drive names in the array. As I use mdadm as a software array, this is easiest done with the following command:

root@server:~# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid1] [raid10]
md0 : active raid5 sdb[0] sdg[3] sdf[2] sdc[1]
      1465159488 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]

Testing hdparm

So, now I know that my md0 array has the following drive (device) names /dev/sdb, /dev/sdc, /dev/sdf and /dev/sdg. Change the drive names according to your own system. To do a quick test if hdparm will work, enter the command below (Note: 60 represents 60 * 5 seconds = 5 min.):

root@server:~# hdparm -S 60 /dev/sd[bcfg]
/dev/sdb:
 setting standby to 60 (5 minutes)
/dev/sdc:
 setting standby to 60 (5 minutes)
/dev/sdf:
 setting standby to 60 (5 minutes)
/dev/sdg:
 setting standby to 60 (5 minutes)

This should set the 4 drives into standby after 5 minutes. After 5 minutes check to see the current state of the drives with the following command:

root@server:~# hdparm -C /dev/sd[bcfg]
/dev/sdb:
 drive state is:  standby
/dev/sdc:
 drive state is:  standby
/dev/sdf:
 drive state is:  standby
/dev/sdg:
 drive state is:  standby

If you don't see the word standby then you may need to activate ACPI in your bios. Now, we can change the spindown time to the value we actally want. Enter the changed hdparm command as follows:

root@server:~# hdparm -S 180 /dev/sd[bcfg]
/dev/sdb:
 setting standby to 180 (15 minutes)
/dev/sdc:
 setting standby to 180 (15 minutes)
/dev/sdf:
 setting standby to 180 (15 minutes)
/dev/sdg:
 setting standby to 180 (15 minutes)

To keep those settings after reboot you would normally just edit your /etc/hdparm.conf and add the following block to the end of the file.

/dev/sd[bcfg] {
        mult_sect_io = 16
        write_cache = off
        spindown_time = 180
}

However, the settings in /etc/hdparm.conf don't seem to be respected in my Ubuntu 12.04 LTS installation. As a workaround for this I call up a little script that is executed at startup. Create a file in /usr/local/bin/ and name it hdparm_start.sh with the following content:

#!/bin/bash
sleep 10
hdparm -S 180 /dev/sd[bcgf]

Create the file as root and chmod that file with 0755. Then edit your /etc/rc.local and add before the exit 0 line.

#start hdparm script
/usr/local/bin/hdparm_start.sh

exit 0

Reboot and have a look in the /var/log/boot.log file to see if the script executed. That worked for me!

Power consumption savings

I was able to reduce the server power consumption by 13 Watts by just spinning down the 4 drives in the array. When accessing a file on the raid when the drives are sleeping will initially take a few seconds at the beginning, but it's worth the wait.

Kommentiere diesen Artikel

Kommentar (erforderlich) (keine Anzeige) (optional)
Ja, erkenne mich, wenn ich das nächste mal hier bin