A Bash script that automatically controls NVIDIA GPU fan speeds based on temperature thresholds. The script monitors GPU temperatures and adjusts fan speeds accordingly to maintain optimal cooling while minimizing noise. Supports multi-fan GPUs.
- Automatic GPU-to-fan mapping using nvidia-settings verbose output
- Temperature-based fan curve with configurable thresholds
- Support for multiple GPUs and their associated fans
- Runs continuously in the background with 5-second intervals
- Minimal resource usage
- NVIDIA GPU with proprietary drivers installed
nvidia-settingsutility (part of the NVIDIA driver package)- Linux system with systemd (Ubuntu 20.04+, Kubuntu 24.04+, etc.)
- Root/sudo privileges for fan control
git clone https://github.com/avtc/gpu-fan-control.git
cd gpu-fan-controlchmod +x gpu-fan-control.shThe most robust way to run the fan control script permanently is to create a systemd service. This ensures the script starts automatically on boot and restarts if it fails.
- Create the service file:
sudo nano /etc/systemd/system/gpu-fan-control.service- Paste the following content into the file:
[Unit]
Description=NVIDIA GPU Fan Control Script
After=network.target multi-user.target graphical.target nvidia-persistenced.service
[Service]
Type=simple
ExecStart=/path/to/your/gpu-fan-control/gpu-fan-control.sh
Restart=on-failure
RestartSec=10
User=root
Group=root
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetImportant: Replace /path/to/your/gpu-fan-control/gpu-fan-control.sh with the actual absolute path where you cloned the repository (e.g., /home/username/gpu-fan-control/gpu-fan-control.sh).
- Save the file:
Press
Ctrl+O, thenEnter, thenCtrl+Xto exit nano.
- Reload the systemd daemon:
sudo systemctl daemon-reload- Enable the service to start on boot:
sudo systemctl enable gpu-fan-control.service- Start the service immediately:
sudo systemctl start gpu-fan-control.service- Check the service status:
sudo systemctl status gpu-fan-control.serviceYou should see "Active: active (running)".
- View the logs:
sudo journalctl -u gpu-fan-control.service -f- Test after reboot:
sudo rebootAfter rebooting, verify the service is running:
sudo systemctl status gpu-fan-control.serviceFor systems with multiple GPUs (like 8x RTX 3090), you may want to set power limits automatically on system startup to ensure consistent performance and thermal management. This can be achieved using a systemd service.
- Create the power limit service file:
sudo nano /etc/systemd/system/gpu-power-limit.service- Paste the following content into the file:
[Unit]
Description=Set NVIDIA GPU Power Limit
After=network.target multi-user.target graphical.target
Wants=nvidia-persistenced.service
# Ensure nvidia-persistenced is started if you use it
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/nvidia-smi -pm 1
# Enable persistence mode for all GPUs
ExecStart=/usr/bin/nvidia-smi -i 0 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 1 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 2 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 3 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 4 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 5 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 6 -pl 280
ExecStart=/usr/bin/nvidia-smi -i 7 -pl 280
# Add more ExecStart lines for additional GPUs (e.g., -i 2, -i 3, etc.)
[Install]
WantedBy=multi-user.target- Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable gpu-power-limit.service
sudo systemctl start gpu-power-limit.service- Verify the power limits:
nvidia-smi -q | grep "Power Limit"- Power Limit Value: The example uses
280watts, which is typical for RTX 3090. Adjust this value based on your GPU model and requirements. - GPU Count: Modify the number of
ExecStartlines to match your GPU count. - GPU Indices: Ensure the GPU indices (
-i 0,-i 1, etc.) match your actual GPU configuration.
- This service sets power limits to 280W for each GPU, which is common for RTX 3090 cards
- The
ExecStartPre=/usr/bin/nvidia-smi -pm 1line enables persistence mode for better performance - Power limits are applied before the fan control service starts, ensuring optimal thermal management
- Adjust the power limit value according to your specific GPU model and power supply capabilities
The script uses the following temperature-to-fan-speed mapping:
| Temperature Range | Fan Speed |
|---|---|
| < 35°C | 20% |
| 35-39°C | 30% |
| 40-49°C | 40% |
| 50-59°C | 50% |
| 60-64°C | 60% |
| 65-69°C | 70% |
| 70-79°C | 75% |
| 80-89°C | 80% |
| ≥ 90°C | 90% |
-
Permission Denied:
- Ensure the script is executable:
chmod +x gpu-fan-control.sh - Make sure the service runs as root (configured in the service file)
- Ensure the script is executable:
-
X Authority Error:
- The script automatically detects the X authority file
- If you encounter issues, ensure you're running in a graphical session
-
NVIDIA Driver Issues:
- Verify
nvidia-settingsis working:nvidia-settings -q gpus - Check that the NVIDIA persistence daemon is running:
systemctl status nvidia-persistenced.service
- Verify
-
Service Not Starting:
- Check the logs:
sudo journalctl -u gpu-fan-control.service -b - Verify the path in
ExecStartis correct - Ensure all dependencies are installed
- Check the logs:
To test the script manually before setting up the service:
sudo ./gpu-fan-control.shPress Ctrl+C to stop the script.
Edit the temperature thresholds in gpu-fan-control.sh:
# Fan curve
if (( temp < 35 )); then
speed=20
elif (( temp < 40 )); then
speed=30
# ... add your custom thresholds here
else
speed=90
fiModify the sleep duration at the end of the main loop (line 72):
sleep 5 # Change 5 to your preferred interval in seconds- This script enables manual fan control, overriding the default NVIDIA driver settings
- Monitor your GPU temperatures initially to ensure the fan curve is appropriate for your hardware
- The script includes safety limits (maximum 90% fan speed) to prevent excessive wear
- Always test in a controlled environment before deploying to production systems
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This software comes with no warranty. Use at your own risk. The authors are not responsible for any damage to your hardware.