How to set fanspeed in Linux from terminal

Hi,
New here, and I’m sure I have this post in the wrong thread, as I couldn’t find where it would fit.

I’m just trying to find help on how to manually set my fan speed on my Nvidia GPU.
the command:
nvidia-settings -a “[gpu:0]/GPUFanControlState=1” -a “[fan:0]/GPUCurrentFanSpeed=n”
gives a read-only error.

What can I type in terminal?
I’m running Lubuntu 18.10 with Nvidia 418.56 drivers.

Thanks!

2 Likes

Outside my area of expertise, but the various write-up on how to control the fan under Linux one can find on the internet typically state that you need to enable cool bits first before you are able to set fan speed with nvidia-settings. I see different idioms being used. A fairly common one seems to be

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

Proceed at your own risk. Why do you want to change the fan speed from the default?

Because I like my GPUs to run cooler.
Under full load they get to the high 70s, but by increasing the fan by 25% they run in the high 60s, which gives better overclocks.

I know in GUI to change fan speed, but I can’t find a headless terminal command for it.

While I believe Cool-bits=4 enables fan speed editing, Cool-bits 28 works as well.
However the gui is needed for that.
I guess I was hoping someone could post a terminal command, to modify fanspeed.
We need a headless (terminal based) variety of nvidia-xsessions at the deep learning and folding community.

I hope NVidia could support us with a terminal command in the next of their driver updates.
Something as simple as:

sudo nvidia-smi -i 0 -f 75

Would suffice!
Just like adjusting the power levels, the above line stating NVidia smi card 0 (main card) set fanspeed at 75% (with values from 0% to 100%.

I’m also annoyed by cards that start thermal throttling before fan speed reaches 100%.

After setting cool-bits to 28 (4 or 31 might work too), you can set fan speed via:
nvidia-settings -a ‘[gpu:0]/GPUFanControlState=1’
nvidia-settings -a ‘[fan:0]/GPUTargetFanSpeed=100’

Edit: I see you used something similar, try “GPUTargetFanSpeed=” instead of “GPUCurrentFanSpeed=”, which is my guess why you got a read-only error!

1 Like

I’m not sure where you can enter those values, but it doesn’t work in my terminal.
Depending on why you use the GPU, if you have constant high GPU usage (like heavy gaming, or folding or crunching), the best thing you can do, is lower the TDP of the card.
It’ll still throttle the speed, but the card will run much cooler.

For reference, I have an open test bench, with an environment temperature of somewhere between 60-75F, and I can get 90-95% performance out of any RTX card running them at the following settings:

GPU , GPU 2: Running watt +x/-y watts

RTX 2060, 2060 Super: 126W +/-1 Watt
RTX 2070: 129W +4/-2 Watt
RTX 2070 Super, 2080: 144W +/-5 Watt
RTX 2080 Super: 149W +/-7 Watt
RTX 2080 Ti: 166W. +14/-12 Watt

I raise the value by x watts, if the ambient temperature gets closer to 85-90F.
I lower the value by y watts, if the ambient temperature gets closer to 55F.

Lowering the power, reduces heat. When heat goes lower, the driver will increase the boost frequency.
Together with a fine tuned overclock, you can get near to 95% of performance, at 60-75% of the power consumption. I’m not sure why Nvidia tunes for maximum performance, instead of highest efficiency on the RTX line, as these cards run very hot (inside a case), and consume a lot of power.

The performance penalty (~5-10%) is well worth the reduction in heat (20-40C lower temps) and power consumption (25-40% lower per card).

If you have an intermittent performance demand on your card, water cooling is offering a better solution.

I am having similar issue in CentOS7.
[root@XX ~]# nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration

Using X configuration file: “/etc/X11/xorg.conf”.
Option “AllowEmptyInitialConfiguration” “True” added to Screen “Screen0”.
Option “AllowEmptyInitialConfiguration” “True” added to Screen “Screen1”.
Option “AllowEmptyInitialConfiguration” “True” added to Screen “Screen2”.
Option “AllowEmptyInitialConfiguration” “True” added to Screen “Screen3”.
Backed up file ‘/etc/X11/xorg.conf’ as ‘/etc/X11/xorg.conf.backup’
New X configuration file written to ‘/etc/X11/xorg.conf’

[root@XX ~]# nvidia-settings -a ‘[fan:0]/GPUTargetFanSpeed=100’

ERROR: Unable to load info from any available system

Has anyone been successful in pulling the GUI. I cannot get that to work either
[root@XX ~]# nvidia-settings

ERROR: Unable to load info from any available system

Where can I find documentation on Cool-bits and how to control fan speed? My titans run at 83C and 87C when I am training my ai. The CPU is 66C.

ubuntu 18.04

I would say those are temperatures in the normal range for a GPU operating under full load. Looking at my GPU’s temperature right now, it shows 85 deg C, while running at 92% load. Your CPU is likely running cooler because it is not anywhere close to fully loaded (or maybe it’s a very efficient CPU). The six-core Intel CPU in my workstation here is under 100% continuous load from 14 tasks and currently shows a temperature of 86 deg C.

If those are two identical Titans it seems they may not be getting equal air flow, you might want to try spacing them further apart if the PCIe slot assignments allow for this.

Under full load, the drivers will try to not fry your GPU, but the GPU certainly runs too hot at anything over 75-80C!
In terminal you can set the power curve:
sudo nvidia-smi -i 0 -pl 150
Where ‘0’ is your primary GPU (and 1 would be your secondary, and so on…)
and ‘150’ is your capped wattage.

Overclocking and fan curve you can only access via X-server (which is accessible from the GUI).
To enable fan curve, type in terminal:
sudo nvidia-config --enable-all-gpus
(this might crash your desktop on any newer than 18.04 Linux OSes if you have more than 1 GPU)
then do:
sudo nvidia-config --cool-bits=4
where ‘4’ is the option to just enable fan curve, and 28 is the option to also enable overclocking.

I have many a times asked Nvidia to make a terminal command for fan curve and overclocking; as it won’t be too hard to implement (without accessing X-Config from the GUI); alas, Nvidia has never listened to any suggestions or feature request (like really, it’s probably an afternoon of coding for those who know what they’re doing, what will save hundreds of hours of people using the program…).

1 Like

If you just want a command:
nvidia-settings -a GPUFanControlState=1 -a GPUTargetFanSpeed=60
Shouldn’t need sudo/root/elevated permissions but YMMV.

But I wanted to give a full explanation/guide. I stumbled across this post while trying to find the answer myself, and through the answers here I found how to do it so I thought I’d give back the summary version with commands of what I did. The same command is near the end of this post as well:

Firstly you must make sure that you can use nvidia-settings at all - that may depend on OS, kernel, drivers, dependencies, etc. - sorry to neeraj but this may be worth looking up elsewhere.

Afterward, the coolbits option should, I believe, be able to be set with:
nvidia-xconfig --cool-bits=4

You might need to be root or have elevated permissions to do that. Or you can try to edit the config file yourself in case that doesn’t work, but YMMV.
In Manjaro, it should be location [1] though I’ve seen people say you can also have it at location [2]. In most other systems using X Server Display, it should be at location [3]. Still, please research and ideally use a command-line to do so, as there are also more possible locations I’ve seen mentioned:
[1] /etc/X11/mwhd.d/nvidia.conf
[2] /etc/X11/nvidia.conf
[3] /etc/X11/xorg.conf.d/20-nvidia.conf
[4] /etc/X11/xorg.conf
[5] /usr/share/X11/10-nvidia.conf

If editing the file, make sure that you put the option in the correct section. It should always be in Section "Device", and if you have more than one GPU you may have more than one of those sections, so you may want to add the option to each device you want to enable it on. Before the EndSection line, you should have a line with Option "Coolbits" "4" (Also all indentations on my file were in spaces, so make sure to match the file if it’s spaces or tabs, just in case).
So in summary the file should have at some point something like this (copied straight from my file, yours may differ, and it seems the spaces aren’t showing in this post):

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
Option "Coolbits" "4"
Option "NoLogo" "1"
EndSection

For which value you want for coolbits, I referred to this ArchLinux wiki article so add these up as you wish (each being a different bit in a binary number), but for fan control you only need 4 (bit 2).

With that, you may still need to restart your PC (or at least the X Display Server, or the Nvidia driver or daemon or what-have-you) for the config to take effect (if you used the command nvidia-xconfig it should work immediately but I’m not sure). Now you should always be able to use the GUI interface to set it, but to do it automatically through the command-line you first need to identify what you can do.

This command listed ALL attributes possible for nvidia-settings (fair warning, many lines of output, may be best to pipe it to a file):
nvidia-settings -e list

If you want all the queries with a description as well (fair warning, very big output):
nvidia-settings -q all

From that list I looked at all the entries that had ‘fan’ in them, for me they were:

GPUFanControlState (boolean)
GPUTargetFanSpeed (integer)
GPUCurrentFanSpeed (read-only)
GPUResetFanSpeed (??? - no information on query, might always reset the speed to zero when set? No clue.)
GPUCurrentFanSpeedRPM (read-only)
GPUFanControlType (read-only)
GPUFanTarget (read-only)

And you can use nvidia-settings -q <attribute name> to check each of them and what they do.
Some are read-only, so you can’t change them.

If you have more than one GPU and want to target only one, you can try nvidia-settings -q [gpu:0]/GPUCurrentFanSpeed but for me it showed nothing or, with -V all, that it couldn’t find display on any available system. :shrug:

Then you can run the -a ASSIGN option, or --assign=ASSIGN, to set the value of the ones you can control. So to set the fan speed:
nvidia-settings -a GPUTargetFanSpeed=60

And then you can check what speed the fan is at with:
nvidia-settings -q GPUCurrentFanSpeed

Finally, if you want the script to run every time you log in, one way is to create or modify the~/.xprofile file (you may need to set it as executable, and there are other ways but this works well enough for me) and just add the command to it with a & at the end of the line.

For example:

nvidia-settings -a GPUFanControlState=1 -a GPUTargetFanSpeed=50 & set GPU fan control on and the target fan speed.
nvidia-settings & #Open the GUI application anyway to make sure it worked.
#If you have KDE Konsole you can use this to keep the terminal open after executing. You should comment out or remove the first line and uncomment this one. Different terminal GUIs will have (slightly) different commands.
#konsole --noclose -e nvidia-settings -V all -a GPUFanControlState=1 -a GPUTargetFanSpeed=50 &

Hopefully this helps someone!

Edit: After testing the startup script, I had to add -a GPUFanControlState=1 as I had previously done that in the GUI (the little checkbox “Enable GPU Fan Settings”, which I promptly forgot - I actually thought it was just part of the interface and not a necessary command. ^^; ).

1 Like

I do confirm, -a '[gpu:0]/GPUFanControlState=1' does the trick:

nvidia-settings -V -c :0 -a '[gpu:0]/GPUFanControlState=1' -a '[fan:0]/GPUTargetFanSpeed='"30" -a '[fan:1]/GPUTargetFanSpeed='"40"

It’s sequential, so GPUFanControlState should be before setting up fan speed.

I can confirm that the command below are working fine:

## Open a terminal and type
nvidia-settings 

# This will generate a nvidia-settings.rc configuration file that is needed for running commands via terminal. 

# Change the fans speed on all GPUs 
nvidia-settings -a GPUFanControlState=1 -a GPUTargetFanSpeed=60

# Change fans speed on specific GPUs 
nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=60

# Check all atributes that can be used 
nvidia-settings -e list 

Now the problem that I am facing is that this work on the system with GUI using a terminal there but if I connect to the machine via SSH I cannot run those commands, I am not sure what I am missing, this is the error I am getting:

Unable to init server: Could not connect: Connection refused

ERROR: The control display is undefined; please run `nvidia-settings --help`
       for usage information.

Can someone tell me what I am missing when connecting via SSH?

Thanks

I can confirm that the command below are working fine:

💡 Important: coolbits need to be enable with the xorg.py file before performing nvidia-settings command line

## Open a terminal and type
nvidia-settings 

# This will generate a nvidia-settings.rc configuration file that is needed for running commands via terminal. 

# Change the fans speed on all GPUs 
nvidia-settings -a GPUFanControlState=1 -a GPUTargetFanSpeed=60

# Change fans speed on specific GPUs 
nvidia-settings -a [gpu:0]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=60

# Check all atributes that can be used 
nvidia-settings -e list 

Now the problem that I am facing is that this work on the system with GUI using a terminal there but if I connect to the machine via SSH I cannot run those commands, I am not sure what I am missing, this is the error I am getting:

Unable to init server: Could not connect: Connection refused

ERROR: The control display is undefined; please run `nvidia-settings --help`
       for usage information.

Can someone tell me what I am missing when connecting via SSH?

Thanks

1 Like

Have you tried to use sudo for SSH?

In some cases you’ll need to ‘-t’ or ‘tt’ to get su privileges.

Yes I tried sudo and same results

1 Like

nvidia-settings is a graphical application. attempting to run it, even from just the command line, over SSH from a local to a remote machine, is likely to try to connect with the x-server in the remote machine.

x servers are generally configured to refuse non-local connections. You might try doing ssh -Y on linux, or using an SSH client on windows that supports x forwarding, such as Mobaxterm.

I haven’t tried this myself, at least not recently, so there may be more steps involved.

Try adding the --display command the address of the X server running your gui (most likely :0):

nvidia-settings --display :0 -a GPUFanControlState=1 -a GPUTargetFanSpeed=60

The very first command “nvidia-settings”, doesn’t work. it gives the following:

Unable to init server: Could not connect: Connection refused

ERROR: The control display is undefined; please run `nvidia-settings --help` for usage information.

Adding ‘-y’ to ssh also doesn’t change this.

The suggestion was to use “-Y”, not “-y”.