How to Let Drives Spin Down

twsps

Contributor
Joined
Jul 10, 2018
Messages
113
Sheesh! It's hard to troubleshoot a script that breaks on another system. But I suspect you're have the same issue that @meku had on the previous page of this thread. Drive manufacturers format their smartctl output differently. Apparently some have the pattern "Temp" on multiple lines. So just try changing line 75. Change grep "Temp" to grep "Temperature_Celsius".
Mine isn't being fixed by changing that line. Any Suggestions?
Code:
How many minutes do you want between spin checks?

15

Friday, Aug 03

  pass0   pass1   pass2   pass3   Tmax Tmean				

08:15:51  Spin 9) ./spincheck.sh: line 85: let: Tsum=0+9): syntax error in expression (error token is ")")

Spin 1) ./spincheck.sh: line 85: let: Tsum=9+1): syntax error in expression (error token is ")")

UNKNOWN UNKNOWN ./spincheck.sh: line 42: printf: 9): invalid number

^9	5.00  ERRc= -28.57
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211

Maxburn

Explorer
Joined
Oct 26, 2018
Messages
60
Is point 3 add-on card still an issue? If not are there specific cards to look for?

I'm reviewing my backup strategy and I think I would like a second pool as a backup target but I only need it on a couple times a week while the backup is happening. I haven't built the box yet and I suppose I could put the primary pool on a HBA.

The alternative is my manually doing file copy backups with a toaster but honestly I haven't been too good at remembering to do that. Meanwhile the nightly rsync task I had pushing to another NAS over a remote VPN was working great without my being involved.
 

FreeNasNewbie

Dabbler
Joined
Sep 22, 2014
Messages
11
Hi all,

Freenas is great software, stable and reliable. And the new 11.2.-GUI look-and-feel is highly user-friendly.

However: I have exactly the same question. In the meantime , is there a solution available to spin down drives using LSI 9211-8i IT-Mode (SAS 2008-IT, BIOS 7.39.02.00, Firmware 20.00.07.00, BSD-Driver 21.02.00.00)?
After noticing a few weeks ago all drives will never spin down (using freenas 9.10) I upgraded to Freenas 11.2 applying all available updates. But nothing changed. Drives do not spin down.

The amazing fact is that drives spun down in an earlier freenas version (either freenas 9.2 or 9.3, sorry, I can't remember exactly) using exactly the same hardware/firmware settings. So, maybe it's a software issue that can be fixed?

I know freenas is a server, designed to run 24/7. However for advanced private use and SME it may be useful to reduce power consumption during night or weekend spinning down disks. And the developers obviously had this in mind otherwise it would not be available in the GUI.
I can't believe that this feature is now only available if drives are directly attached to the SATA mainboard connectors.

Or are there any (hidden) processes accessing the drives preventing them from spinning down? I tested with no active connections from clients. No installed plugins or prgrams in jails. All other settings are default. Just one NFS shares is defined.
OS is on a SSD, logsystem is on a USB stick.

Any tip/hint is highly appreciated.

Thanks a million for your support!
Mat
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Or are there any (hidden) processes accessing the drives preventing them from spinning down?
It's very likely you have something running the accesses the hard drives periodically. It's really not hard to force the drives to spin down but it takes a lot on learning how to command these things to spin down and then paying close attention as to what applications are being run which access the hard drives. For example, do you have any VMs or jails or plugins running as these are key things that cause the drives to be accessed and thus not sleep. You say you have nothing configured so you should be able to send the command manually to sleep the drives immediately. Listen for them to stop spinning. Then wait to see if they spin back up. If they do then you have some application which is using the drives/pool some way. Unfortunately I'm not familiar enough with FreeNAS 11.2 to provide further advice.
 

FreeNasNewbie

Dabbler
Joined
Sep 22, 2014
Messages
11
joeschmuck, thanks a million for your reply.

It seems that GUI settings doesn't have an effect. So I did a little CLI-based testing using console (and later on using the shell via GUI) after carefully reading the whole thread again.

Additional information about the setup:
- OS is installed on a separate SSD
- logsystem is installed on an USB stick
- no system data or log information stored on data disks
- overall 9 data (pool) disks (all SATA, WD Red, 3 TB), 1 disk connected directly to the SATA-port (ada0), 8 disks connected to the HBA (da0 - da7)

My summary:
1. You are right. It's very easy to spin down disks connected to an HBA via CLI manually. 2. Issuing the command camcontrol standby /dev/(a)daX - t 600 stops spinning all disk(s) immediately.
2. I'm unsure why - the -t parameter seems to be ignored. Is it? Shouldn't the disks stop with a delay of 10 minutes?
3. Disks keep spun down during a 24-h-period. NFS-mounts/-umounts (but no file access) and using the Web-GUI don't affect the pool disks. No scheduled scrubs during this period.
4. Trying to access a file in a NFS-mounted directory after this 24-h-period of inactivity leads into an I/O error (drives don't spin up). However, accessing files locally via GUI-Shell works fine. Hm, maybe an NFS-issue? I'll do a little bit more research on it. That's OT here, I think.
5. Once running, disks won't spin down again, obviously there's no timer set with the camcontrol command (or ignored) - and - again - GUI settings seem to be ignored.

Now, what can I do to make the spindown-command persistent? For sure it's a silly idea to enter the command manually after using the system :smile: and after reboot/update.

Many thanks again for your support!
Mat
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Now, what can I do to make the spindown-command persistent? For sure it's a silly idea to enter the command manually after using the system :) and after reboot/update.
First of all, good job in doing your research and running the tests. To make this persistent you could easily write a script (just like you would from the command line) into a text file and then execute that file via CRONTAB (CRON job). You can select if you would like to run it once or maybe even once a day. So once you have this all up and running, pay attention to your head loading count and the spinup count, you could inadvertently cause this to increase significantly which means the drives are cycling up and down too frequently which will likely cause a drive failure. In my opinion cycling more than once a hour is way too much but it's up to you to figure out what you desire.

As for the NFS, I'm not sure why that would be the case, very odd. Does this happen also for CIFS/SBM shares? This could be a deal breaker. If I had a similar HBA then I could test this out with you but I do not.

Good Luck!
 

pelipro

Cadet
Joined
Jun 4, 2019
Messages
2
Hi, I had been struggeling to make my drives spin down as I do only need them once a day for backups.
When I saw this post: https://serverfault.com/questions/968303/how-to-make-hard-drive-standby-spin-down-on-a-timer/969252#
I rewrote this script in python. Maybe somebody finds it useful

Code:
import subprocess
import time

drives_to_check = ['ada3', 'ada4', 'ada5']
no_sleep_hours = ['00', '01']
seconds = 600

if time.strftime("%H") in no_sleep_hours:
    exit()

o = subprocess.check_output(f'/usr/sbin/iostat -x -z -d {seconds} 2', shell=True)

for drive in drives_to_check:
    if drive not in o.decode().split('extended')[-1]:
        p = subprocess.check_output(f'/sbin/camcontrol cmd {drive} -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r -', shell=True)
        if p.decode()[27:29] != '00':
            q = subprocess.check_output(f'/usr/local/sbin/ataidle -s /dev/{drive}', shell=True)

You have to add the drives you would like to check and spindown to the drives_to_check list.
If you want to run the script at all times, replace: no_sleep_hours = ['00', '01'] with no_sleep_hours = []
or adjust it to what you like.
The script will collect data for 600 seconds and if the disk is not used und it is spinning then it will start a spindown.
You can add it to cron with */15 * * * * /usr/local/bin/python3 /path/to/the/folder/check_disk_usage_and_spindown.py
so it will run every 15 minutes. Run it as root.
 

Glorious1

Guru
Joined
Nov 23, 2014
Messages
1,211
Hi, I had been struggeling to make my drives spin down as I do only need them once a day for backups.
When I saw this post: https://serverfault.com/questions/968303/how-to-make-hard-drive-standby-spin-down-on-a-timer/969252#
I rewrote this script in python.
It's been a while since I've looked at this, but when I did (OP) getting drives to spin down was no problem. As time went on, FreeNAS would spin up the disks at various times with no apparent reason. Running your script every 15 minutes may put them back to sleep, but if they're spun up and down multiple times a day, at some point it's better just to leave them spinning.
 

pelipro

Cadet
Joined
Jun 4, 2019
Messages
2
Indeed, you should not spin down your drives very often. I only use the script above for some backup drives. They only recieve a backup once a day from an other computer via sftp, after that I make a snapshot and then they are 23 hours unused. I think in this situation it is fine to spin them down. If have have a share on then that is used more often you should not do it.
I'll share another script. I run it via cron every two minutes and it records the state of the harddisks. That way I can see that they are not constantly spinning down and waking up.
FF means drive is up and running
00 means drive has spun down
Adjust "drives" to match the drives you want to watch.

Code:
import subprocess
from datetime import datetime
datetime.now().strftime('%Y-%m-%d %H:%M:%S')

def main():
        check()

def check():
    drives = {'ada0':'', 'ada1':'', 'ada2':'', 'ada3':'', 'ada4':'', 'ada5':''}

    state = []

    for drive in drives:
        try:
            o = subprocess.check_output(f'/sbin/camcontrol cmd {drive} -a "E5 00 00 00 00 00 00 00 00 00 00 00" -r -', shell=True)
            drives[drive] = o.decode()[27:29]
        except:
            drives[drive] = '??'
    with open("/path/to/folder/drive_stats.txt", "a") as myfile:
        myfile.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} {drives}\n")
    print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), f"{drives}")

if __name__ == '__main__':
    main()
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Keep an eye on your SMART data for spinup and head load counts, what you think is happening and what is really happening may be two different things. If these counts go up more than 1 per day, they you are not controlling the drives like you think. If the count goes above 5 per day then in my opinion you are adding much more stress to the drive motor and could be shortening the life of your drives. Just my opinion.
 

ngandrass

Explorer
Joined
Jun 26, 2019
Messages
68
Hello everyone,

I ran into multiple spindown problems myself during the last years of using FreeNAS in an home environment. Therefore I took the iostat approach and created a shell script as well as a small guide on how to install and use it. Hopefully this is able to help someone! :)

More information and download: https://www.ixsystems.com/community/resources/hdd-spindown-timer.122/

Feel free to report any bugs or contribute!
 

floyd71

Dabbler
Joined
Mar 13, 2021
Messages
11
I tried something as follows (apart settings for S.M.A.R.T. and Standby:

From GUI go to
Storage / Pools / Edit Dataset

then set "Enable Atime" to OFF (default value is ON)
This option is related (as explained) : Choose ON to update the access time for files when they are read. Choose Off to prevent producing log traffic when reading files. This can result in significant performance gains.

Other, very important matter is to go to GUI
system / system dataset and choose pool which is not your data. I set it on "boot-pool"
That is all!

I tested it on
TrueNAS CORE 12.0-U2.1 with hardware: HPE ProLiant Microserver Gen10 Plus equipped with 2 x 6TB Seagate IronWolf HDD (mirrored).

Here is observation after a while...
I was happy at the beginning, but unfortunately, it does not work as I would like to be.
Disks are really spin down, but after a short time, you can hear starting of the HDDs and again spinning down... so I guess it is not good scenario for the motor of the disks... and maybe it will not work well.
 
Last edited:
Top