Skip to content

Instantly share code, notes, and snippets.

@Yatoom
Last active Nov 24, 2021
Embed
What would you like to do?
Thinkfan configuration

Thinkfan setup

Note: I configured this thinkfan setup for my old Thinkpad w520 on Ubuntu 17.10.

1. Install necessary programs

Install lm-sensors and thinkfan.

sudo apt-get install lm-sensors thinkfan

2. Setup configuration

Find the temperature control devices with

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

Add them to /etc/thinkfan.conf, including (level, min_temperature, max_temperature):

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

(0,	0,	60)
(1,	60,	65)
(2,	65,	70)
(3,	70,	75)
(4,	75,	80)
(5,	80,	85)
(7,	85,	32767)

3. Enable fan control

echo "options thinkpad_acpi fan_control=1" > /etc/modprobe.d/thinkfan.conf
modprobe thinkpad_acpi
  • You can check with lsmod if thinkfan_acpi is running
  • To reload a module you need to remove it with sudo modprobe -r <module>, but this is not always possible, so we might need a reboot here.

4. Testing and running

To test thinkfan, use:

thinkfan -n

And to run it, use:

sudo service thinkfan start

And to retrieve the status, use:

service thinkfan status

5. Running on startup

To make it run at startup, we need to edit /etc/modules and add the lines below, to make the modules thinkpad_acpi and coretemp load at boot time. The thinkpad_acpi has to be loaded before coretemp.

thinkpad_acpi
coretemp

Note that this may change the /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp*_input paths (hwmon3 can become hwmon2 or vice versa), probably because of the order in which the modules are loaded or something. So, in the /etc/thinkfan.conf config, you might need to update these lines.

Furthermore, we need to enable the thinkfan service via systemctl.

sudo systemctl enable thinkfan.service
######################################################################
# 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
#hwmon /proc/acpi/ibm/thermal (0, 10, 15, 2, 10, 5, 0, 3, 0, 3)
#hwmon /sys/devices/virtual/hwmon/hwmon0/temp1_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp3_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp4_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp5_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp1_input
hwmon /sys/devices/platform/coretemp.0/hwmon/hwmon3/temp2_input
(0, 0, 60)
(1, 60, 65)
(2, 65, 70)
(3, 70, 75)
(4, 75, 80)
(5, 80, 85)
(7, 85, 32767)
@wuseman

This comment has been minimized.

Copy link

@wuseman wuseman commented Sep 11, 2019

Nice one!

For new visitors if you are lazy just use:

   find /sys/devices -type f -name "temp*_input"|sed 's/^/hwmon /g'
@woolfg

This comment has been minimized.

Copy link

@woolfg woolfg commented Nov 18, 2019

thanks +1 , just helped me to setup thinkfan on my T440s

@managervcf

This comment has been minimized.

Copy link

@managervcf managervcf commented May 7, 2020

Thanks! It helped with my X1C6.

@lukaspour

This comment has been minimized.

Copy link

@lukaspour lukaspour commented May 13, 2020

@managervcf HI, can you please share your x1c6 config?

Thanks! It helped with my X1C6.

@managervcf

This comment has been minimized.

Copy link

@managervcf managervcf commented May 16, 2020

@lukaspour

HI, can you please share your x1c6 config?

Actually, I have changed the thinkfan.conf file recently because of /proc/acpi/ibm/thermal consisting of 8 temperatures on battery and 16 temperatures on AC.

Every time I plugged/unplugged AC and rebooted, I got an unexpected behavior or an error from the thinkfan.service saying:

ERROR: Sensor /proc/acpi/ibm/thermal has 8 temperatures, but you have 16 correction values for it.

This variable number of temperatures (8 on battery vs 16 on AC) didn't let me use the simple syntax below.

tp_thermal /proc/acpi/ibm/thermal (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -66, 0, 0, 0, 0, 0)

(0,	0,	50)
(1,	50,	60)
(2,	60,	65)
(3,	65,	70)
(4,	70,	75)
(5,	75,	80)
(6,	80,	85)
(7,	85,	32767)

As I couldn't find any relevant info about this problem online, I tried experimenting with the complex example syntax (/usr/share/doc/thinkfan/examples/thinkfan.conf.complex).

Finally, this config below fixed my problem of variable number of temperatures to correct. Of course, fan levels and min/max thresholds are just an example that happens to work for my machine. I hope it will help you or anyone having a simiar problem.

######################################################################
## thinkfan 0.9 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.
##
#######################################################################
##
## This file shows how to use sensor-specific temperature limits.
## First of all, you need to specify temperature inputs. On a Thinkpad, you can
## just use:
##
tp_thermal /proc/acpi/ibm/thermal  # provides us with 16 temperature inputs

##
## On other systems, you have to specify a file in /sys/class/hwmon for each
## sensor you want to use. They are numbered in their order of appearance.
## For example:
#
# hwmon /sys/class/hwmon5/temp2_input           #1
# hwmon /sys/class/hwmon0/device/temp3_input    #2
#
## If you want to read temperatures directly from the hard disk, thinkfan needs
## to be compiled with -DUSE_ATASMART. Then you can do:
#
# atasmart /dev/sda                             #3
# ...
#
## You can have as many temperature inputs as you like. You should at get the
## temperature from the CPU, the GPU and the hard disk.
#

#
## Next we specify the fan we want to use. On a Thinkpad, this is:
#
tp_fan /proc/acpi/ibm/fan

#
## On anything other than a Thinkpad you'll probably use some PWM control file
## in /sys/class/hwmon. Remember that fan levels range from 0 to 255 and that
## they're just a number, not including the word "level" as seen below.
## A sysfs fan would be specified like this:
#
# pwm_fan /sys/class/hwmon/hwmon2/device/pwm1
#
## But remember you can only have one fan.

#
## Then you need to specify the temperature limits for each of the sensors.
## A dot means that the corresponding sensor should be ignored. The length of the
## UPPER and LOWER limits must be the same as the number of temperatures. In this
## example, /proc/acpi/ibm/thermal contains 16 sensors (on older thinkpads,
## there may be only 8), some of which are unused (hence the dots).
## A sysfs temperature input always contains only one sensor, so if you specify
## 5 sysfs files above, the length of your limits must be 5, too.
#
## I've come up with these preliminary settings for my Thinkpad T61p. They probably
## don't make sense for anything else, so you most definitely have to work
## something out for yourself.
#


{ "level 0"   # the fan level
# ^-------^   This works for /proc/acpi/ibm/thermal.
#             for a PWM fan in /sys/class/hwmon it would have to be just
#             0 or "0".
#
#    Sensor count:
#    1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
#    ==============================================
    (0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0)      # LOWER limit
    (50	.  .  .  .  .  .  .  .  .  .  .  .  .  .  .)      # UPPER limit
}


{ "level 1"
# ^-------^ For a PWM fan you may have to use something around 30 to get the
# same speed.
    (50 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (55 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 2"
    (55 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (60 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 3"
    (60 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (65 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 4"
    (65 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (70 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 5"
    (70 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (75 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 6"
    (75 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (80 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level 7"
    (80 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (85 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}

{ "level disengaged" # nice idea: "level auto" can also be used.
                     # but again: only numbers for sysfs.
    (85 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
    (99 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .)
}
@cohnt

This comment has been minimized.

Copy link

@cohnt cohnt commented Jul 1, 2020

Used this to help get thinkfan running on my P53. Thank you for sharing!

@dsboo

This comment has been minimized.

Copy link

@dsboo dsboo commented Dec 13, 2020

thanks very much i use this on my t480s:)

@sebfoucault

This comment has been minimized.

Copy link

@sebfoucault sebfoucault commented Jan 4, 2021

thanks very much i use this on my t480s:)

Hi @dsboo, Any specific adaptation for t480s that would be valuable to share ?

@kendoori

This comment has been minimized.

Copy link

@kendoori kendoori commented Feb 10, 2021

@managervcf your variant worked for me on my T480. It's been super difficult to get updated config for modern TPs

@jasonwert

This comment has been minimized.

Copy link

@jasonwert jasonwert commented Feb 12, 2021

@managervcf Thanks so much! This works great for me on a T440p using Kde Neon, I just had to change to 8 sensors from 16.

@grssnbchr

This comment has been minimized.

Copy link

@grssnbchr grssnbchr commented Apr 20, 2021

@managervcf Thanks, I'm using your config, but I still get the following error:

You have configured more temperature limits than sensors. That doesn't make sense.
Refusing to run without usable config file!

This is because sometimes my /proc/acpi/ibm/thermal has 8 readings, sometimes it has 16 (and it doesn't actually matter whether on AC or BAT). So I thought your config covers that variability.. maybe I'm doing something wrong?

@uguremirmustafa

This comment has been minimized.

Copy link

@uguremirmustafa uguremirmustafa commented Jul 5, 2021

This was helpful! I use it with my L14 gen1.

@jheled

This comment has been minimized.

Copy link

@jheled jheled commented Aug 2, 2021

Can someone tell me how to get the system fan control running again after I started thinkfan?

I tried 'sudo systemctl stop thinkfan', but the fan control remains off, and even
manually setting the fan (echo level 7 | sudo tee /proc/acpi/ibm/fan) fails to start the fan.

Thanks, Joseph

@wuseman

This comment has been minimized.

Copy link

@wuseman wuseman commented Aug 2, 2021

Can someone tell me how to get the system fan control running again after I started thinkfan?

I tried 'sudo systemctl stop thinkfan', but the fan control remains off, and even
manually setting the fan (echo level 7 | sudo tee /proc/acpi/ibm/fan) fails to start the fan.

Thanks, Joseph

After you execute the echo command please provide output fom ¨cat /proc/acpi/ibm/fan' command.

printf '%s' 'level 7' > /proc/acpi/ibm/fan
cat /proc/acpi/ibm/fan
@monosoul

This comment has been minimized.

Copy link

@monosoul monosoul commented Oct 17, 2021

Wrote an article with a configuration example for ThinkPad P14s (Gen 2) and a bit of deep dive into configuration settings: https://blog.monosoul.dev/2021/10/17/how-to-control-thinkpad-p14s-fan-speed-in-linux/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment