Getting hard drives to properly spin down in FreeNAS (especially with ZFS) requires understanding multiple system interactions. The immediate spin-up behavior you're observing typically occurs because:
- Background ZFS processes (scrubs, resilvers, snapshots)
- System monitoring tools (smartd, sysctl)
- Misconfigured APM/SATA settings
First, verify your current disk states:
smartctl -i /dev/ada0 | grep -i 'APM Level'
sysctl dev.ada.0 | grep 'apm'
zpool status
Then implement these critical adjustments:
# Disable unnecessary disk access
sysctl vfs.zfs.scrub_delay=3600
sysctl vfs.zfs.resilver_delay=3600
sysctl vfs.zfs.vdev.async_write_active_min=1
sysctl vfs.zfs.vdev.async_write_active_max=1
Edit /usr/local/etc/smartd.conf
to reduce polling frequency:
DEVICESCAN -a -o on -S on -n standby -s (S/../.././02|L/../../7/03)
Create a post-init script (/usr/local/etc/rc.d/spindown
):
#!/bin/sh
. /etc/rc.subr
name="spindown"
start_cmd="${name}_start"
spindown_start() {
for disk in $(sysctl -n kern.disks); do
camcontrol cmd ${disk} -a "EF 03 00 00 00 00 00 00 00 00 00 00" -r -
camcontrol apm ${disk} -l 127
camcontrol standby ${disk} -t 1200
done
}
load_rc_config $name
run_rc_command "$1"
Monitor disk states with:
while true; do
printf "%s - %s\n" "$(date)" "$(smartctl -n standby /dev/ada0 | grep 'mode')"
sleep 60
done
Expect output like:
Mon Jul 10 14:00:01 UTC 2023 - Device is in STANDBY mode
Mon Jul 10 14:30:45 UTC 2023 - Device is in ACTIVE mode (brief access)
Mon Jul 10 14:31:01 UTC 2023 - Device is in STANDBY mode
When I set up my FreeNAS 11.2 system with a USB boot device and 4-disk ZFS pool, I expected the HDD Standby (20 minutes) and APM Level 127 settings to keep disks spun down during inactivity. However, the disks kept waking up almost immediately after spindown - a common frustration for energy-conscious sysadmins.
To identify what's preventing persistent spindown, SSH into your FreeNAS box and run:
grep -E 'sd[a-d]' /var/log/messages | grep -i -E 'start|stop'
This reveals disk activity patterns. Common culprits include:
- ZFS background scrubs (even when idle)
- SMART monitoring services
- System logging to disks
- Periodic snapshot operations
Add these to your /etc/local/sysctl.conf
:
# Reduce ZFS background activity vfs.zfs.scrub_delay=86400 vfs.zfs.resilver_delay=86400 vfs.zfs.vdev.async_write_max_active=1 vfs.zfs.txg.timeout=60
Edit /etc/periodic.conf
to minimize disk activity:
daily_status_zfs_enable="NO" daily_scrub_zfs_enable="NO" weekly_scrub_zfs_enable="NO"
Then disable SMART monitoring for non-critical disks via the FreeNAS GUI at Services → S.M.A.R.T.
Create /usr/local/etc/rc.d/spindown
with:
#!/bin/sh . /etc/rc.subr name="spindown" start_cmd="${name}_start" spindown_start() { for disk in $(sysctl -n kern.disks); do if [ "$(camcontrol identify $disk | grep -c 'ZFS')" -eq 0 ]; then camcontrol apm $disk -l 127 camcontrol standby $disk -t 1200 fi done } load_rc_config $name run_rc_command "$1"
Make executable and enable:
chmod +x /usr/local/etc/rc.d/spindown echo 'spindown_enable="YES"' >> /etc/rc.conf.local
Check actual spindown status with:
for disk in $(sysctl -n kern.disks); do echo -n "$disk: " camcontrol cmd $disk -a -E "5C 00 00 00 00 00 00 00 00 00 00 00" -r - done
For more control, create a cron job (crontab -e
):
*/10 * * * * /usr/local/bin/spindown_check
With /usr/local/bin/spindown_check
containing:
#!/bin/sh for disk in $(sysctl -n kern.disks); do if ! lsof +D /mnt | grep -q "$disk"; then camcontrol standby $disk fi done