2

How can I adjust fan speed according to hard drive temperature via Fancontrol?

  • 1
    I don't know anything about fancontrol, but supports HDD temp; you could try asking for the feature or giving it a shot yourself. The easiest solution at hand seems to be to write a daemon (or just a shell script ran at boot) script that queries the disk temperature regularly and then sends commands to fancontrol. Also, a little googling can go a long way. – Kenneth B. Jensen Feb 8 '19 at 6:13
  • 1
    How does hddfancontrol malfunction? Did you install fancontrol directly from that page or as part of the lm_sensors package? I could write for you a shell script, but I use neither fancontrol nor hddtemp; I'm not sure how their outputs are structured. If you have any experience with using the shell so far, see if you can give it a crack -- check out tldp.org/LDP/Bash-Beginners-Guide/html tldp.org/LDP/Bash-Beginners-Guide/html and tldp.org/LDP/abs/html – Kenneth B. Jensen Feb 8 '19 at 7:07
  • 1
    hddfancontrol is not in root's $PATH. What directory is it installed in? Running which hddfancontrol as your normal user might yield the information you're looking for; it needs to be somewhere like /usr/local/bin. If you cannot find it, try running locate hddfancontrol or find / -iname *hddfancontrol* – Kenneth B. Jensen Feb 8 '19 at 7:24
  • Let us continue this discussion in chat. – Matthew Wai Feb 8 '19 at 7:28
  • 2
    FAO other reviewers (like me) who come across this question in the Review queues: this question has a comprehensive and detailed self-answer. – Anthony Geoghegan Mar 6 '19 at 15:25
4

I finally found a simple script to control fan speed according to hard drive temperature via Fancontrol, Hddtemp, and Lm-sensors. In the following script, “/dev/sda” is the hard disk to be monitored, and “/Fancontrol/Hddtemp” is the output file to be read by Fancontrol. Press Ctrl + Alt + T to open Terminal and run the following command to check whether “/dev/sda” is the correct one:

sudo hddtemp /dev/sd[a-z]

Use only the one supported by Hddtemp, which will display the temperature rather than “S.M.A.R.T. not available”.
Replace “/dev/sda” with the correct one in the script if necessary.
If you have not yet configured Fancontrol, see this page, this page, and this page and run the following commands one by one (restart Linux after running the first one):

sudo sensors-detect
watch sensors
sudo pwmconfig
sudo service fancontrol start

Then, go through the procedure below:
(1) Run the following command to create a script file.

sudo mkdir -p "/Fancontrol/" & sudo xed /Fancontrol/HDD_temp

(2) Copy the following script into the file and save it.

#!/bin/bash
File=/Fancontrol/Hddtemp
while true
do 
temperature=$(sudo hddtemp -n /dev/sda)
echo $(($temperature * 1000)) > "$File"
sleep 30 
done

(3) Run the following command to make it executable.

sudo chmod +x /Fancontrol/HDD_temp

(4) Run the following command to create a service file.

sudo xed /lib/systemd/system/HDD_temp.service

(5) Copy the following lines into the file and save it.

[Service]
ExecStart=/Fancontrol/HDD_temp

[Install]
WantedBy=multi-user.target

(6) Run the following commands one by one:

sudo chmod 664 /lib/systemd/system/HDD_temp.service
sudo systemctl daemon-reload
sudo systemctl start HDD_temp.service
sudo systemctl enable HDD_temp.service

Then, the script “HDD_temp” will be run as a system service at Linux startup.

(7) Run the following command to edit “fancontrol”, the configuration file.

sudo xed /etc/fancontrol

Find the line that begins with “FCTEMPS”. For example:

FCTEMPS=hwmon1/pwm1=hwmon1/temp1_input

On that line, “hwmon1/temp1_input” is the temperature (e.g. the chipset temperature) currently read by Fancontrol. Replace it with “/Fancontrol/Hddtemp”, and the line will become:

FCTEMPS=hwmon1/pwm1=/Fancontrol/Hddtemp

Save the file and run the following command to restart Fancontrol.

sudo service fancontrol restart

Then, the fan controlled by “hwmon1/pwm1” will respond to “/Fancontrol/Hddtemp”, the hard disk temperature. Note that "HDD_temp" and "Hddtemp" are the script file and output file respectively. Don't confuse them.

|improve this answer|||||
  • After Ctrl+Alt+T I bet you need to install fancontrol and lm-sensors :-p – beginer Apr 16 '19 at 7:34
  • In my answer, "Fancontrol", "Hddtemp", and "Lm-sensors" are hypertext links to their download pages. I assume readers know how to install them. – Matthew Wai Apr 16 '19 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.