Have a laptop that is running Linux? Don’t have control of your fans? Maybe this lightweight utility will help you regain your ability to control them!
Note: For the purpose of this tutorial we will be working with Ubuntu LTS 14.04.3.
I recently made the switch to Linux from Windows. No real particular reason why; aside from the Apple IIe my father had, and the ones we used in elementary school, I largely grew up with Windows starting with Windows 95. I still use Windows today and I think that, besides certain privacy and forced update issues of Windows 10, I think it’s the best one yet. But I’ve always been interested in Linux and have played with Linux-based servers (including the one this blog is hosted on), and so I figured I might as well dive into the world of Linux desktop operating systems.
So I did just that. I installed the flavour of Linux I was most familiar with, Ubuntu, and aside with various other issues (to be saved for future posts) I noticed one thing as I was playing around with the laptop on my lap. It was hot. Like, really hot. My fan wasn’t running. That’s not very good for the hardware, so I set out to find a way to fix it. When I was on Windows 10 I used a neat little utility called NoteBook FanControl (or NBFC from this point forward) by Stefan Hirschmann to take manual control of the fan if I needed it. Turns out he’s also made it available on Linux although it takes a bit of finagling to get it to work. So let’s get to it!
Open up the Terminal with CTRL-ALT-T
Before we get started on installing it we need to set up our dependencies. Because NBFC is written using Microsoft’s .NET framework, we need to install the open-source alternative known as Mono.
First, let’s add Mono’s GPG signing key and repository and then update our repos. This will allow us to install the latest version of Mono right from the source.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list sudo apt-get update
(If you use a different flavour of Linux please refer to this official Mono installation document for instructions specific to your distro)
Now let’s install Mono!
sudo apt-get install mono-complete
Next we need to install git so we can grab the software from GitHub.
sudo apt-get install git
Now we’re all set to get working on NBFC. Let’s get started on that by first obtaining the software from GitHub. For the purpose of this guide we’ll clone to the /opt/directory and work from there
sudo git clone --depth 1 https://github.com/hirschmann/nbfc.git && cd /opt/nbfc
Installing and Configuring NBFC
Now that we have NBFC downloaded, we need to install it. Ensure you are in the /opt/nbfc directory where there is a shell script called build.sh. We’re going to run this script with typing the command below. It might take a while as the script downloads some additional dependencies; just let it do its thing.
sudo sh build.sh
Every time I ran the build script I noticed that the output indicated there were 3 warnings; so long as there are no errors it should not be an issue. As a note, however, I did repeatedly run into an issue where nuget.exe did not install correctly when called by the script; this caused problems with running NBFC, so the fix to this will be included at the bottom of this guide under Potential Errors and Fixes.
To confirm that it was installed, change directories to /opt/nbfc/Linux/bin/ReleaseLinux; the script should create this directory and populate it with various files. If you can enter that directory and see the files, we’re good to move on to the next step! If not, something’s gone wrong and trying again. If that still doesn’t work, I recommend creating a ticket on the developer’s GitHub project page.
So now that it’s been installed we need to do a few final steps to configure it. To begin with, we need to start the NBFC service so that nbfc.exe can communicate with mono.
sudo sh start-nbfcservice.sh
Now we need to select a config file most appropriate to your laptop. These configs can be found in a subdirectory within our current working directory. Let’s switch to it now by typing
Look through the various files configs and find the one that matches your laptop. If you cannot find your laptop, have no fear. Find the name that best resembles your laptop’s model number. I have an Asus G750JM and found the Asus M52VA config to work well after some customization.
Once you’ve found the best option for you, let’s navigate back to the previous directory and get the darn thing running! Change directories with
and then load your chosen config file. We’ll use the M52VA config for this example (spaces between words should contain a backslash)
mono nbfc.exe config --apply Asus\ M52VA
And then let’s run it!
mono nbfc.exe start
So… did it work? Chances are the fans aren’t running just yet, so let’s check the status of nbfc.exe with
mono nbfc.exe status -a
The output should look very similar to this:
|Service enabled : True
Selected config name : Asus M52VA
Temperature : 40
Fan display name :
Auto control enabled : True
Critical mode enabled : False
Current fan speed : 0.00
Target fan speed : 0.00
Fan speed steps : 9
This confirms that NBFC is running and controlling the fans. If your output indicated that the service is not running or you get something along the lines of “object not set for an instance of an object” or “Cannot communicate” don’t fret, we’ll address these in the Potential Errors and Fixes section at the end of this guide. You also might notice that the current and target fan speeds are at 0. If so, the config you’ve selected is set to have an idle fan at your current temperature. To change this, you’ll need to edit the config file, which we’ll address now.
Customizing Your Config File
Before we edit anything we need to stop nbfc.exe.
mono nbfc.exe stop
Now navigate to the Configs directory and create a copy of your selected config that you’ll work on. For the purpose of this example we’ll continue to use the Asus M52VA config. I named the copied file as default.xml for the sake of simplicity (no more backslashes!).
sudo cp Asus\ M52VA.xml default.xml
Now use your favourite text editor. I’m going to use nano.
sudo nano default.xml
By looking at the file it’s quite easy to understand how the config works. The various temperatures and the corresponding fan speeds can be found under <TemperatureThreshold>. For the purpose of testing the config to ensure it’s working, we’ll set the fan speed to 100%.
For the first temperature threshold I set the UpThreshold to 50 and the DownThresthold to 0 with the FanSpeed to 100.00. This will turn the fan on to 100% when the temperature is between 0 and 50 degrees Celsius.
Save the config. In nano hit CTRL-X followed by Y when asked if you want to overwrite and finally Enter to commit the changes to that filename.
Head back to the previous working directory, select the new config file to be loaded, start NBFC again, and then check its status to see if it’s working.
cd .. mono nbfc.exe config --apply default mono nbfc.exe start mono nbfc.exe status -a
If all is working, the same status output as you saw earlier should appear but now the fan speeds should be at 100.00. You should also start to hear the fans ramping up to speed. Hurrah!
At this point you should change the various temperature steps and fan speeds to suit your needs.
Making NBFC Start At Boot Time
By default NBFC must be started manually every time your computer boots. This was not the case for NBFC on Windows, and I certainly wasn’t okay with it being the case on Linux. So I created a very basic script to make it start every time I start up my laptop.
Navigate to /etc/init.d
I’ve made my own script available to be downloaded, which can be obtained by running:
Now we need to make it executable and then add it to the rc.d file (this will enable it so that it is executed when the operating starts).
sudo chmod +x nbfc.sh sudo update-rc.d nbfc.sh defaults
Test to make sure the script works, but first turn nbfc.exe off and stop the nbfcservice so you can make sure the whole script is working
mono /opt/nbfc/Linux/bin/ReleaseLinux/nbfc.exe stop sudo sh /opt/nbfc/Linux/bin/ReleaseLinux/stop-nbfcservice.sh
Now run the script
sudo sh nbfc.sh
The output should indicate that the NBFC has once again started. Finally, reboot your laptop and check to see if the fans start up again!
Potential Errors and Fixes
Object not set to an instance of an object: Mono is likely not installed correctly. If you had mono installed before you followed this guide, remove mono and then reinstall it using the method outlined in this guide.
Could not communicate: The nbfc mono service is not running. Run the service and then this error should go away.
Current and target fan speeds at 0.00: The config in use likely has the fans set to 0% at your laptop’s current temperature. Modify the config using the instructions above.
Linux service disabled: If you assigned a config and attempted to run NBFC but this error still occurs, the problem is that nuget.exe was not added correctly when it was done automatically by running the install script. To fix this, simply run the following commands:
Manually redownload nuget.exe with
cd /opt/nbfc && wget http://nuget.org/nuget.exe
And then restore the packages:
mozroots --import --sync mono nuget.exe restore
The problem should now be fixed.