Saturday, May 9, 2020

Put spinning rust to sleep on a Raspi

After getting my SMB data backed up on a pi connected to two 5TB HDDs (Seagates) using mhddfs to combine both drives/partitions into one mount (without LVM) and getting FreeNAS to do an rysnc push (disable delay-update + lots of private/public key fun) I noticed the 5TB drives just keep spinning and spinning, despite being at idle.

To fix this, thankfully these drives are supported by hdparm.  Install hdparm, read up the arch wiki on it:
https://wiki.archlinux.org/index.php/Hdparm

I ran hdparm -B /dev/sda1 and for sdb1

Both drives showed APM_level as 128.  A value of 127 is needed to have drives stop spinning at idle.  I ran hdparm -B 127 /dev/sda (and again for sdb1) and after about 10 seconds both drives stopped spinning.

And to do a quick spin-up test, I kicked off the rsync job manually- I could hear the drives spin up for the sync portion and then take about 20 seconds to spin down after finishing the sync portion (no writes, was already up to date).

This is a great alternative to the idea of setting up a cron job to unmount the drives between rysnc jobs, especially since I have no idea how unmounting two drives tied into mhddfs might affect things.

But not out of the woods yet- these settings do not persists after reboot- and in typical linux fashion there are different answers on how to set this up to persist after reboot.  This thread was Pi specific but uses hdparm's timing parameter instead of power parameter:
https://maker-tutorials.com/en/spin-down-magage-hard-drive-on-raspberry-pi-hd-idle/

So use their example:



But replace with your uuid's of course, but also change spindown_time = 240 with apm (in this case apm = 127 is what makes my drives spin down).


And then save, and then reboot to see if they persisted.

And of course if you know anything about this blogger, of course not.  In fact it made it worse.  The default settings of APM being 128 (and 127 is what makes the drives allow themselves to spin down) is now at 254!!

So maybe its better to go fully by the tutorial LOL.  I noticed when I would hdparm -B /dev/sba1 it would print out the results "APM_level = 128" so I tried this in the .conf file vs "apm = 128" but no joy.

The tutorial above using "spindown_time" also didn't work though.  Gotta live raspi, this is not an issue with most any other operating system.

Last try is this:  When you go to edit hdparm.conf it pretty much has the man file in it but commented out.  If follow that man file, there is no feature of "by-uuid", it has you go by /dev/sba1 etc.  So trying it that way:  Nope.  Defaults to 254 again.

So with editing the hdparm.conf six ways from Sunday and it still didn't work, the googles says one option is to edit the etc/rc.local file- whatever is there is run during boot up.
https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/

Typed in the two commands I want run:
hdparm -B 127 /dev/sda1

hdparm -B 127 /dev/sdb1

Still- NOPE

So created a script in /mnt called "hdparm.sh"
Inside this script is:
"
hdparm -B 127 /dev/sda1
hdparm -B 127 /dev/sdb1

Tested this script by typing in from /mnt "hdparm.sh"  It printed out the APM_level as 127.

Inputted into rc.local
"# make HDDs sping down at idle
sh /mnt/hdparm.sh &

And Bob's your uncle- now after reboot the hard drives settle down and stop spinning.


Things that may have helped that I did along side these other things so I don't know if they had effect or fixed the issue rather than what I thought did:
- set rc.local to executable
-

No comments:

Post a Comment