Taking your hardware's temperature

Command Line – lm-sensors

© Photo by Jarritos Mexican Soda on Unsplash

© Photo by Jarritos Mexican Soda on Unsplash

Article from Issue 261/2022
Author(s):

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).

Figure 1: lm-sensors allows you to select which hardware you want to scan for, although usually you should just accept the defaults.
Figure 2: The summary of detected hardware.
Figure 3: lm-sensors can automatically add the necessary modules to /etc/modules.

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.

Figure 4: The basic summary of wattage used and temperatures.
Figure 5: The extended summary with the -u option adds additional information about adapters.

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.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest Coast art (http://brucebyfield.wordpress.com). He is also co-founder of Prentice Pieces, a blog about writing and fantasy at https://prenticepieces.com/.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Temperature Testing a NAS

    Using stress, lm-sensors, and hddtemp to sort out temperature and reliability related issues with a home-based NAS box.

  • Perl: Temperature Sensors

    Linux lets tinkerers connect their hardware creations to computers. We’ll show you how you can use a simple Perl interface to check the temperature of your home or office while you’re away.

  • Bpytop

    Linux users have many options for monitoring system resources, but bpytop, a new Python port of bashtop, more than stands out from the crowd.

  • Monitoring Old Devices

    Create monitoring dashboards with SSH, command-line tools, and Node-RED.

  • Sensor Shootout

    Any application that collects a large number of measurements is bound to have some anomalous measurements, but good sensor breakouts should not output such values all the time. We tested eight temperature and humidity sensors for accuracy.

comments powered by Disqus
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.

Learn More

News