How can I adjust fan speed according to hard drive temperature via Fancontrol?
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 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.
(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:
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:
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.