CPU Temperature & Fan Speed


Okay so this turned out to be a little hairy, but it's a one off kinda thing that might make your daily working environment significantly nicer!

You may not have this issue yourself but excessive fan noise does seem to be a common complaint on the linux forums owing to many distributions just opting to run all the system's fans at full speed all the time. Of course this situation isn't unique to linux...

For several years on my Thinkpad I have run a utility to control the speed of the built in fan as it doesn't kick in early enough for my liking. On my desktop I had the opposite problem, it was intollerably noisy by default and I was compelled to seek out a nice little utility that sat in the taskbar and moderated the excessive RPMs of my CPU fan. Both of these fan control apps are real homebrew hobbyist contraptions but despite the rough edges and worrying 'if your computer catches fire I'm not liable' disclaimers they worked well for me and so I set out to find something similar for my new Ubuntu install.

The sad fact is though, to the best of my knowledge there are no equivalent easy little CPU/fan control apps for linux* :-/ However...

You can get the same results with a couple of command line utils. If you want graphical displays of your fanspeed and CPU temp etc that's available too, but that sits on top of these command line tools (google: gkrellm once you've completed these instructions if that's what you're after).

Now although I spend a lot of time computer programming I'm no command line fanboy, I much prefer graphical interfaces. It's not the 1970s any more and spending more than a few minutes of each day in a black and white terminal window on my P4 3Ghz computer with it's 1280x1024 Truecolor display seems a tad anachronistic but bear in mind... once you've got this setup the way you want it that extra icon in your taskbar is kind of surplus to requirements anyway. So let us proceed.

The faint of heart take heed now: part of this process is frightening. If you are of a nervous disposition or have medical issues that are aggravated by stress you may be better off taking your computer to a shop and getting them to fit quieter fans! With that said there follows an overview of what we're going to do...

  1. Install an app that collates info from your system's sensors i.e. temperatures, fan speeds, voltages etc.
  2. Detect what sensors your system has.
  3. Make your system (kernel) aware of said sensors.
  4. Run a script that calibrates your fans and saves the settings for the fan control app.
  5. Run the fancontrol app - this modifies your fan speed based on the aforementioned sensor readings.
  6. Make it so that the fan control app starts automatically at boot time

1. Install sensor collation app

This is the easy part! Simply go to Synaptic Package Manager and then find and install the package lm_sensors.

2. Detect sensors

Again this is pretty simple, fire up a terminal window and type: sudo sensors-detect. This, unsurprisingly, runs the sensor detector script. It will ask you several yes/no questions, answer YES to all of them. By the end of the script it should have detected at least one sensor module which it will helpfully display between "#----cut here----" lines. I only had one which was w83627ehf, cool huh!

3. Tell your kernel about it...

There's 2 ways to do this, the first way - as espoused by the above script - is to open (using sudo) the config file /etc/modules and add this device name to it. The second and simpler way is to simply type: sudo modprobe w83627ehf, or whatever the name(s) of your sensor chip is, into the command line. If you have more than one chip you'll need to do this for each one. If it all worked correctly you should be able to type the command sensors into your terminal window and it will return a list of current sensor info. If this deosn't work, go google "lm_sensor install" and figure out what went wrong. Assuming it did work we can move on to stage...

4. Calibrate you fans and enter fan control settings

At the terminal you need to type sudo pwmconfig but this is the scary bit... It stops your processor fan! Now I know that seems like a terrible idea, and indeed it is something that should make you squirm to think about, let alone do, which is why it only does it for 5 seconds at a time. If you're not comfortable with 5 seconds you can modify the script to use a lower value. That, however, isn't the worst bit!

Once it has identified which fan controllers do what it asks if you would like to "generate a detailed correlation". "Sure" you say, "Who wouldn't want a detailed correlation?; whatever one of those is" and before you know it you are plunged into a nauseating incremental decent in fan speed that goes from very fast to totally stopped via terrifyingly slow for a seemingly very long time, or at least it does on my system which thankfully survived the ordeal.

That's far more worrying than it is actually dangerous and I suspect it very rarely, if ever, damages your hardware. However the more cautious among you may want to have a second terminal constantly running the sensors command during this process in order to check the CPU temperature, ready to yank the cord should things get too hot for comfort. Alternatively you could skip this step entirely and manually create the fancontrol config file with extremely conservative settings, trimming them downwards at your leisure as per step...

5. Run Fan Control app and adjust settings

This app is called, wait for it... fancontrol, that's right just type sudo fancontrol at the command line. It does what it says on the tin i.e. controls your fan, according to the config file you just generated - /etc/fancontrol. It's this file you need to edit if you're not happy with the settings generated by the pwmconfig script above. I still haven't figured out how to launch an file as root from the file browser but in terminal window you can just type sudo nano /etc/fancontrol. So try it out, play with the numbers and when you're happy we can move on to the final stage...

6. Making it start automatically at boot time

All you need to do to get the fan control app to run at startup is add the line 'fancontrol' to the file /etc/rc.local - nice :-) To edit this file type sudo nano /etc/rc.local into your terminal window and add it before the line that says EXIT=0. This is somewhat nicer than using the Windows startup folder in that it starts before you log in and there's no window hanging around cluttering up your taskbar afterwards.

Phew! That was a slog...

Notwithstanding that I bet you feel good now ;-) Well Done! You should treat yourself to a bit of World of Warcraft or Ebaying for vintage erotica, whatever it is you do for recreation, happy and content by virtue of the fact your fan no longer sounds like an shrieking jet turbine :-)


* If you really want this GUIfying send me some money and I'll write a frontend for you ;-) Roger.




Moving to Ubuntu is a blog by Roger Heathcote, proprietor of Technicalbloke.com with a focus on moving from Microsoft Windows to Ubuntu linux, the free linux based operating system with a ton of great free software and great windows interoperability, specifically the Ubuntu 8.04 Hardy Heron LTS release from Canonical. Here I present a series of articles on configuring and maintaining an Ubuntu linux installation, installing software/applications/programs on Ubuntu linux, throubleshooting any problems I have with Ubuntu along the way and sharing any tips and tricks I discover in the process of moving from Windows XP to Ubuntu. I will endeavor to use the Gnome graphical user interface (GUI) instead of the command line interface (CLI) wherever possible so as to show that switching to linux (and especially Ubuntu) these days does not require you to become a hardcore command line hacker. If you are thinking about moving to Ubuntu please feel free to ask questions and likewise, if you have already made the move to Ubuntu please take the time to comment and share your advice, tips, tricks (and corrections!) - I hope you enjoy the site, and (hopefully) switching to linux :-)