I found the bulk of my answer on Ubuntu Forums but the command to set the fan speed given was wrong. I also wrote the shell script myself (and I'm a noob), so feel free to comment how I did everything wrong, as long as you tell me how to fix it :) I added excessive comments so people who don't understand bash can get an idea of what I'm doing. This only works for 1 GPU, and will need modifications for multiple. By the way, the fan curve I have set is speed%=0.028*(degreesC^2)
.
Set-up
- Run your file browser of choice as root (in my case
sudo konqueror
).
- Go to
/etc/X11
and allow write access to all groups (but keep the window open).
- Open up the Nvidia X server settings window (
nvidia-settings
in the terminal).
- Go to the nvidia-settings configuration.
- Click Save Current Configuration and then click save on the pop-up window.
- Close Nvidia Settings and run
sudo nvidia-xconfig
, then again with --cool-bits=4
.
- Reboot.
Script
#!/bin/bash
# Put "sleep 30" here if you run it at start-up
# to make sure this starts after the Nvidia driver does.
fan="0"
gpu="0"
echo "GPU fan controller service started."
nvidia-settings -a "[gpu:$gpu]/GPUFanControlState=1" > /dev/null
check="$(nvidia-settings -a \"[fan:$fan]/GPUTargetFanSpeed=30\" | tr -d '[[:space:]]')"
working="Attribute'GPUTargetFanSpeed'($(hostname):0fan:$fan)assignedvalue30."
if [[ "$check" != "$working" ]]; then
echo "error on fan speed assignment: $check"
echo "Should be: $working"
exit 1
fi
while true
do
degreesC="$(nvidia-smi -i $gpu | grep -owEe '[0-9]+C')"
fanSpeed=$(($degreesC ** 2))
fanSpeed=$(($fanSpeed / 50))
if [[ $fanSpeed -gt 100 ]]
then
fanSpeed=100
fi
nvidia-settings -a "[fan:$fan]/GPUTargetFanSpeed=$fanSpeed" > /dev/null
sleep 8
done
I probably won't be updating this in the future, as I'll be upgrading to an RX 480.