FreeNAS is a pretty great (and free!) Network Attached Storage system. Recently, it was updated to version 9.3 which contained a lot of great improvements including automatic updates over the network. (Previously, the upgrade process was manual and kind of a pain in the neck.)
Unfortunately, FreeNAS isn’t very good at the power-saving thing. (read: spinning down your hard drives when they’re not being used.) And prior to FreeNAS 9.x, it was pretty easy to get the drives to go into Standby mode using a few commands. But again, FreeNAS has changed the default install to put the system log (which it writes somewhat regularly to) on the very drives you’re trying to spin down.
Fortunately, there is a fix.
Looking around the Internet, I came up with a page about the inability to spin down drives on the FreeNAS forums as it seems some other people were having the same problem. Yet only vague answers were given. Some of the posts were generally dismissive of the idea of saving 15 watts per hour by spinning down the 4 hard drives in somebody’s array. Fortunately, someone alluded to a fix for the problem by noting that the .system file/folder could be relocated to an SSD or a USB flash drive and that this would allow the drives to fully go idle and allow the spin down commands to work.
After much tinkering, I came up with a method for getting my drives to go spin down after being idle for a few minutes. Here is is:
Attach a USB Flash drive or an SSD
When I originally wrote this, my choice was a SanDisk Ultra Fit 16GB drive which I had laying around after the review I wrote on it a few months ago.
After talking with a Freenas forum member who had a FreeNAS box that was used more heavily, they informed me that their FreeNAS .system dataset gets 2GB of writes per hour! That’s ~100x more writes!
Naturally, moving the .system dataset off to a USB flash drive would be a bad idea as it would quickly wear out the drive in, say, a month’s time. In the same breath, it should also be noted that if your FreeNAS box is getting that much use, you really shouldn’t bother trying to spin down your hard drives at all.
Which to pick: a USB Flash drive? or an SSD?
Both use a form of wear-leveling to prolong the life of the drive by spreading out the writes evenly across the NAND flash memory. But to me, it comes down to your use case:
Is this going to be a light-duty home NAS box? (read: holds your MP3s and Movies and maybe some backups or other files) and will generally stay idle most of the time?
If Yes, it is going to be a home NAS, then a USB flash drive will probably be fine. The larger, the better. (More space to spread out the writes. I chose 16GB, though 32GB might be better.)
If No, it is going to be a small office NAS (or you just want a better guarantee of reliability), then pick up a small 32GB or 64GB SSD. It should be robust enough to handle the repeated writes of the .System dataset.
Add the drive via the Volume Manager
In the FreeNAS web console, click on: Storage -> Volume Manager
Call it whatever you want. I figured a name like “dotsystem” would be a good one since that’s where we’re moving the “.system” data.
Click on the [+] icon under Available disks
Add Encryption if you wish. I figure it may slow down the system a bit, though. So I kept it simple and left it disabled.
Also, we’re not extending any volumes, so leave the “Volume to Extend” option as “—–“.
After clicking the plus icon (+), the window will change and show that the proposed addition. You can drag the little circular handle/knob thing back and forth, but there’s likely only 1 size when using a 16GB drive.
Then click, Add Volume. The Volumes tab should look something like this:
Change your System Dataset Pool location
Next, click on System -> System Dataset
Then click on the “System dataset pool” drop down and change it to our newly created pool. In this example, we chose the name “dotsystem“.
And then click the Save button.
Set the “ataidle” command to run at Startup
The ataidle command can get your hard drive to spin down immediately or after the drive has been idle for a certain period of time.
Go to the Tasks -> Init/Shutdown Scripts section of FreeNAS and add the following commands as tasks and select the “postinit” option:
This command instructs device ada0 (your 1st hard drive) to go into standby (spin down) after being idle for 5 minutes. Adjust this delay number to your wishes. Many people choose 5, 15, 30, or 60 minutes. (Note: the switch is a capital “S” and not a lowercase “s”.)
/usr/local/sbin/ataidle -S 5 /dev/ada0
In the screenshot above, the ZFS storage array has 4 disks: ada0 through ada3.
Adjust your configuration accordingly by adding or subtracting commands and changing adaX to reflect which drive number (ada0, ada1, ada2, etc.) depending on how many disks are in your array.
Test that the drives actually go into Standby
To make sure that the drives are capable of spinning down when idle, we need to start by disconnecting the FreeNAS from the network so that nothing attempts to use the NAS.
Then we launch the Shell and issue the following command:
camcontrol cmd ada0 -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r -
This command tests drive ada0 to see if it is in Standby mode or not. If you receive the following response where the second to last group is a “00”:
50 00 00 78 00 00 00 00 00 <span style="text-decoration: underline;"><strong>00</strong></span> 00
Then that single drive is in Standby.
If the response is where the second to last group is “FF”:
50 00 00 78 00 00 00 00 00 <span style="text-decoration: underline;"><strong>FF</strong></span> 00
Then the drive is still spinning.
To instruct a drive to immediately go into Standby mode, issue the following command:
ataidle -s /dev/ada0
(note the lowercase “s”)
This instructs the drive ada0 to immediately attempt to go into Standby mode. After waiting a few seconds, you can re-issue the “camcontrol” command above and you should see that the 2nd to last group is now “00” indicating that it is in Standby.
Another way to verify the spin down of the drives
If you don’t have one already, you should consider getting yourself a Kill-A-Watt power measurement device ($19). Instead of issuing those convoluted commands, if you have a Kill-A-Watt, you can hook-up your FreeNAS box and watch in real-time as the “ataidle” command causes your box to draw less power.
In my experimentation, I found that my FreeNAS box uses approximately 50 watts when idle and all 4 of the disks are spinning. But when the 4 drives in the array are in Standby mode, the FreeNAS box uses only 35 watts! (A savings of 15 watts per hour.)
Assuming that I only use the NAS for 1 hour per day, that’s a savings of around 345 watts per day. That’s a savings of 125kWh per year (or about $20 in electricity costs.) Naturally, your results may vary, but I think it is a worthwhile effort to save a little extra electricity.
Will the USB Flash drive wear out prematurely?
Possibly. And if it does, you might be a sad camper unless you’re backing up your “.System” data. Which, I should add, is only semi-important.
Yes, apparently, there is little risk of losing your data, but if the USB flash drive dies, it could hose your Domain Controller if you’re using Active Directory. If you’re using SMB file sharing, it will lose all of your Samba settings. So fair warning here before you try this procedure.
The general consensus (from all the reading I’ve done) is that if the USB flash drive dies, you will not lose your data. It will just force you to re-install FreeNAS from scratch. Not a tragedy, but certainly a waste of time.
If you’re wondering how to backup your “.system” dataset? Good question. I’m currently looking into using rsync as well as ZFS send/receive. I’ll update this section when I have a good way of doing it.
There seems to be some concern in the FreeNAS forum about this procedure that a USB flash drive will wear out quickly. Personally, I’m not convinced this will happen for light-duty use cases. Here’s why:
From my observations so far, the files in “.System” take up about 90MB and the Reporting Tool in FreeNAS web interface indicate that the “dotsystem” volume gets about 289MB of writes over a 2-day period meaning that in 1 year, the volume will get around 54GB of writes. That’s not a whole lot of writes for a 16GB drive.
(Your mileage may vary, of course. If your NAS gets a ton of traffic, then there will be a lot more writes to the system log. This leads to the question: If your NAS is constantly busy, should you really bother trying to spin down the disks?)
Most USB Flash drives have dynamic wear-leveling algorithms built in. Although dynamic wear-leveling isn’t typically as robust as static wear-leveling (often found in SSDs), a large USB Flash drive should be good enough to evenly wear the drive’s flash cells over the lifetime of the NAS since the “.System” data takes up so little space. (See this Wikipedia entry on Dynamic Wear-leveling if you’re curious about how this works.)
In order to safeguard against pre-mature failure of a USB flash drive, the larger the drive used in this procedure, the better off you’ll be as there is more space on the drive to spread out the writes for the wear-leveling. In this post, I decided that a 16GB flash drive (many of which can be had for $15 or less) would be more than enough. Definitely don’t use an old 512MB flash drive; that will be a bad candidate for this procedure.
Unfortunately, I don’t know where the “sweet spot” or what the minimum size is for a USB Flash drive in this procedure. Anyway, I will certainly be keeping an eye on this flash drive and will definitely update this post if anything changes. 🙂
If you liked this article, please help spread the word using one of the social networking sites below. Thanks!