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
Go to the ‘Thermal Settings’ section and you can control the fan speed by your own hands:
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
cd to the directory which it downloaded in:
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:
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
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.
There is a free tool ‘Green With Envy’ for nvidia cards. Using this software you can easy set up a custom fan curve.
Yes, also painless over/down clocking and startup. Will be updating the article some time.
the script do not execute at startup on ubuntu 20.04
Sorry, I updated the article with a solution that works for every distribution.
thank you very much for the update
You’re a goddamn legend
Thanks for the compliments.
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 »
I just realized that nfancurve changed how it interprets the fan curves and temperatures (
tcurve) from arrays(using parentheses for array literals ) to strings; Updated the article; Test it now. If the problem still persists; you could comment out
which_curveto bind the fans. Thanks for the contribution for power limiting. Will leave it here. Someone might find it useful. You could also fork the project on github and link your fork here.
I get a blank screen after editing the xorg-conf. How do I go around this?
Well, You should edit the file with respect to your machine.
Maybe you can give me the contents of
/var/log/Xorg.0.logand maybe I can help you with the errors it’ll give.
You can do that by switching to another terminal with Ctrl+Alt+f2 or f3 or … and login.
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 »
Hey, Glad it’s working for now. When you install the nvidia drivers, at first it always creates a /etc/X11/xorg.conf for you which has fundamental configuration to get the display to show such as Screen entry. You can always regenerate this with the nvidia-xconfig command. All you need to do is enter those device sections (Section Device) into the /etc/X11/xorg.conf.d/20-nvidia.conf config file and that’ll work a treat! I tested with Ubuntu and Arch that entering your device sections in the xorg.conf.d directory is better and applies all the settings. In your case, it’s a bit weird. I suggest you get physical… Read more »
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?
Sorry about all the problems I’ve caused. I meant
/var/log/Xorg.0.logwhenever it has problems showing something. We may tell a lot just from that.
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 »
You’re very welcome. Glad it’s all working now but if it messes up again, don’t hesitate to post the log here; I’ll reply as quickly as I can.
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 :))
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?
Hi, First make sure that
nvidia-smiand the NVIDIA X Server Settings show your fan. Have you gone through the first step of setting the
cool-bits? I included another method of creating 20-nvidia.conf since that seems to work better. A reboot is preferred after such changes.
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 »
As I see from the errors, it says that you don’t have xorg even installed which doesn’t make any sense; I suppose that tool looks for deprecated environment variables but those errors shouldn’t bother the tool just writing fan. And yes you can make the xorg.conf.d directory yourself and add the 20-nvid… file yourself, no problem. I also tried searching for your graphics card “Asus NVIDIA GeForce GT 710” and there doesn’t seem to be a version with fan. I’m confused about what fan you’re hearing. Please elaborate. You don’t need to worry about that last line of the log;… Read more »
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 »
Oh no problem :).
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.
This method will probably work on every card as long as it’s an Nvidia running with proprietary drivers. But EVGA could be using a specific solution to control the 3 fans separately. This is probably not overlooked by them and the fans will get controlled by the bios in the worst case scenario to prevent overheating.
Having only that one fan running probably is the lowest mode for cooling the card with no noise and it’ll probably ramp up during loads. Try testing the card with a benchmark.
Thank you for your detailed response. I’ll give it a try!
hi, i did every step but it looks like xprofile does not start at boot (and yes, i’ve gave it exec permissions)
Hi, I can’t keep with every change ubuntu or every other distribution or DE makes. The SDDM login manager runs
.xprofileafter the X server has started which is what we want. Try searching in your DE’s for startup programs and add the script there. Tell me your result.
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 »
Thanks, but doesn’t the
nvidia-xconfigcommand write the configuration into
/etc/X11/xorg.conf? doesn’t deleting the file just reverse what the command did? Could you elaborate by providing your X log file after the blank screen? it’ll be either
~/.local/share/xorg/Xorg.0.log. Thank you.
Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.