This script automates the deployment and configuration of a custom fan control solution for ThinkPad laptops. It performs the following actions:
- Root Access & ACPI Verification: Ensures the script runs as root and that the ThinkPad ACPI module is configured with
fan_control=1. - GRUB Boot Parameter Update: Adds
thinkpad_acpi.fan_control=1to the kernel boot parameters and runsupdate-grub. - Kernel Module Reloading: Attempts to reload the
thinkpad_acpimodule (or advises a reboot if it’s built into the kernel). - Installation of Custom Fan Control Script: Installs
thinkfan-exwhich:- Monitors temperature sensor files.
- Maps temperatures to fan levels.
- Supports command-line options:
-status: Displays current fan status and sensor temperature readings.-config: Opens the configuration file (/etc/thinkfan-extreme.conf) for editing.-uninstall: Removes the fan control setup (script, systemd service, GRUB changes, and bash completion).-help/--help: Displays usage information.
- Systemd Service Unit & Bash Completion: Creates and enables a systemd service (
thinkfan-extreme.service) and installs bash completion for ease of use. - Logging: Detailed logs are written to
/var/log/thinkfan-extreme.log.
-
Download the Script: Save the deployment script (for example, as
/home/$USER/Downloads/thinkfan-extreme.sh). -
Make It Executable:
sudo chmod +x /home/$USER/Downloads/thinkfan-extreme.sh -
Run the Script as Root:
sudo /home/$USER/Downloads/thinkfan-extreme.sh - Reboot the System: A reboot is recommended to ensure all kernel and module changes are applied.
# Exemple of how to set up your config file# Critical temperature in millidegrees Celsius (75000 = 75°C) #CRITICAL_TEMP=75000
# Temperature thresholds for each fan level (in millidegrees Celsius). #declare -A level_threshold #level_threshold[0]=40000 #level_threshold[1]=45000 #level_threshold[2]=50000 #level_threshold[3]=55000 #level_threshold[4]=60000 #level_threshold[5]=65000 #level_threshold[6]=70000 #level_threshold[7]=75000
# Critical temperature in millidegrees Celsius (76000 = 76°C) CRITICAL_TEMP=76000
# Temperature thresholds for each fan level (in millidegrees Celsius). declare -A level_threshold level_threshold[0]=40000 level_threshold[1]=45000 level_threshold[2]=50000 level_threshold[3]=55000 level_threshold[5]=65000 level_threshold[6]=70000 level_threshold[7]=76000
This Bash script automates the deployment and configuration of a custom fan control solution for ThinkPad laptops. It ensures proper ACPI settings and installs a custom fan control script (thinkfan-ex), a systemd service unit, and bash completion for enhanced command-line usability.
- Root Privilege Verification: The script checks that it’s run as root.
- ACPI Configuration: Ensures
/etc/modprobe.d/thinkpad_acpi.confcontainsfan_control=1(with backup creation if needed). - GRUB Boot Parameter Update: Appends
thinkpad_acpi.fan_control=1to the kernel boot parameters and runsupdate-grub. - Kernel Module Management: Reloads the
thinkpad_acpimodule if possible, or advises a reboot if the module is built into the kernel. - Custom Fan Control Script: Installs
thinkfan-exwhich:- Dynamically reads temperature sensor files.
- Maps temperatures to discrete fan levels (0 to 7, or “level disengaged” for critical temperatures).
- Supports command-line options:
-status: Displays current fan status and sensor temperature readings.-config: Opens the configuration file (/etc/thinkfan-extreme.conf) for editing.-uninstall: Uninstalls the fan control setup, disables its systemd service, reverts GRUB changes, and removes bash completion.-helpor--help: Shows usage information.
- Systemd Service Unit: Creates and enables
thinkfan-extreme.serviceto runthinkfan-excontinuously at boot. - Bash Completion: Installs a bash completion file for streamlined command usage.
- Logging: Detailed events are logged to
/var/log/thinkfan-extreme.logfor troubleshooting.
- ThinkPad ACPI Kernel Module: Must be loaded with
fan_control=1. - Root Access: Both the deployment script and the installed components require root privileges.
- GRUB Update: Kernel boot parameter changes will need a reboot to take effect.
Once installed, the custom fan control script (thinkfan-ex) will run as a service at boot. It continuously monitors temperature sensors and adjusts fan speeds accordingly.
-
-status: Display the current fan control status and sensor temperature readings. -
-config: Open the configuration file (/etc/thinkfan-extreme.conf) for editing. -
-uninstall: Uninstallthinkfan-ex, disable its systemd service, revert GRUB changes, and remove bash completion. -
-helpor--help: Show usage information and available options.
To remove the fan control setup, run:
sudo thinkfan-ex -uninstallThis command will:
- Stop and disable the systemd service.
- Remove the
thinkfan-exscript and bash completion. - Revert the GRUB boot parameter changes.
All events during deployment are logged to /var/log/thinkfan-extreme.log. Check this file for troubleshooting or to verify successful configuration. To continuously monitor the log, use:
tail -f /var/log/thinkfan-extreme.log-
Module Reloading: If the
thinkpad_acpimodule is built into your kernel (and thus cannot be reloaded), a reboot is required for configuration changes to take effect. -
Fan Control Verification: After configuration, the script displays current fan settings from
/proc/acpi/ibm/fan.
This project is licensed under the MIT License.
Bruno Bellizzi Grande
Last updated: March 10, 2025