Thinkfan installation guide

Hello,
I’ve recently had to install and use Thinkfan (https://software.opensuse.org/package/thinkfan) in a while on my Lenovo T480, and I just wanted to post the steps I took to set it up properly.

I must give credit to:
https://www.lxle.net/forums/discussion/821/how-to-set-up-thinkfan-on-a-lenovo-thinkpad-t430/p1
and
https://thinkwiki.de/Thinkfan
I am just summarizing the steps with a few updates.

  1. First lm-sensors and thinkfan need to be installed.
    lm-sensors are already in the repository
sudo zypper in sensors

and thinkfan needs to be downloaded from (https://software.opensuse.org/package/thinkfan)
2. You need to setup sensors

sensors-detect

Just go through and say yes to almost everything to probe.
3. Find the sensor addresses

*find /sys/devices -type f -name "temp*_input"*

This will return a bunch of sensors and some of them “virtual” we should ignore them. We can in fact do that by:

*find /sys/devices -type f -name "temp*_input" |grep -vi virtual*
  1. Refer to these addresses in
*/etc/thinkfan.conf*

before the temperature settings in a matrix of numbers corresponding to level and temperature (1 ,40, 45)…
you must probe these sensors in the configuration file using hwmon
For example:

hwmon */sys/devices/virtual/hwmon/hwmon0/temp1_input
*hwmon */sys/devices/platform/coretemp.0/hwmon/hwmon1/temp3_input
*hwmon */sys/devices/platform/coretemp.0/hwmon/hwmon1/temp1_input
*hwmon */sys/devices/platform/coretemp.0/hwmon/hwmon1/temp2_input*

and then you may configure the level-temperature matrix as you wish. I make sure that the fan starts at 35 degrees celsius then max out at 60 degrees celsius and I do push my laptop to the limits most of the time.

Finally, you can enable thinkfan

sudo systemctl enable thinkfan
sudo systemctl start thinkfan

reboot, test and it should be good to go.

Some of the other steps mentioned in my references would work in general, but un-necessary in my case and un-necessary if we are using one of the packages in our repos.

When you’d like to share a special procedure to do something,
You’re welcome to post in the following Forum

https://forums.opensuse.org/forumdisplay.php/783-Unreviewed-How-To-and-FAQ

Generally speaking,
Most posts in these regular Technical Help Forums are for asking questions.

Thx for sharing,
TSU

For future reference, an example of successful thinkfan configuration(power inefficient but stays cool):

/etc/thinkfan.conf
######################################################################
# thinkfan 0.7 example config file
# ================================
#
# ATTENTION: There is only very basic sanity checking on the configuration.
# That means you can set your temperature limits as insane as you like. You
# can do anything stupid, e.g. turn off your fan when your CPU reaches 70°C.
#
# That's why this program is called THINKfan: You gotta think for yourself.
#
######################################################################
#
# IBM/Lenovo Thinkpads (thinkpad_acpi, /proc/acpi/ibm)
# ====================================================
#
# IMPORTANT:
#
# To keep your HD from overheating, you have to specify a correction value for
# the sensor that has the HD's temperature. You need to do this because
# thinkfan uses only the highest temperature it can find in the system, and
# that'll most likely never be your HD, as most HDs are already out of spec
# when they reach 55 °C.
# Correction values are applied from left to right in the same order as the
# temperatures are read from the file.
#
# For example:
# tp_thermal /proc/acpi/ibm/thermal (0, 0, 10)
# will add a fixed value of 10 °C the 3rd value read from that file. Check out
# http://www.thinkwiki.org/wiki/Thermal_Sensors to find out how much you may
# want to add to certain temperatures.

#  Syntax:
#  (LEVEL, LOW, HIGH)
#  LEVEL is the fan level to use (0-7 with thinkpad_acpi)
#  LOW is the temperature at which to step down to the previous level
#  HIGH is the temperature at which to step up to the next level
#  All numbers are integers.
#

# I use this on my T61p:
#tp_fan /proc/acpi/ibm/fan
#tp_thermal /proc/acpi/ibm/thermal (0, 10, 15, 2, 10, 5, 0, 3, 0, 3)

hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp2_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp5_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp3_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp4_input


(0,     0,      35)
(1,     30,     40)
(2,     35,     45)
(3,     40,     50)
(4,     45,     55)
(5,     50,     60)
(7,     55,     32767)


I’ve been recently haunted by thinkfan 1.2 failing to launch. because hardware locations not being defined consistently in between reboots. The official maintainer apparently made some changes to accept new syntax.

At least for the thinkfan versions available on OpenSUSE LEAP 15.2 and TW do not work as described (optional: true, index: [1,2,3,] … etc), and old syntax do not work either.

After struggling with rc.local, I found an awesome article: https://bookstack.mesrits.net/books/fedora-32/page/lenovo-thinkfan

to help me out and the following is summary.

While as root

su -

First:

mkdir -p /etc/systemd/system/thinkfan.service.dcat > /etc/systemd/system/thinkfan.service.d/10-restart-on-failure.conf << EOF
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=3


[Service]
Restart=on-failure
RestartSec=3
EOF

Second:

cat > /etc/systemd/system/thinkfan.service.d/00-generate-config.conf << EOF[Service]
ExecStartPre=-/usr/bin/thinkfan-config
EOF

Third:
Create a file /usr/bin/thinkfan-config


#!/usr/bin/env bash

# associative array to map sensors to names
declare -A SENSORS

function map_sensors() {
    for d in $(find ${1} -mindepth 1 -maxdepth 2 -type d -name 'hwmon*'); do
        SENSORS[$(cat ${d}/name)]=${d/${1}/}
    done
}

# map sensors from the following sysfs directories
map_sensors "/sys/devices/platform/coretemp.0/hwmon/"
map_sensors "/sys/devices/virtual/thermal/"

#echo ${SENSORS
[li]}[/li]#echo ${!SENSORS[@]}

# generate and replace configuration
cat > /etc/thinkfan.conf << EOF

##############################################################################

sensors:
  - hwmon: /sys/devices/platform/coretemp.0/hwmon/${SENSORS['coretemp']}/temp1_input
  - hwmon: /sys/devices/platform/coretemp.0/hwmon/${SENSORS['coretemp']}/temp1_input   
  - hwmon: /sys/devices/platform/coretemp.0/hwmon/${SENSORS['coretemp']}/temp1_input   
  - hwmon: /sys/devices/platform/coretemp.0/hwmon/${SENSORS['coretemp']}/temp1_input   
  - hwmon: /sys/devices/platform/coretemp.0/hwmon/${SENSORS['coretemp']}/temp1_input   
#  - hwmon: /sys/devices/virtual/thermal/${SENSORS['pch_skylake']}/temp1_input  
#  - hwmon: /sys/devices/virtual/thermal/${SENSORS['acpitz']}/temp1_input (-5)
#  - hwmon: /sys/devices/virtual/thermal/${SENSORS['iwlwifi_1']}/temp1_input

fans:
  - tpacpi: /proc/acpi/ibm/fan

levels:
  - [0, 0, 25]
  - [1, 25, 30]
  - [2, 30, 35]
  - [3, 35, 45]
  - [4, 40, 50]
  - [5, 45, 55]
  - [6, 50, 60]
  - [7, 55, 32767]

##############################################################################
EOF

then finally

systemctl disable thinkfan
systemctl enable thinkfan
systemctl start thinkfan

and everything works perfectly from then on.

Almost forgot, need to make the thinkfan-config to be executable as root

chmod +x /usr/bin/thinkfan-config