How to set fanspeed in Linux from terminal

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