How to Let Drives Spin Down

mattbbpl

Patron
Joined
May 30, 2015
Messages
237
I know a guy who took something like a hundred USB thumb drives and made a ZFS pool out of them, because he got them for free as trade show leftovers. While cool, I wouldn't want to store my data on it.
I'm on the fence about whether I should be impressed or disgusted, but... dang.
 

Montel Bahn

Dabbler
Joined
Oct 12, 2015
Messages
40
I'm on the fence about whether I should be impressed or disgusted
Me too. .. Not sure if it's all like shibboleths, designed to waste cpu cycles of independant minded individuals. Murica!!
 

Montel Bahn

Dabbler
Joined
Oct 12, 2015
Messages
40

ornstedt

Dabbler
Joined
Apr 26, 2014
Messages
10
I want to thank everyone for all their time, effort and suggestions, but I am giving up on this and running any scripts. I'm marking it in my mind as impossible. I did try the most recent suggestions, which still didn't work. With the NFS/UNIX dtaset/share I can't mount it, even with NFS turned on in windows 7. I tried copying to /usr/local/sbin and I think it did copy, but I either get permission denied or or not found when trying to execute. Also, the script posted in the first post, I remember it being different than it currently is. Did someone change it or is my mind playing tricks on me?

I bet that all of these problems are caused by an incorrect first line in the script.
It is essential that the first line is verbatim as the line below.

#!/usr/local/bin/bash

You can easily check this with the command.

head spincheck.sh

If not you will get the error message you have seen.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
So the GUI/scripts wants to know what spindown setting to tell the drive,

Correct.

but it's going to access the drive in secret regardless, thus keeping it spinning??????

Many different things within the system might be touching the pool. FreeNAS is built upon FreeBSD, which is itself a moving target.

No matter how long-winded or brief you choose to be, DON'T BE GENTLE! I only ask for accuracy and precision.

To your tangential points about NFS, iSCSI.... obviously I'm testing with all my services turned off, I'm noobish but what's with the red herrings of confusion?

Those aren't tangential points. The point is that FreeNAS itself isn't actually involved in processing the protocols that are being served to the network. When a NFS request comes in from the network, it goes through the TCP stack, into the kernel NFSD thread, which then hands it off to ZFS to read the data. ZFS issues the requests to the disk subsystem, which fulfills the request, returning it to the NFSD thread, which then passes it onto the network. At no point is the FreeNAS middleware involved, which means that FreeNAS has no particular opportunity to manage disk spinup when an access occurs.

What I CLEARLY wrote is any plain ol' script (OBVIOUSLY) can know/inquire as to the state of the disk. Again, any constructive advice/insight is appreciated!
Thus FreeNAS .py files shouldn't wake the drives for ANY reason, per the current docs, let alone in such a long-standing troublesome manner (see multitude bug reports and forum postings)

The very act of inquiring about the state of a disk can be sufficient to wake a disk up.

If you can find a place where a FreeNAS .py file is waking the disks without a reason, submit a bug report.

If you can find a place where a FreeBSD system utility, maintenance script, etc., is waking the disks, also submit a bug report.

But there are a whole bunch of problems relating to drive spindown/spinup, which in general is a very complicated topic. It isn't just "my system woke up at some random time", but also goes to much more complex things such as staging of disk spinups in a staggered manner to manage PSU load, optimizing spinups to only spin disks that need to be spun, etc.

I'm straining my noobish mind here but if the issue is that drives behind HBA cards sometimes don't reveal/or allow spindown/sleep state or whatever, that is also manageable in the GUI code. At the very least it should be disclosed rather than obfuscated.

We deal in the realm of PC hardware around here, where very few things are reliably deterministic. There's no guarantee that any given bit of hardware will support a given feature, or that it will even be detectable that it doesn't support a feature. One kind of hard drive will wake up when you talk to it with SMART while another won't. Etc.

But basically here's how this breaks down.

The developers give us FreeNAS for free, it's their way of validating the foundation for TrueNAS, their paid product. I doubt anyone is spinning down disks on TrueNAS, but if/when someone does, and files a bug report, issues related to this will be much more likely to get looked into.

You have access to the FreeNAS box, plus also the source code. You're welcome to locate any problems and submit bug reports, or even to patch the code and submit the patch.

However, since there's a hell of a lot of work that the TrueNAS guys have on their plates to continue creating a viable, sellable product, and since issues with spinning down/up disks isn't among them, my guess is that this isn't going to get a lot of traction. You could try shipping them a case of beer and asking them to look into it.

Re: FreeNAS is a framework... (is that the same as nested wrappers?) where could I find docs regarding this? I have predisposed bias in favor of bsd and zfs, but so far FreeNAS is harshing my buzz.

Your buzz is artificial. FreeNAS is a framework. In a traditional BSD system, you have to manually create your ZFS filesystem, and you have to edit /etc/exports for NFS exports, enable certain things in /etc/rc.conf for NFS service, and then install various bits of software to do reporting and monitoring. And you need to do that for each protocol and thing you want to do with the server. With FreeNAS, someone has done all the hard work, and has presented it under a unified management portal. Underneath, it is still pretty much a standard NanoBSD image of FreeBSD, and FreeNAS configures all that stuff for you. That's what the framework is.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
This is educational and sad/disappointing at the same time.
And sorry for piling-on. I don't want to be belligerent but forums, bug report and blogs are full of seemingly pointless discussions on this matter.
https://forums.freenas.org/index.php?threads/hdd-standby-spindown.10763/
Over the course of many years, versions.

Yes, because it's an incredibly complicated topic. What you're identifying as a single topic is actually closer to a dozen different somewhat related issues.
 

meku

Dabbler
Joined
May 4, 2014
Messages
34
Very helpful topic, and thanks to this script I can verify that HDD will enter standby.

I would like to highlight this from the OP:
If the disk is spinning, any smartctl command on it will reset the standby timer.

Meaning that even running the spincheck.sh script can prevent HDD from entering standby, so make sure the minutes between checks is greater than the HDD standby timer.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Very helpful topic, and thanks to this script I can verify that HDD will enter standby.
I'm glad it worked for you. Please report back after you have several days of spincheck.log and let us know if the results are what you hope for.
To let the spincheck run for that long, you might have to use tmux as described in the first post.
 

meku

Dabbler
Joined
May 4, 2014
Messages
34
Trying to grep my devlist for which disks to test/ignore was getting complicated so I modified the script to get the list of HDD from the FreeNAS database - so this script will only check disks that have a HDD standby timer set in the FreeNAS config. Also had to change the smartctl grep for Temperature_Celcius because "Temp" was returning multiple rows.
Code:
#!/usr/local/bin/bash
# checks at a user-specified interval to see if disk is in standby.
# Also prints disk temperature (Celsius) if spinning.
# Only disks with a HDD Standby timer set in FreeNAS config.
# Must run as super user.

repeat=20        # repeat disk names after x lines

# load freenas config to get access to SQLITE storage
. /etc/rc.freenas

get_disks()
{
        local IFS="|"
        local f="disk_name disk_hddstandby"
        local sf=$(var_to_sf $f)

        ${FREENAS_SQLITE_CMD} ${FREENAS_CONFIG} \
                "SELECT $sf FROM storage_disk WHERE disk_enabled = 1 AND disk_hddstandby <> 'Always On'" | \
        while eval read -r $f; do
                echo $disk_name
        done
}
if [ "$1" -gt 0 ]; then
        SEC=$(($1 * 60))
else
        echo "How many minutes do you want between spin checks? (must be greater than standby timer)"
        read MIN
        SEC=$(bc <<< "$MIN*60")
        echo
fi

s=$(get_disks)
disks=( $s )
count=0

while [ 1 ] ; do
        if [ "$count" -eq 0 ]; then
                echo -n "          "
                for DEVID in "${disks[@]}"; do
                        printf "%-9s" $DEVID
                done
                echo
        fi
        count=$((count + 1))
        if [ "$count" -eq "$repeat" ]; then
                count=0
        fi
        TIME=$(date "+%H:%M:%S")
        echo -n "$TIME  "
        for DEVID in "${disks[@]}"; do
                TEMP=
                smartctl -n standby "/dev/$DEVID" > /dev/null
                RETURN=$?        # need to preserve because $? changes with each if comparison
                if [[ $RETURN == "0" ]] ; then
                        STATE="Spin"
                        TEMP=$(smartctl -a -n standby "/dev/$DEVID" | grep "Temperature_Celsius" | awk '{print $10}')
                elif [[ $RETURN == "2" ]] ; then
                        STATE="STANDBY"
                else
                        STATE="UNKNOWN"
                fi
                printf "%-9s" $STATE" "$TEMP
        done
echo
sleep $SEC
done
 

willrun4fun

Dabbler
Joined
Jan 19, 2016
Messages
29
First Thanks for the writeup! I put in an ssd to put my sysdata on and with a few commands I am saving 30W of power :)

Just one question, the output of the shell script does not line up very nice. Is there a way to fix it?

Code:
Thursday, Jun 30
  ada0     ada1     ada2     ada3     ada4     da0     
16:22:25  Spin 1)  1)       STANDBY  STANDBY  STANDBY  STANDBY  UNKNOWN 
16:27:25  Spin 1)  1)       STANDBY  STANDBY  STANDBY  STANDBY  UNKNOWN 
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
You're welcome. Please try the spincheck script in this post; it is an updated version. Let me know how it goes.

However, that newer script has features that only will work for SuperMicro boards I think. I'll update the one on this post without those features this weekend.
 
Last edited:

willrun4fun

Dabbler
Joined
Jan 19, 2016
Messages
29
That one gives me even more errors. At least the original one works.

Code:
Friday, Jul 01
          ada0    ada1    ada2    ada3    ada4    pass5   Tmax Tmean  RPM MODE     Fan%
05:14:19  Spin 1) 1)      ./spincheck2.sh: line 94: let: Tsum=0+1): syntax error in expression (error token is ")")
STANDBY ./spincheck2.sh: line 94: let: Tsum=1+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 94: let: Tsum=1+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 94: let: Tsum=1+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 94: let: Tsum=1+: syntax error: operand expected (error token is "+")
UNKNOWN ./spincheck2.sh: line 94: let: Tsum=1+: syntax error: operand expected (error token is "+")
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
./spincheck2.sh: line 56: printf: 1): invalid number
./spincheck2.sh: line 56: printf: 1): invalid number
./spincheck2.sh: line 56: printf: .16: invalid number
^1    0.00    0 Standard  0   ERRc= -33.41
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
That one gives me even more errors. At least the original one works.
Hmmm - I just ran it and it works for me. Please check two things:
1. Do you find bash in /usr/local/bin/ ? If not you probably need to install it with 'pkg install bash'.
2. Please post the output of (sudo) 'camcontrol devlist'. You have some different devices there that need to be excluded in the script where I exclude my Sandisk flash drives.
 

willrun4fun

Dabbler
Joined
Jan 19, 2016
Messages
29
Bash is installed.

Code:
[root@freenas] ~# camcontrol devlist
<KINGSTON SV300S37A120G 605ABBF2>  at scbus0 target 0 lun 0 (ada0,pass0)
<Hitachi HUA723020ALA641 MK7OA840>  at scbus1 target 0 lun 0 (ada1,pass1)
<TOSHIBA DT01ACA200 MX4OABB0>      at scbus2 target 0 lun 0 (ada2,pass2)
<TOSHIBA DT01ACA200 MX4OABB0>      at scbus3 target 0 lun 0 (ada3,pass3)
<Hitachi HUA723020ALA641 MK7OA840>  at scbus4 target 0 lun 0 (ada4,pass4)
<ADATA USB Flash Drive 0.00>       at scbus6 target 0 lun 0 (pass5,da0)
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
OK, I gather the Kingston is your SSD, ADATA is obviously a flash drive, so the ones we want are the 2 Hitachis and 2 Toshibas?

I don't have access to my FreeNAS now so can't test, but try this as a test:

Code:
DEVLIST1=$(camcontrol devlist)
DEVLIST="$(echo "$DEVLIST1"|sed '/KINGSTON/d'|sed '/ADATA/d')"
echo $DEVLIST

If the output has just the 4 hard drives, edit the script to replace my SanDisk line with the middle line above, and try it again.
 

willrun4fun

Dabbler
Joined
Jan 19, 2016
Messages
29
ok, the output from the above is:
Code:
freenas# ./test.sh
<Hitachi HUA723020ALA641 MK7OA840> at scbus1 target 0 lun 0 (ada1,pass1) <TOSHIBA DT01ACA200 MX4OABB0> at scbus2 target 0 lun 0 (ada2,pass2) <TOSHIBA DT01ACA200 MX4OABB0> at scbus3 target 0 lun 0 (ada3,pass3) <Hitachi HUA723020ALA641 MK7OA840> at scbus4 target 0 lun 0 (ada4,pass4)


I put that line in my spincheck and get:
Code:
freenas# ./spincheck2.sh
./spincheck2.sh: line 5: If: command not found
How many minutes do you want between spin checks?
5
Friday, Jul 01
          ada1    ada2    ada3    ada4    Tmax Tmean  RPM MODE     Fan%
08:59:29  STANDBY ./spincheck2.sh: line 95: let: Tsum=0+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 95: let: Tsum=0+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 95: let: Tsum=0+: syntax error: operand expected (error token is "+")
STANDBY ./spincheck2.sh: line 95: let: Tsum=0+: syntax error: operand expected (error token is "+")
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
./spincheck2.sh: line 56: printf: Standard: invalid number
^0    0.00    0 0         0   ERRc= -33.57


I don't have ipmi on this board I am testing on so this script is probably trying to do to much. I will have my Supermicro board in as soon as it comes in. Newegg decided to take a super long holiday weekend and hasn't shipped anything this week.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Right, need ipmi. We could strip out that stuff easily.
But I also see there's a little bug. If the drive is in STANDBY, the script won't wake it up to read the temperature. So then the arithmetic using the temperature fails.
Assuming ada1 is still in standby, please paste this into your terminal and see what comes back - presumably a blank line?:
Code:
smartctl -a -n standby "/dev/ada1" | grep "Temp" | grep -o "..$"
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
I just replaced the script in the first post of this thread with one that is more bulletproof. It should work on non-SuperMicro boards, including those without IPMI. It will remove flash and SSD drives from the list that have KINGSTON, ADATA, or SanDisk in their entries. Other such patterns can easily be added. If they are not removed, the script should still carry on and will just list their status as "UNKNOWN".
 
Last edited:

willrun4fun

Dabbler
Joined
Jan 19, 2016
Messages
29
Glorious1 thanks for so many updates and the help so far!

Here is the output from the new version of the script you posted, it looks like the drive status is working fine but the temp throws a divide/0 error:

Code:
[root@freenas] ~# ./spincheck2.sh
How many minutes do you want between spin checks?
5
Saturday, Jul 02
  ada1    ada2    ada3    ada4    Tmax Tmean              
Saturday, Jul 02
  ada1    ada2    ada3    ada4    Tmax Tmean              
12:02:25  STANDBY STANDBY STANDBY STANDBY dc: divide by zero
^0    0.00  ERRc= -33.57


It is not a huge deal. I can go look at the Kill-a-watt and easily see if they are spinning as well.

I think my appletv or mac mini server is prone to waking it up.
 
Last edited:

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Glorious1 thanks for so many updates and the help so far!

Here is the output from the new version of the script you posted, it looks like the drive status is working fine but the temp throws a divide/0 error:
Yeah, when I changed it I didn't anticipate that there might be NO drives spinning. I put a new one there that hopefully fixes that, if you feel like trying it. Interesting that the header printed twice for you because you happened to start it just after noon, when it prints a new header. But the header shouldn't be out of alignment with the data. Is that the way it looks in your spincheck.log?
 
Top