How to Let Drives Spin Down

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Many of us want to have drives in one or more pools/volumes go into standby (i.e., stop spinning). I'm no expert, but I was able to do it finally and understand most of what is going on. As cyberjock has said, FreeNAS is not really designed for this, so it's like fitting a round peg in a square hole. Still, the developers left open the possibility.

Note that many of the experts here will tell you that drives last longer if they just keep spinning rather than stopping and starting, and even that less energy and resources are consumed by letting them spin than starting and stopping them and having to manufacture and ship replacement drives. I have no argument with any of that. But some of us may want to have drives spin up once a day (or less) for a task and then spin down.

There are several caveats:
  1. The first thing to know is that you can't spin down a volume that the system dataset is on. By default, this is the first volume you created. The system dataset gets written to constantly. You can set it to another volume in System > System Dataset (also check Syslog and Reporting Database). Ideally you would put that in a special volume on a solid state drive (SSD) or a SataDOM. I have a SSD in a USB enclosure left over from upgrading the drive in a laptop and it works fine plugged into a USB port. USB flash drives are not recommended as the constant writing is hard on them.

  2. This will be a dealbreaker for some people: If there are shares on the volume you put in standby, it will spin up any time someone logs into the server, even if they are going into a different volume (does not apply to SSH). FreeNAS, in its wisdom, spins up all disks in volumes that have shares, even if you are going for a share on another volume. I have not tested whether this is true when the person logging in has no access privileges to that share.

  3. Another caveat is that you can't do this power management stuff through an add-on card, at least not the one I have, LSI 9240-8i flashed to IT mode. I read somewhere that the FreeBSD developers decided that supporting that functionality is not going to happen. So I can control disks attached to the motherboard SATA ports, but not to the card. The GUI lets you make settings on disks attached through the card, but they have no effect. In my case, I have my main volume on the disks on the card, spinning 24/7, and a backup volume on disks on the motherboard, spinning up once a day to receive replication tasks.
If you still want to do it, here are the steps:
  1. If you need to find out which disks are in the volume you want to spin down, go to Storage > Volumes and click on the volume. Then click the Volume Status icon at the bottom. Under the raid configuration the drives are listed. Note the names (ignore the p2 on the end).

  2. Go to Storage > Volumes > View Disks. Click on the first of the disks in the volume and click the Edit button at the bottom. "HDD Standby" is the standby timer: number of minutes the disk is idle before it should go into standby. Set Advanced Power Management to 127 (I'm not sure this is needed as -- says APM is off on my drives). Click OK and do the same for all drives in the volume.

  3. Go to Services > S.M.A.R.T. Settings. Set Power Mode to Standby. This means SMART won't check the drive (and spin it up), if it is in Standby mode (spun down).
That's all there is to it. But beware of the following (yup, two more caveats):
  1. Anything you do to access the volume, even indirectly, will spin it up. This includes creating or editing any share or task, snapshot, replication, rsync, etc., on that volume. If you click on Storage > Snapshots, FreeNAS will spin up all volumes to look for snapshots (I'm not sure if this is true when there are no snapshots on the volume). SSH into the server does not spin it up unless you do something in that volume. An noted above, any login to any share will spin up all volumes with shares.

  2. If you or a script does a smartctl command on that disk, it may affect the standby state. If the disk is spinning, any smartctl command on it will reset the standby timer. If the disk is in standby, smartctl will spin it up to execute the command unless the "-n standby" option tells it not to.
You can put a disk in standby manually. The following commands are equivalent, putting disk /dev/ada0 into standby and setting the standby timer to 10 minutes (600 seconds):
Code:
sudo camcontrol standby /dev/ada0 -t 600
sudo ataidle -S 10 /dev/ada0

If like me, you have no direct way to tell if drives are spinning, various scripts are available to help. One strategy is based on a camcontrol command. It is nice because, in my testing, it did not reset the standby timer if the disk was spinning. So I could poll the drives every minute and whatch when the went to sleep. However, it doesn't work when you have drives attached through a card.

I now use one based on the return value of a smartctl command, based on a script by joeschmuck. It asks you how often you want the disks checked and prints a compact table headed by drive labels and with each line getting a timestamp. Beware that it will keep your drives awake if the chosen check interval is shorter than the standby timer. As a bonus, the script gives the temperature of the drives that are spinning.

If you want to run it for a while, log in via SSH and start a tmux session first by typing "tmux". Call the script with sudo ./spincheck.sh. The log, spincheck.log, will will get the ouput forked from inside the script. This will keep logging after your SSH session ends. You can monitor progress with "cat spincheck.log". You have to "tmux attach" to get back to the session to end the script with Control-C.

Here's a sample of the output:
Code:
[jim@Tabernacle ~]$ sudo bin/spincheck.sh
How many minutes do you want between spin checks?
15

          da0      da1      da2      da3      ada0     ada1     ada2     ada3
12:20:28  Spin 30  Spin 31  Spin 32  Spin 31  Spin 28  Spin 30  Spin 28  Spin 28
12:35:29  Spin 31  Spin 31  Spin 33  Spin 32  Spin 29  Spin 31  Spin 29  Spin 29
12:50:29  Spin 31  Spin 31  Spin 32  Spin 32  STANDBY  STANDBY  STANDBY  STANDBY  


And the script:
Code:
#!/usr/local/bin/bash
# spincheck.sh version 2016-07-02; should work for any board.
# Run as superuser. See notes at end.

# Creates logfile and sends stdout and stderr to the log,
# leaving the previous contents in place. If you want to append
# to existing log, add '-a' to the tee command.
LOG=spincheck.log
exec > >(tee -i $LOG) 2>&1

SP=33.57   #  Setpoint mean temperature, for information only

function get_disk_name {
# The awk statement works by taking the $LINE as input,
# setting '(' as a _F_ield separator and taking the second field it separates
# (ie after the separator), passing that to another awk that uses
# ',' as a separator, and taking the first field (ie before the separator).
# In other words, everything between '(' and ',' is kept.
   DEVID=$(echo $LINE | awk -F '(' '{print $2}' | awk -F ',' '{print$1}')
}

function print_header {
   # Header is printed when script starts and each new day
   DATE=$(date +"%A, %b %d")
   echo $DATE
   echo -n "  "
   while read LINE ; do
     get_disk_name
     printf "%-8s" $DEVID
   done <<< "$DEVLIST"     # while statement works on DEVLIST
   printf "%4s %5s %4s %-8s %s \n" "Tmax" "Tmean"
}

function data {
   if [[ $i > 0 ]]; then
     Tmean=$(echo "scale=2; $Tsum / $i" | bc)
     ERRc=$(echo "scale=2; $Tmean - $SP" | bc)
   else
     Tmean= ; ERRc= ; Tmax=
   fi
   # print current data
   printf "^%-3d %5.2f" $Tmax $Tmean
   printf "  ERRc= %5.2f\n" $ERRc
}

echo "How many minutes do you want between spin checks?"
read T
SEC=$(bc <<< "$T*60")       # bc is a calculator

# Get list of drives; remove SanDisk
DEVLIST1=$(camcontrol devlist)
# Remove lines with flash drives or SSD; edit as needed
# You could use another strategy, e.g., find something in the camcontrol devlist
# output that is unique to the drives you want, for instance only WDC drives:
# if [[ $LINE != *"WDC"* ]] . . .
DEVLIST="$(echo "$DEVLIST1"|sed '/KINGSTON/d;/ADATA/d;/SanDisk/d')"
print_header

# Main loop
while [ 1 ] ; do
   # Print header every quarter day.  Expression removes any
   # leading 0 so it is not seen as octal
   HM=$(date +%k%M); HM=`expr $HM + 0`
   R=$(( HM % 600 ))  # remainder after dividing by 6 hours
   if (( $R < $T )); then print_header; fi
  # print time on each line
   TIME=$(date "+%H:%M:%S"); echo -n "$TIME  " 
   Tmax=0; Tsum=0  # initialize drive temps for new loop through drives
   i=0  # count number of spinning drives
   while read LINE ; do
     get_disk_name
     TEMP=$(smartctl -a -n standby "/dev/$DEVID" | grep "Temperature_Celsius" | grep -o "..$")
     smartctl -n standby "/dev/$DEVID" > /var/tempfile
     RETURN=$?     # need to preserve because $? changes with each if comparison
     if [[ $RETURN == "0" ]] ; then
       STATE="Spin"
     elif [[ $RETURN == "2" ]] ; then
       STATE="STANDBY"
     else
       STATE="UNKNOWN"
     fi
     printf "%-8s" $STATE" "$TEMP
     # Update temperatures each drive
     if [ $STATE == "Spin" ] ; then
       let Tsum=$Tsum+$TEMP
       if [[ $TEMP > $Tmax ]]; then Tmax=$TEMP; fi;
       let "i += 1"
     fi
  done <<< "$DEVLIST"
   data  # manage data
  sleep $(($T*60)) # seconds between runs
done

# Logs:
#  - disk status (spinning or standby)
#  - disk temperature (Celsius) if spinning
#  - max and mean disk temperature
#  - fan rpm and mode
#  - current and new fan duty cycle
#  - optional diagnostic variables
# Includes disks on motherboard and on HBA.

# Uses joeschmuck's smartctl method (returns 0 if spinning, 2 in standby)
# https://forums.freenas.org/index.php?threads/how-to-find-out-if-a-drive-is-spinning-down-properly.2068/#post-28451
# Other method (camcontrol cmd -a) doesn't work with HBA
 
Last edited:

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
This is somewhat obsolete now it seems. Recent updates bring additional changes that spin drives up for no apparent reason. One that is like clockwork is the daily maintenance tasks at 3 am. The rest are at odd times. Sometimes only one or two drives of a pool will be spinning. I wish the developers would at least somewhat accommodate those who want to use the power management features they put in the GUI.
 

wintermute000

Explorer
Joined
Aug 8, 2014
Messages
83
what I really want is a way to let drives spin up concurrently.
I have six spinning platters and it takes ages for them to spin up as they are doing it sequentially.
It may be more of a BSD issue than freenas but either way searching extensively for the issue I've come up with blank.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
what I really want is a way to let drives spin up concurrently.
I have six spinning platters and it takes ages for them to spin up as they are doing it sequentially.
It may be more of a BSD issue than freenas but either way searching extensively for the issue I've come up with blank.

More of a general computing issue. You're putting the hardware in a state none of the software is set up to deal with; neither ZFS nor FreeBSD are aware that you've spun down the disks, and there's no code to deal with that and spin up the disks.

This would require significant rearchitecting to handle it correctly. What's happening now is that as ZFS attempts to write to each drive, you get a stall until it spins up.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
I've seen a lot of people WANTING that feature. As I recall it is something controlled by some motherboards. Have you checked your MB settings?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
It isn't controlled by the motherboard, at least not for the purposes of this discussion.
 

paylesspizzaman

Explorer
Joined
Sep 1, 2015
Messages
92
This is somewhat obsolete now it seems. Recent updates bring additional changes that spin drives up for no apparent reason. One that is like clockwork is the daily maintenance tasks at 3 am. The rest are at odd times. Sometimes only one or two drives of a pool will be spinning. I wish the developers would at least somewhat accommodate those who want to use the power management features they put in the GUI.
Is there a way to disable all these processes that wake the drives? Or at least make it where they won't run unless the disk is already spinning...
 
Last edited:

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Is there a way to disable all these processes that wake the drives? Or at least make it where they won't run unless the disk is already spinning...
s there a way to disable
Maybe for a very high-level expert, but I think it would require rewriting the OS. If you can easily offload the system dataset and have no jails actively using the pool, I suggest you try spinning the drives down yourself and see if your experience is like mine.

What older version of FreeNAS would I have to run to get away from the new unneeded waking events?
Sorry, I don't know exactly. Maybe mid-2015 if you go back through the versions.
 
Last edited:

enemy85

Guru
Joined
Jun 10, 2011
Messages
757
i don't think you can...FN is designed this way, so if you can't stand this design probably is easier to find a different OS that better suits your needs
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
What's more likely is that some dev inadvertently enabled something that's touching the pool. Since a TrueNAS system never spins down its disks and a FreeNAS system should never do so either, I'm guessing it's more a matter of "no one's noticed" plus "no one's that interested in looking into it."

So there's potentially some good self-help available here if you choose to try; take a careful look at what's going on in the system at the moment the unwanted spin-ups occur. This especially includes things that are logged to syslog, etc.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
...FN is designed this way . . .
Since a TrueNAS system never spins down its disks and a FreeNAS system should never do so either . . .
Let's not forget that the developers put controls into the GUI that allow you to put the disks in standby. So I wouldn''t say it's designed not to. They should either remove those controls or fix the inadvertent and needless spinning up of disks.
 

paylesspizzaman

Explorer
Joined
Sep 1, 2015
Messages
92
i don't think you can...FN is designed this way, so if you can't stand this design probably is easier to find a different OS that better suits your needs
So then the question becomes, is it worth moving away from zfs just to be able to spin-down disks. I think I would personally rather pay for the extra 30 watts to know my data is safe with zfs. That said, I am still interested in spinning down disks.
 

paylesspizzaman

Explorer
Joined
Sep 1, 2015
Messages
92
What's more likely is that some dev inadvertently enabled something that's touching the pool. Since a TrueNAS system never spins down its disks and a FreeNAS system should never do so either, I'm guessing it's more a matter of "no one's noticed" plus "no one's that interested in looking into it."

So there's potentially some good self-help available here if you choose to try; take a careful look at what's going on in the system at the moment the unwanted spin-ups occur. This especially includes things that are logged to syslog, etc.
The problem with me doing this is I'm totally a "Windows" user, so obviously terrible with anything command line. My first computer was an XP machine. Hacking to me is opening cmd and typing ipconfig. At some point, I probably will try to figure out what is spinning the disks up though. Hopefully the people on these forums will continue to be awesome and as helpful as usual to me.
 

paylesspizzaman

Explorer
Joined
Sep 1, 2015
Messages
92
Let's not forget that the developers put controls into the GUI that allow you to put the disks in standby. So I wouldn''t say it's designed not to. They should either remove those controls or fix the inadvertent and needless spinning up of disks.
This is true. You would think they would take out those settings if they are NOT intended to be used. On that note, I am having trouble figuring out advanced power management and hard drive spin-down on my FreeNAS server. What exactly does the "advanced power management" do? I read that an APM setting of 1-127 permit spin-down, while 128-255 do not, but haven't been able to find anything conclusive beyond that. I also read that the spin-down setting is in intervals of 5 seconds for settings 1-240 while settings 241-254 are in 30 minute intervals. Is that true for the FreeNAS GUI setting? Via the GUI, I set my spin-down to 240, which I thought would be 20 minutes and APM to 1. However, the drives spin-down much quicker than 20 minutes after I access them. My system is: FreeNAS 9.3.1, Supermicro X10SDV-4C-TLN2F, 2x Samsung M393A4K40BB0-CPB 32GB DDR4-2133, 1x GH-PELY423 Bifurcation adapter, 1x Intel Pro 1000 EXPI9402PT dual port, 1x IBM M1015 IT mode P20 firmware, 1x HP 468405 SAS expander, 16x 4TB Seagate Green HDDs 2 8disk Z2 vdevs striped, 3x 2TB Seagate Green HDDs 3 disk Z1 vdev, Seasonic X850 Gold PSU.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
what I really want is a way to let drives spin up concurrently.
I have six spinning platters and it takes ages for them to spin up as they are doing it sequentially.
It may be more of a BSD issue than freenas but either way searching extensively for the issue I've come up with blank.
Actually spinning up drives sequentially is typically be design to reduce power surges on your power supply. Imagine if you have 20 drives and you tried to spin them all up at once. The power draw would be substantial and what if the power drop caused instability in your system. I prefer sequential powering up of my drives.

This is somewhat obsolete now it seems. Recent updates bring additional changes that spin drives up for no apparent reason. One that is like clockwork is the daily maintenance tasks at 3 am. The rest are at odd times. Sometimes only one or two drives of a pool will be spinning. I wish the developers would at least somewhat accommodate those who want to use the power management features they put in the GUI.
Is this for a clean virgin FreeNAS installation, no jails, nothing but a bare NAS running? Regardless of where your jails are located, if you have a shared space on the pool and the jail tries to access it, well things don't sleep very well. With some methodical testing I'd think you could figure this out. I am curious about the 3AM wake-up though, that could be something you can't get around if you have already moved your System Dataset and Jails/Plugins off the pool.

But in reality, there are a lot of folks here who can speak from personal experience, hard drives in general will last longer if you don't spin them up frequently. My drives are well over the 3 year warranty period and they run 24/7 with me shutting the system down a few times a year to blow any dust out of the case and power supply. I do have all my jails and System Dataset on the pool as well, it keeps the heads active which I prefer. I know I'm promoting just leaving your drives spinning, not the title of this thread. I'll stop peddling my wares now.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Via the GUI, I set my spin-down to 240, which I thought would be 20 minutes and APM to 1. However, the drives spin-down much quicker than 20 minutes after I access them.
No, the GUI setting is in minutes, as described in the user guide. How are you determining when the disks spin down?
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Is this for a clean virgin FreeNAS installation, no jails, nothing but a bare NAS running? Regardless of where your jails are located, if you have a shared space on the pool and the jail tries to access it, well things don't sleep very well. With some methodical testing I'd think you could figure this out. I am curious about the 3AM wake-up though, that could be something you can't get around if you have already moved your System Dataset and Jails/Plugins off the pool.
No, there are jails, but the pool I was trying to keep in standby has no system dataset, no jails, no jail storage, and no shares.

Methodical testing would probably take more knowledge than I have. More importantly, it is not worth it to me to nuke my setup and go back to fresh install and empty system. If that's what it takes to get drives to standby reliably, nobody is going to be able to use that feature anyway.
 

paylesspizzaman

Explorer
Joined
Sep 1, 2015
Messages
92
No, the GUI setting is in minutes, as described in the user guide. How are you determining when the disks spin down?
I have my system plugged into a wattmeter and listen for the spin-ups. I also ran the smartctl -a -n standby /dev/daX and what it returns aligns with what the meter says. If the spin-down setting is in minutes, it must not work properly, or the APM setting overrides it. I do not have any jails installed, system dataset is on the boot drive and I do NOT have any jails installed. Changing the APM setting from 1 to 64 changes the power consumption to a sort of mid-level. I'm really curious what APM is actually doing?
 
Top