Saving Power on Your Custom Home NAS

Saving Power on Your Custom Home NAS

Electricity use is something that has gotten away from us as a society. Recent conversions to CFL or LED lighting has certainly helped, and LED flat panel TV's have dramatically reduced their power needs. The big consumer now is your refrigerator and your computer(s).

There's a couple of things you can do to have more energy efficient computers, including liberal use of sleep or hibernate modes. With a NAS server though you don't want to have to wake up the server every time you need a file. There's a happy medium you can take.

Simply this: spin down your hard drives. A NAS typically has more than 1 large hard drive, and those things can be power hungry.

Find your drives...

I'm assuming you run Ubuntu Linux but these commands should be effective on any flavor of Linux. Making them run at startup may vary by distribution.

First, locate the hard drives' paths you will be powering down. One way to do that is:

ls -l /dev/sd*

That command will list all of your SATA drives on the system. Since my OS drive is an SSD located at /dev/sda I ignore it.

Now, for each drive in the server you want to power down run the following:

hdparm -S 180 /dev/sd[*]

Replace the sd[*] with the proper drive location. My commands look like this:

# Set harddrive spin down to 15 minutes:
hdparm -S 180 /dev/sdc
hdparm -S 180 /dev/sdd
hdparm -S 180 /dev/sde
hdparm -S 180 /dev/sdf

That will make my four data drives spin down after 15 minutes of inactivity. The downside is a slight delay when I start to access data on one of those drives (sometimes up to 3 seconds) but the power savings can be large.

Make it run at boot:

Now, take those commands and add them to your /etc/rc.local file just before the "exit 0" line using Nano or your favorite editor:

sudo nano /etc/rc.local

Make that file look something like:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Set harddrive spin down to 15 minutes:
hdparm -S 180 /dev/sdc
hdparm -S 180 /dev/sdd
hdparm -S 180 /dev/sde
hdparm -S 180 /dev/sdf

exit 0

And there you have it!

Also, if you build your own machines, be sure to opt for the 80 plus gold or platinum certified power supplies - they are much more energy efficient. With rising energy costs in a few months you'll more than make up for the extra few bucks spent on the better power supply.

Posted by Tony on Feb 15, 2016 | Linux Tricks, Servers