Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Last active February 10, 2024 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miraculixx/a98a7c8a94a03ab7c3b4fae2637aef12 to your computer and use it in GitHub Desktop.
Save miraculixx/a98a7c8a94a03ab7c3b4fae2637aef12 to your computer and use it in GitHub Desktop.

Thinkfan Configuration for Lenovo X-Series

Why?

X-Series seems to have an issue with the fan control on suspend. In particular when thinkfan is active during suspending, the fan will continue to run indefinitely, even in suspended state.

How?

The systemd configuration used here simply stops thinkfan right before going to sleep, and reactivates it upon wakeup.

The solution adapts a comment made on thinkfan's github page, vmatare/thinkfan#181 (comment)

Installation

  1. Install thinkfan as per usual instructions

  2. Copy the ./etc/systemd files in this repository to their corresponding directories in /etc/ on your system

  3. Restart thinkfan

# https://github.com/vmatare/thinkfan/issues/181#issuecomment-1353799531
[Unit]
Description=Set fan to auto so BIOS can shut off fan during S2 sleep
Before=sleep.target
After=thinkfan-sleep.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t '%N' "Setting /proc/acpi/ibm/fan to 'level auto'"
ExecStart=/usr/bin/bash -c '/usr/bin/echo "level auto" > /proc/acpi/ibm/fan'
[Install]
WantedBy=sleep.target
[Unit]
Description=Notify thinkfan of imminent sleep
Before=sleep.target
[Service]
Type=oneshot
ExecStart=/usr/bin/pkill -x -pwr thinkfan
# Hack: Since the signal handler races with the sleep, we need to delay a bit
ExecStart=/usr/bin/sleep 1
[Install]
WantedBy=sleep.target
[Unit]
Description=Reload thinkfan after waking up from suspend
After=sysinit.target
After=suspend.target
After=suspend-then-hibernate.target
After=hybrid-sleep.target
After=hibernate.target
[Service]
Type=oneshot
# original: ExecStart=/usr/bin/pkill -x -usr2 thinkfan
ExecStart=/usr/bin/pkill -x -usr2 thinkfan
# thinkfan can exit with 1 if thinkfan is not running, and 0 if it was running. both is ok
SuccessExitStatus=0 1
# be sure to reload
ExecStartPost=/usr/bin/systemctl restart thinkfan.service
[Install]
WantedBy=sleep.target
options thinkpad_acpi fan_control=1
[Unit]
Description=Thinkfan, the minimalist fan control program
Documentation=man:thinkfan
After=sysinit.target
After=systemd-modules-load.service
[Service]
Type=forking
EnvironmentFile=-/etc/default/thinkfan
ExecStart=/usr/sbin/thinkfan $THINKFAN_ARGS $DAEMON_ARGS
PIDFile=/run/thinkfan.pid
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
Also=thinkfan-sleep.service
Also=thinkfan-wakeup.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment