Package: hddfancontrol
HDD Fan controlHDD Fan control is a command line tool to dynamically control fan speed according to hard drive temperature on Linux.This has 3 benefits:it allows maintaining your hard drives in the ideal temperature range to have maximum longevity and avoid overheatingBecause fans will slow down or stop when not needed:it minimizes noise generated by the fansit also minimizes power consumption at the same timeWhen is this useful?HDD Fan control is useful when you have one or several hard drives with one or several fans close to them, and do not want to let the motherboard control the fan speed, because it does so either statically, or using a temperature sensor unrelated to the real drive temperature (either on the CPU or on some other place on the motherboard).The ideal use case is for a NAS with several hard drives, a low power CPU (ie. ARM or Intel Atom) with passive cooling (no fans), and a chassis with fans close to the hard drive. It that case the CPU will generate less heat than the hard drives and it makes sense to control fan speed according to the main heat source.FeaturesCan run in daemon modeCan control several fans and/or several drives with a single invocationSupports 6 different ways of querying temperature:hddtempinvocationhddtempdaemon queryhdparminvocationsmartctlinvocation (SCT)smartctlinvocation (SMART attributes)drivetempnative kernel hwmonCan automatically spin down drives after a customizable period of inactivityCan adapt to different fan characteristicsCan be set to stop fans or run them at full speed at customizable temperaturesCan be configured to never set the fans below a certain speed (useful if the fans controlled by HDD Fan control are the only ones available in the chassis)Can also optionally monitor CPU temperature, and control fan speed accordinglyPrerequisitesA Linux distributionA least one SATA hard drive, that supports:Temperature queryingPower state queryingA motherboard which:exposes to the OS a PWM to control fan speedexposes to the OS a sensor to query fan speedMost motherboards and SATA drives fit these requirements.InstallationHDD Fan control requiresPython>= 3.6.Distribution packagesSome Linux distributions have a hddfancontrol package available in their repository:Arch Linux (AUR):hddfancontrolFedora:hddfancontrol(thanks toTC01)From PyPI (with PIP)If you don't already have it,install pipfor Python 3Install HDD Fan control:pip3 install hddfancontrolInstallhdparmandhddtemporsmartctl.
On recent Ubuntu and other Debian derivatives:sudo apt-get install hdparm smartmontools.From sourceIf you don't already have it,install setuptoolsfor Python 3Clone this repository:git clone https://github.com/desbma/hddfancontrolInstall HDD Fan control:python3 setup.py installInstallhdparmandhddtemporsmartctl.
On recent Ubuntu and other Debian derivatives:sudo apt-get install hdparm smartmontools.To query fan characteristics, you may also need pwmconfig. On Ubuntu and other Debian derivatives, it is part of the fancontrol package, that you can install withsudo apt-get install fancontrol. HDD fancontrol and fancontrol are unrelated. The fancontrol daemon isnotneeded for HDD fan control to operate. If you use both fancontrol and HDD fancontrol, be careful not to make them control the same fans.ConfigurationA word of cautionThe default parameters will run fans at 100% speed at temperatures > 50°C, and run them a 20% speed if < 30°C, which corresponds to the usual recommended drive operating temperature. If you are sure that there are no other components in your system that generate significant heat, if you have other fans to cool down your system, or if you have a case optimized for passive cooling, you can set minimum speed to 0%, which will stop the fans if temperature is below the minimum threshold.Be aware that a misconfiguration of this tool can lead to a failure to cool down your system properly which can damage components or reduce their lifetime.Before using HDD Fan control unmonitored for long period of time, I recommend keeping a minimum fan speed for security, and checking that the temperature of your system stays in reasonable range as expected.Fan configurationTo get the value for the--pwm,--pwm-start-valueand--pwm-stop-valueparameters, you can either:Use the-tor--testparameter, which will run some tests and detect the values at which the fans start and stop. However you need to have previously identified the PWM file (the--pwmparameter)use thepwmconfig tool.Drive auto spin downSATA drives can be configured to automatically spin down after a certain period of inactivity, which saves power. If your drives are configured to do so, you may notice that they do not spin down when HDD Fan control is running.
This is due to the fact that HDD Fan control will query temperature at fixed interval, which the drive will consider an activity and reset the spin down timeout.
To fix that, you can either:Use a value for the-i/--intervalparameter higher than your SATA spin down time (not recommended unless your spin down time is very low, ie < 2 min). In that case you do not need to use hddfancontrol's--spin-down-timeswitch, because the builtin SATA drive timeout (that you can set for example withhdparm -S XXXcommand) should take effect.Use the--spin-down-timeparameter that will monitor drive activity and spin it down if inactive, independantly of the SATA feature (recommended)Keep in mind that spinning down and up a drive repeatedly wears it prematurly, so unless you are in a power constrained environement (ie. laptop), do not set the spin down time too low.Reading temperature while a drive is in low power state will make it spin up, so HDD Fan control will stop querying temperature in that case, and wait for the drive (which will be cooling down in low power state anyway) to spin up.Some HGST (previously Hitachi) drives support a special way of querying temperature that does not spin up drives, which HDD Fan control will detect and use, however it still prevents them from spinning down, so the above instructions still apply.Command line usageRunhddfancontrol -hto get full command line reference.As an example, the command line below will instruct HDD Fan control to:monitor temperature of drives/dev/sdaand/dev/sdbcontrol fan speed using PWM 2 and 3 in/sys/class/hwmon/hwmon1/device/start both fans using PWM value 200consider the fans will stop with PWM value 75never run the fans below 10% of their maximum speedcheck temperature at least every minuteautomatically spin down drives if they are inactive for 2 hours (7200 seconds)run in daemon modelog what is going on to/var/log/hddfancontrol.loghddfancontrol -d /dev/sda /dev/sdb -p /sys/class/hwmon/hwmon1/device/pwm2 /sys/class/hwmon/hwmon1/device/pwm3 --pwm-start-value 200 200 --pwm-stop-value 75 75 --min-fan-speed-prct 10 -i 60 --spin-down-time 7200 -b -l /var/log/hddfancontrol.logSystemd serviceA systemd service file is provided to control the daemon easily.
If you installed hddfancontrol from a distribution package, you likely already have it installed, otherwise you can install it from the sources of this repository with:sudo cp ./systemd/hddfancontrol.service /etc/systemd/system/
sudo mkdir -p /etc/conf.d
sudo cp ./systemd/hddfancontrol.conf /etc/conf.d/hddfancontrolThen you need to edit theHDDFANCONTROL_ARGSvariable in/etc/conf.d/hddfancontrolto set the parameters (drives, temperature range...).You can then start the daemon withsudo systemctl start hddfancontrol, see its status withsudo systemctl status hddfancontroland enable automatic startup at boot time withsudo systemctl enable hddfancontrol.OpenRC serviceAn OpenRC service file is provided to control the daemon easily.
If you installed hddfancontrol from a distribution package, you likely already have it installed, otherwise you can install it from the sources of this repository with:sudo cp ./openrc/hddfancontrol /etc/init.d/
sudo mkdir -p /etc/conf.d
sudo cp ./systemd/hddfancontrol.conf /etc/conf.d/hddfancontrolThen you need to edit theHDDFANCONTROL_ARGSvariable in/etc/conf.d/hddfancontrolto set the parameters (drives, temperature range...).You can then start the daemon withsudo rc-service hddfancontrol start, see its status withsudo rc-service hddfancontrol statusand enable automatic startup at boot time withsudo rc-update add hddfancontrol default.LicenseGPLv3