Skip to content

Instantly share code, notes, and snippets.

@pythonhacker
Last active September 5, 2023 05:20
Show Gist options
  • Save pythonhacker/cca8e65f3ffa1639d2ab196d917cd760 to your computer and use it in GitHub Desktop.
Save pythonhacker/cca8e65f3ffa1639d2ab196d917cd760 to your computer and use it in GitHub Desktop.
Controlling fan speed on Lenovo Thinkpad running antiX (or other Debian derivatives)

About

This is a write up on how to use thinkfan on Lenovo ThinkPads running antiX Linux. I am writing from my (bad) experience after installing antiX Grup Yorum 21 on a Lenovo ThinkPad P15s with the fan running constantly at max speed.

This is based on the guide provided at https://gist.github.com/Yatoom/1c80b8afe7fa47a938d3b667ce234559 however since the thinkfan utility does not seem to be available in the default repos of antiX Linux, it also includes steps to build the utility from source code - plus other tweaks for Thinkpad.

Try installing from repo

 $ sudo apt install thinkfan

If this works - great! (However this most likely fails on antiX). If it failed go to the step below.

Build and installthinkfan from source

Thinkfan can be downloaded from its sourceforge project site - https://sourceforge.net/projects/thinkfan/ . Unarchive the package to a folder.

Install the dependencies,

$ sudo apt update && sudo apt install cmake libyaml-cpp-dev pkg-config -y
$ cd thinkfan-1.2.1
$ cmake .
$ make
$ sudo make install

If everything goes right this will install thinkfan to /usr/local/sbin folder.

Also install acpitool - this will be useful to check the fan speeds.

$ sudo apt install acpitool -y

Create thinkfan configuration file - /etc/thinkfan.conf

$ sudo su
$ find /sys/devices/platform/thinkpad_hwmon/ -type f -name 'temp*_input' | xargs -I {} echo "hwmon {}" > /etc/thinkfan.conf

Add the control levels to the file as indicated in the referral gist above. These have been reproduced below.

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

Your thinkfan configuration should finally look something similar to below:

hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp6_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp3_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp7_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp4_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp1_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp5_input
hwmon /sys/devices/platform/thinkpad_hwmon/hwmon/hwmon4/temp2_input

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

Add fancontrol to thinkpad_acpi

$ echo "options thinkpad_acpi fan_control=1" > /etc/modprobe.d/thinkfan.conf
$ rmmod thinkpad_acpi && modprobe thinkpad_acpi

Check with lsmod | grep thinkpad_acpi if this worked or not.

Check current state of fan

If your fan is running at max speed (apart from hearing the obvious noise!) - you should see something like this,

 $ acpitool -f
 Fan            : enabled
 Fan Speed      : 3979 RPM

The fan speed would be above 3000 RPM.

Start thinkfan

$ thinkfan -s 10

It immediatley daemonizes and goes to background.

You should see your CPU fan slowing down and going quiet if everything has gone right till this point.

Check by,

$ acpitool -f
Fan            : enabled
Fan Speed      : 1980 RPM

NOTE: thinkfan dynamically alters the speed of the fan by sampling CPU temperatures. It does not switch the fan on or off or set it at a fixed average speed.

Startup

Edit /etc/modules and add the following lines.

 thinkpad_acpi
 coretemp

Refer to https://www.antixforum.com/forums/topic/how-do-i-start-a-daemon/ on writing a init script for starting the thinkfan as a daemon at boot time.

MX Linux

The same setup should work for MX Linux as well though I haven't tested it. Do try it out for other Thinkpad laptops running antiX/MX Linux and please give feedback.

@pythonhacker
Copy link
Author

The same setup works for Peppermint Linux.

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