I have built a new FreeBSD file server with multiple HDDs. I found whenever the disks are not accessed for a while, the disks would spin down completely or park its head. How do I disable HDD spin down or head parking? On Linux, I know it can be done via hdparm
, but what about FreeBSD?
Note:
-
AFAIK, This is not a duplicate question. 99% of the search result for "HDD spin down" at serverfault.com is Linux-specific. The only "HDD spin down" related question on serverfault.com is How to make hard drive standby (spin down) on a timer?, which doesn't answer the question, and make use of ataidle, obsolete since 2018-12-31. Other candidates include How to get FreeNAS to spin down disks? – doesn't answer the question, or Checking whether disk is in sleep state (FreeNAS) – uses
atacontrol
, removed since FreeBSD 11. -
Search result of "freebsd spin down hard disk" at Google or DuckDuckGo consists mostly of old forum posts at forums.freebsd.org or tutorials from elsewhere, which all included suggestions of now-obsolete
ataidle
oratacontrol
tools. In addition, none of the posts explained the relation between ATA Standby mode and APM, and explanation of Extended Power Conditions is nonexistent.
Thus, I believe a reference question "How do I disable hard disk spin down or head parking in FreeBSD" with detailed explanation of ATA Standby, APM, and EPC would serve a useful purpose for the community, and help further readers coming from the search engine.
Best Answer
On FreeBSD 12,
camcontrol
is used to control HDD power management, including spinning down and hard parking. Previously,ataidle
oratacontrol
was used, but their functionalities have already been merged intocamcontrol
, they are deprecated and no longer supported.TL;DR
You should run these commands on every reboot. For example, via
/etc/rc.local
.Disable automatic spin down
Set "Standby" timer to
0
seconds, set APM to a number equal or greater to128
, and disable EPC "standby_z" timer. Don't forget to changeada1
to your hard drive.This should be good enough for most people.
Disable automatic spin down & head parking
Set "Standby" timer to
0
seconds, disable APM, and disable EPC.This essentially disables all power management. If your hard drive supports EPC, it's recommended to use the EPC solution below (keep on reading), instead of blindly disabling all power management. Also, if you are not seeing excessive increase of Load/Unload Cycle Count in S.M.A.R.T., you probably don't need it, disabling spin down should be good enough.
Finally, it should be noted that there is no guaranteed way to disable head parking, ultimately it's a vendor and model specific behavior. The best thing we can try is to disable as much power management as possible. It usually works, but has no effect on some especially problematic hard drive models (such as WD Green). The only way to save them is using vendor-specific tools, which is out of the scope of this answer.
Disable automatic spin down or head parking via EPC
If your hard drive supports EPC, it's recommended to use the EPC solution below (keep on reading) to disable spin down or head parking. To prevent HDDs from spining down, disable
standby_z
. To prevent HDDs from parking, disableIdle_b
,Idle_c
andstandby_y
.First, check whether your HDD supports EPC.
To enable and disable spin-down via EPC...
Troubleshooting
If your HDD does not support APM, you'll get the following error. If your HDD only support EPC, you can use EPC and ignore this error.
If your HDD does not support EPC (or if EPC is already completely disabled, e.g. also, enable APM will automatically disable EPC), you can use APM and ignore this error.
If you can not disable hard disk spin down or head parking cannot be disable regardless of Standby/Idle Timer, APM, or EPC settings, unfortunately, only vendor-specific tools may help you. It's outside the scope of this answer.
Explanation
To understand the meanings of these commands, we must pause for a moment to learn their technical background. In fact, HDD power management is a mess. It's controlled by three independent mechanisms, namely, the basic ATA Command Set 2 (ATA8-ACS2), Advanced Power Management (APM), and Extended Power Conditions (EPC). Also, if we count vendor proprietary features found in some Seagate and WD Green drives, there are four mechanisms in total, but it's out of the scope of this answer.
In order to get the expected result, each of these mechanisms must be configured correctly. For example, if the disk Standby timer is disabled via the ATA Command Set, but APM is still set to a value lower than 128, the disk will still spin down. And to complicate the matter, not all hard drives support all of these mechanisms. For example, some enterprise-grade HDDs don't support APM and use EPC exclusively, we also have HDDs that support EPC but disables it, defaulting to APM, in addition, some earlier-generations of HDDs and many consumer-grade HDDs don't support EPC at all.
To get the desirable settings, each of the power management mechanism must be correctly configured.
ATA Command Set 2 (ATA8-ACS2)
The ATA Command Set 2 specification supports basic power management. It defines four power states in ATA drives and a Standby timer.
In other words, Standby causes the hard drive to spin down, and Idle is a low-power mode without no spin down. Since the standard doesn't say what a hard drive should do in Idle mode, it's vendor-specific behavior. For an educated guess, it could allow the HDD to spin at a reduced speed, or to also park its head. Finally, Sleep should never be used, unless you're going to remove the HDD or shut down the system.
Only the Standby timer can be disabled by setting it to
0
seconds. The Idle state is not controlled by a timer, and cannot be disabled.Alternatively, you can also set the Standby timer to the number you want, however, the encoding of the timer is really strange!
Source: ATA/ATAPI Command Set - 2 (ACS-2)
A concise summary can be found from
hdparm
's man page:On FreeBSD,
However, the devil is in the detail. There is no guaranteed way to disable either "Standby" or "Idle" states. First, as previously stated, there is no timer for "Idle", only a timer for "Standby". Thus, if the HDD vendor decides to enter Idle aggressively, and if Idle mode implies a head parking, you are out of luck without EPC. For example, some WD Green hard drives are known to perform head parking aggressively.
Also, HDDs are allowed to enter "Idle" or "Standby" by itself without host intervention.
Thus, if the HDD vendor decides to enter Standby aggressively, You're also out of luck.
Advanced Power Management (APM)
Advanced Power Management (APM) is a power management mechanism for personal computers standardized in the late 90s. It has long been superseded by ACPI, however, it's still used in HDD power management and is supported by almost all hard drives. It's unsupported only in some enterprise-grade hard drives.
The implementation of APM is not specified by the standard, thus it depends on the vendor and model of your hard drive. The only things we can be sure are that
"128" enables all power saving features without spinning down. Presumably, the HDD can spin at a reduced speed, or to park its head.
Usually, APM can be disabled. It's possible that speed reduction or head parking can be disabled if APM is disabled, but we cannot know for sure.
On some hard drives, APM cannot be disabled, alternatively, we can use "254", the maximum performance mode defined by APM.
In FreeBSD,
Extended Power Conditions (EPC)
This is the latest power management standard in hard drives, it's usually supported on enterprise-grade hard drives (some newer hard drives don't support APM, EPC is used exclusively). Seagate markets EPC as PowerChoice™ Technology.
It offers the more fine-tuned power management levels, more specific than the basic Idle, Standby states in the standard ATA command set. It defines 2 power states and 5 power conditions.
Each power condition can be controlled by a timer, and they can also be enabled or disabled individually.
Note that the precise meaning of
Idle_a
,Idle_b
,Idle_c
,Standby_y
, orStandby_z
is not specific in the standard at all! Again, it's up to HDD device manufecterer to implement them. I used the definition from the HGST/WD Ultrastar and Seagate datasheets. Make sure to check the full datasheet of your hard drive model!It's clear to see that for our selected hard drives, disabling
Standby_z
will prevent the HDD from spinning down, and disablingIdle_b
,Idle_c
andStandby_y
will prevent the head from being unloaded. Thus, if your HDD support EPC, it's recommended to use them.Also, APM must be disabled first before using EPC.
In FreeBSD,