Categories
Howto

How to control Nvidia graphics card Fan Speed Automatically in Linux

In linux, the fan speed is not controlled by default and the card itself auto adjusts the fan speed; in this tutorial I’m going to teach a way to Automatically and Manually control the fan speed of an Nvidia graphics card on Linux with proprietary drivers at Boot and Reboot.

Table of contents:
1. Controlling Fan Speed manually (Mandatory step)
2. Controlling Fan Speed Automatically at boot with a script
3. Controlling Fan Speed Automatically at boot with the Green With Envy GUI
4. Controlling Fan Speed Headlessly

1.Controlling fan speed Manually (Mandatory configuration changes)

Nvidia doesn’t enable this feature by default and it’s on the user to enable it using the command line.
Back in the days, it used to be nvclock but the support was dropped in 2010. Here’s a short guide on how to control the fan using Nvidia X Server Settings.

The ‘Nvidia X server Settings’ application is installed along with the proprietary driver.The following command needs to be executed in Terminal to enable fan control in Nvidia X server Settings:

sudo nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration

Note that this might not work on some distributions and you may be required to edit /etc/xorg.conf.d/20-nvidia.conf and add the following lines:

Section "Device"
        # You may change the identifier number to your use case.
        Identifier      "Device0"
        Driver         "nvidia"
        BoardName      "GeForce GTX"
        VendorName     "NVIDIA Corporation"
        Option         "Coolbits" "28"
EndSection

Note: You may want to change the Coolbits value to your own needs. The reference sheet is available at http://download.nvidia.com/XFree86/Linux-… But it’s recommended to keep it at 28 to enable all the features.

After this, a reboot or a logout is required to apply the changes.

After the reboot/login, open the NVIDIA X Server Settings application 
nvidia xserver powermizer

Go to the ‘Thermal Settings’ section and you can control the fan speed by your own hands:
controlling fan speed in nvidia xserver settings

2.Controlling fan speed Automatically at boot with a script (Step 1 required)


Now this was only controlling it manually through the nvidia-settings software. These changes will not apply at boot and do not auto adjust; but the changes were required in order to enable fan control.
I found a little program on github to control the fan speed with a fan curve:

Download the program from github with this command:

cd ~/
git clone https://github.com/nan0s7/nfancurve

after that, cd to the directory which it downloaded in:

cd nfancurve

now we see a few files:

config
LICENCE
nfancurve.service
README.md
temp.sh
USAGE.md

The only file which needs to be modified is the config file; inside this file, fan curve and some other options can be set; here are some of the important ones:

min_t="25" # This is the temperature which any number below it will cause the fan speed to drop to 0
fcurve = "30 37 45 55 57" # Fan Speeds

tcurve = "45 55 65 75 85" # Temperatures

Now in this example; the fan speed would be 30% at the temperature of 45 Celsius, 37% at 55 Celsius and so on. after changing the values to your preference, save the changes.
The fan speed is controlled by file temp.sh. First make the script, executable with the command below:

chmod +x ./temp.sh

Then run the script:

./temp.sh

If everything is working fine, the fan speed will adjust and you’ll see the changes on your terminal. Now stop the script by using CTRL+C.

Now if I want the script to run at reboot without being bothered; it can be added to the startup applications manager of the DE(kde has ~/.config/autostart-scripts/) or add it to ~/.xprofile. The latter is highly recommended since it will start whenever your X server has started and every distribution supports it.

If you want to add it to your Desktop Environment’s startup application manager; just simply search it and add the temp.sh script wherever you saved it. Every Desktop Environment is different and the process is super easy; so I’m not including it in this tutorial. You can search for it for your own Desktop Environment.

To add this script to~/.xprofileand make it executable; do as follows:

echo '~/nfancurve/temp.sh &' >> ~/.xprofile
chmod +x ~/.xprofile

Or just edit it with your own text editor. Note that this file might not exist in some cases; but it will execute anyways.

Save the file and wallah! Now the script will run and auto adjust the fan speed by the curve set at boot.

3.Controlling fan speed Automatically at boot with the Green With Envy GUI

There is a nice GUI to properly control Nvidia graphics cards in linux called Green With Envy or GWE for short.

It’s not available in ubuntu’s official repos as of now but it’s available on flatpak. Setup flatpak using this link: https://flatpak.org/setup/.

After setting up flatpak; install GWE with the following commands:

flatpak install flathub com.leinardi.gwe

After that, you can run it with the following command:

flatpak run com.leinardi.gwe

Working with the GUI is pretty easy and straightforward(Hell, that’s why I introduced it) and doesn’t require explanation.

This program can be added to startup by adding the above to ~/.xprofile; To do so, execute the following:

echo 'flatpak run com.leinardi.gwe --hide-window &' >> ~/.xprofile

By default, this program cannot add itself to startup but the above will work around that.

4. Controlling Fan Speed Headlessly

In order to control an nvidia graphics card’s fan speed headlessly; an X server needs to be started. It can be the minimum. Just to get X initialized; then nvidia-settings will work and so will tools such as nfancurve.

There is a great tool to do that automatically by starting an X server for each gpu: https://github.com/andyljones/coolgpus

Apparently nvidia unlike amd doesn’t provide hwmon in sysfs in order to control the fans. 

Subscribe
Notify of
guest
32 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
nvidias

There is a free tool ‘Green With Envy’ for nvidia cards. Using this software you can easy set up a custom fan curve.

Genofiend

the script do not execute at startup on ubuntu 20.04

Genofiend

thank you very much for the update

Anon

You’re a goddamn legend

ProDigit

Script says ‘min_t2 is greater than the first value in the tcurve2!’ This is not true, as t2 is set to 20, and tcurve2 is set to 35.   I would like to ask to add power limiting to the script as well. Eg: When temperature gets to 80c, limit power to 160W. If it gets to 84C, limit power to 130W; through the command: sudo nvidia-smi -pl 130   Third, some people have 2 GPUs. The above command can be modified by doing: sudo nvidia-smi -i 0 pl 130 sudo nvidia-smi -i 1 pl 145 In case one wants… Read more »

Kelvin

I get a blank screen after editing the xorg-conf. How do I go around this?

Kelvin

Hey countercookie, I managed to solve it (hopefully.. Will reboot and test it out again later tonight as I am remoting and have no access to the pc in case anything happens). Just FYI, I am running dual GPU setup on my PC. Both RTX2080Ti. When I ran the set of codes, no Xorg.conf was found, so it was created for me manually. It had problems cause it just gave me a blank screen. When I switch to another terminal, it hangs too, and does not allow me to access anything. At first, I took the long path and reinstalled… Read more »

Last edited 3 years ago by Kelvin
Kelvin

Hi,

You did mention that I would have to enter those device sections into /etc/xorg.conf.d/20-nvidia.conf but I do not seem to have that folder. I am very confused too as there are quite a few number of things such as xorg.con.d missing for my PC. Do you mind helping me out on this?

Kelvin

Hey hey, no need to apologise. I’m learning a lot from your post, and just by having a conversation with you I’m learning much more. Thank you for that! I’ve listened to your advice and I generated a new Xorg.conf by using the nvidia-xconfig command. I added cool-bits = 4 and everything works fine now. I am able to control both the GPU fans.Thank you for helping out on this. Noted on the log. So far, all is well, and there are no errors! Again, thank you so much for the help, countercookie. Appreciate it a lot. Your post is… Read more »

daniel

Thanks so much hombre! It really helped me in my Ubunru 20 with my RTX2080. I allways forgot to start the fans manualy at the start of the session and the temp were 50-55 while coding… Now it’s history :))
Tnx!

John Rose

I’m running Ubuntu Focal (i.e. 20.04) on an Aorus B450 Pro Wifi motherboard with an AMD Ryzen 3 3100-U CPU & an Asus NVIDIA GeForce GT710 graphics card, as stated in the NVIDIA X Server Settings app. I’ve tried the ‘Controlling fan speed Automatically at boot with a script’ method. However, nfancurve (running temp.sh using the default config file) shows “No fans detected”. Any ideas?

John Rose

Thanks for suggestions. I didn’t do the cool-bits stuff in method 1 (Controlling fan speed Manually) because I wanted to use method 2 (Controlling fan speed Automatically at boot with a script) and didn’t realise that I had to do method 1 first. I’ve tried the ‘cool bits’ command in method 1 and it gave: sudo nvidia-xconfig -a –cool-bits=28 –allow-empty-initial-configuration [sudo] password for john:  WARNING: Unable to locate/open X configuration file. Package xorg-server was not found in the pkg-config search path. Perhaps you should add the directory containing `xorg-server.pc’ to the PKG_CONFIG_PATH environment variable No package ‘xorg-server’ found Option “AllowEmptyInitialConfiguration” “True”… Read more »

NVIDIA Thermal Settings Screenshot.png
Last edited 3 years ago by John Rose
John Rose

Apologies for wasting your time. My grandson built this computer and he’s not very communicative. There are 2 fans: one mounted on top of the CPU’s heat sink & the other attached to the motherboard/case (not sure which) but near the graphics card. I mistakenly thought that the second was attached to the graphics card. The BIOS has allowed me to set fan speeds according to temperature. So I’ve done that for the second fan (called SYS_FAN1 by the BIOS) so as to have it off until the graphics card reaches 50 degrees. I clean installed Ubuntu 20.04 on this… Read more »

tomcat

Hey, newbie to Linux here. Thanks very much for the tutorial.

This is probably a stupid question, but will this also work with EVGA cards? I know that in Windows you need to use their X1 software in order to get all three fans spinning, and with my fresh install of Garuda Linux I only have one fan running.

tomcat

Thank you for your detailed response. I’ll give it a try!

Davide Baldelli

hi, i did every step but it looks like xprofile does not start at boot (and yes, i’ve gave it exec permissions)

wavey

sudo nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration use this command with care! After executing it and rebooting, i got stuck at blank screen. This is a guide for anyone with the same issue. ALSO keep in mind that im a beginner and just sharing what worked for me. THIS STEP IS NEEDED ONLY IF YOU HAVE SPLASH SCREEN ENABLED. if you have splash screen enabled, you need to disable it. To do this, press shift (if that doesnt work try esc or space) at boot when manufacturers logo is shown. In case of dualbooting, press shift right after you picked linux. now… Read more »

justdial share price bse

Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.