4

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

7
  • 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. Feb 8, 2019 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 Feb 8, 2019 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* Feb 8, 2019 at 7:24
  • Let us continue this discussion in chat. Feb 8, 2019 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. Mar 6, 2019 at 15:25

2 Answers 2

6

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.

2
  • After Ctrl+Alt+T I bet you need to install fancontrol and lm-sensors :-p
    – beginer
    Apr 16, 2019 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. Apr 16, 2019 at 11:35
1

I found Mathew Wai's answer really good, but I ran into some issues with drives sleeping and temperature data corruption. This has been stable for me:

FILE=/tmp/Hddtemp
while true
do
    temperature=$(hddtemp -n /dev/sdc 2>/dev/null)
    # Set base temp if we got nothing in stdout, this mean we are asleep
    if [ "$temperature" == "" ]; then temperature=30; fi
    # Get a tempfile to write out temp
    NEW=$(mktemp /tmp/Hddtemp.XXXX)
    echo $(($temperature * 1000)) > $NEW
    # Handle case of initial/clean run
    if [ -e $FILE ]; then
        CLEAN="rm -f $(readlink -f $FILE)"
    fi
    # Atomic symlink replacement
    ln -s $NEW $FILE.lnk
    mv -T $FILE.lnk $FILE
    # Clean old link, if it existed
    $CLEAN
    sleep 30
done

Given that hddtemp is going away in the next Debian release, I've changed mine to use "drivetemp", which can be read from sensors so I'll replace:

    temperature=$(hddtemp -n /dev/sdc 2>/dev/null)

with

    temperature=$(sensors -A drivetemp-scsi-5-0|grep temp1|tr -s ' '|cut -d '+' -f 2|cut -d '.' -f1)

I am just starting to use this sensors method, so I can't say for sure that it is stable.

0

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.