Taking your hardware's temperature
Command Line – lm-sensors
With lm-sensors, you can monitor your hardware's internal temperature to avoid overheating.
Hardware temperatures have long been the concern of system administrators and server farms. However, with summer and the recent record temperatures worldwide, excess heat inside a computer case has become every user's concern. Too much heat can cause a computer to act erratically. In extreme cases, overheating can result in your computer shutting down until it cools off or, worse, cause permanent damage to sensitive components. If you're using a laptop positioned on your bare legs, you could even suffer third-degree burns.
With so much at stake, there is a real need to monitor hardware temperatures, at least on new machines, on hotter days and during long sessions on your computer. On Linux, you have a number of utilities that will read temperature settings, but many are minimally useful or even obsolete. As a result, you not only have the heat to contend with, but also inadequate or obsolete tools as well. Fortunately, the lm-sensors (Linux monitoring sensors) [1] package can help solve this problem, although it does require some setup and the loading of kernel modules.
A Matter of Thermodynamics
Quite simply, computer components give off heat when they are in use. When crammed into a confined space, their heat can easily increase rather than disperse. Faster components generally produce more heat. The problem can be especially difficult with a laptop, whose components are crammed into an even smaller space than in a workstation or server. The trend in the last decade toward thinner and thinner laptops aggravates the problem even further.
In any case, the ideal is to have more cool air coming into the case and more hot air leaving the case, with air entering the front of the case and fans pushing the air to the back and the top. However, this air flow can be blocked or diverted by components and the points where they are secured to the chassis. Moreover, hot days can mean that the air entering the case does not cool as well as it does on colder days.
To monitor this difficult and ever-changing situation, modern hardware usually has temperature sensors. By reading the differences in these sensors, you can construct a map of just how the air flows – or does not flow – in a case. Linux kernel modules read these sensors, and, like other information about hardware, output it to the /sys
pseudo-filesystem where it can be assessed for use by applications. Unfortunately, /sys
is not intended to be human-readable, although information can be deciphered with complicated workarounds that are impractical for average users.
Instead, most users rely on utilities to give them information about hardware in a readable format. Although there are countless utilities that give information about hardware – among them I-Nex, HardInfo, KInfoCenter, and lshw
– few of these utilities report on temperatures, particularly those on the desktop. Of the utilities that do, most seem to give only an averaged reading, which has limited use. Even worse, like much free software, some of these utilities you see mentioned on the Internet have come and gone. For example, Glances originally gave multiple temperature readings, but it has removed these readings as it has evolved towards being a top
replacement. Similarly, while hddtemp
can read the temperature of the older mechanical drives, it does not support the increasingly common solid state drives, even though it identifies them. In these circumstances, lm-sensors fills an important gap in hardware utilities.
Setting Up lm-sensors
The lm-sensors package provides data on hardware temperatures, voltage, and fans. Found in most major distributions, lm-sensors usually has to be installed. lm-sensors has a long history of causing problems on certain laptops after running it with anything but default settings, so research the limitations and workarounds before using it on a laptop. Some Asus and Gigabyte motherboards also have documented problems when you stray from the defaults [2]. If you decide to use lm-sensors, you should be safe if you stick with the default settings.
Before you use lm-sensors, you must scan for the kernel modules it requires with
sensors-detect
Which modules you accept will determine what hardware lm-sensors will detect. Most users will want to simply accept the defaults, if only to avoid any potential problems. If you skip any choices, you can run the command again (Figure 1). After you make each selection, lm-sensors scans the specific type of hardware, indicating with a simple Success!
message when a type is detected (Figure 2). When all scans are complete, lm-sensors summarizes its discoveries. It then offers to add the appropriate lines to /etc/modules
(Figure 3).
Once this setup is complete, run the command sensors
to get a report on temperatures inside the case (Figure 4). The report shows the wattage being used by the power supply, as well as current temperatures. Both wattage and temperature also show the maximum safe limits. Figure 4 shows the result of the scans of a system in a Lian-Li Lancool-205 Mesh Black case [3] (an exceptionally cool-running case) on a spring day of about 16°C; results for most cases are apt to be higher in the heat of summer, generally somewhere between 35-40°C. As you can see, all statistics are well below the high or critical levels. For a more complete report, add the -u
option to see readings for adapters (Figure 5). If you choose, you can also add --fahrenheit
(-f
) to change the temperature scale.
Note that, although the sensors
man page mentions configuration files /etc/sensors
or /etc/sensors3
, lm-sensors does not create either upon installation, because these configuration files are usually not needed, and any changes written to those files might be overridden in a package upgrade. Still, a configuration file can be useful in some situations, such as when the temperatures reported by lm-sensors need to be offset to match values specified by hardware manufacturers, or users may want to rename sensors or display them in a different order. In such cases, changes can be written to a unique file name and referenced with the option --config-file
(-c
). However, the bare command is usually enough for general temperature monitoring [4].
You should also note that, originally, lm-sensors also included the temperature sensors for DIMMs (RAM chips) that use the i2c protocol. However, this functionality was removed from lm-sensors because not all DIMM chips use the protocol. Should you need this functionality, ArchWiki gives instructions for getting those readings as well [5].
Responding to Readings
If lm-sensors has a fault, it is that there is no way to see how temperatures change over time. However, regular readings (or even a hand on the case) can tell you if the temperature is stable or not.
But what should you do if the temperature is high or approaching critical? The answers are common sense. In the short term, shut down immediately and wait a couple of hours before rebooting, or, possibly, temporarily remove the overheated hardware – although if one part is overheating, others are likely doing so as well. In the long term, remove the side of the case for greater airflow. Use room fans, or invest in portable air-conditioning. For future monitoring, set lm-sensors to start automatically when you boot by running the command:
systemctl enable lm-sensors
If overheating persists, add another fan to the case or a larger fan. You can also get a better-designed case for well under $200 without resorting to a water-cooling case [6]. But whatever you do, do not neglect the overheating. The problem of overheating will not go away. The faster computers become, the worse this problem will likely become as well.
Infos
- lm-sensors: https://wiki.archlinux.org/title/lm_sensors
- Laptop and motherboard problems: https://wiki.archlinux.org/title/Lm_sensors#Laptop_screen_issues_after_running_sensors-detect
- Lian-Li Lancool-205 Mesh Black case: https://lian-li.com/product/lancool-205/
- Configuration files: https://wiki.archlinux.org/title/Lm_sensors#Tips_and_tricks
- DIMM temperatures: https://wiki.archlinux.org/title/Lm_sensors#Adding_DIMM_Temperature_sensors
- Cool-running cases: https://premiumbuilds.com/pc-cases/best-airflow-pc-cases/
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.