The hwmon directories (such as hwmon0, hwmon1, hwmon2, etc.) are part of the Linux hardware monitoring system and can be accessed under the /sys/class/hwmon/ path. These directories are created by the kernel for each detected hardware monitoring device.
Each hwmon directory corresponds to different hardware sensors such as temperature sensors, voltage sensors, fan speed sensors, and PWM (Pulse Width Modulation) fan controllers.
To locate and browse the hwmon directories, you can use the following steps:
1. List hwmon Directories
Open a terminal and list the contents of /sys/class/hwmon/:
ls -l /sys/class/hwmon/
You should see a list of hwmon directories, which might look something like this:
total 0
lrwxrwxrwx 1 root root 0 Mar 7 12:34 hwmon0 -> ../../devices/platform/coretemp.0/hwmon/hwmon0
lrwxrwxrwx 1 root root 0 Mar 7 12:34 hwmon1 -> ../../devices/platform/nct6776.656/hwmon/hwmon1
lrwxrwxrwx 1 root root 0 Mar 7 12:34 hwmon2 -> ../../devices/pci0000:00/0000:00:1f.3/hwmon/hwmon2
2. Identify the Relevant hwmon Directory
To find out which directory corresponds to your PWM controller, you can browse into each hwmon directory and check its contents. For instance:
ls -l /sys/class/hwmon/hwmon2
You might see various sensor files like:
device name pwm1 pwm1_enable temp1_input temp1_label
The naming can give you a clue about what each hwmon is for. Specifically, pwm1 or similar files represent the PWM controller for the fans.
3. Check the name File
Each hwmon directory includes a name file that provides the name of the chip or sensor. You can read this file to get a clearer understanding of what hardware it corresponds to:
cat /sys/class/hwmon/hwmon2/name
4. Read and Write PWM Values
Once you’ve identified the correct hwmon directory, you can read and write to the pwm files to control fan speeds. For example, to set a PWM value:
sudo echo 128 > /sys/class/hwmon/hwmon2/pwm1
Note: Writing directly to these files may require root privileges and is generally done by applications like fancontrol.
Using pwmconfig and fancontrol
A more controlled approach is to use pwmconfig and fancontrol to automate these settings.
-
Run pwmconfig to configure PWM settings:
sudo pwmconfig
Follow the interactive prompts to identify and configure fan control settings.
-
Start and Configure fancontrol:
sudo service fancontrol start
Ensure it runs at startup:
sudo systemctl enable fancontrol
Example Walkthrough
-
Run sensors to see available sensors:
sensors
-
List hwmon directories:
ls -l /sys/class/hwmon/
-
Identify the relevant directory:
cat /sys/class/hwmon/hwmon2/name
-
Read current PWM value:
cat /sys/class/hwmon/hwmon2/pwm1
-
Set a new PWM value (example sets it to 50%):
sudo echo 128 > /sys/class/hwmon/hwmon2/pwm1
Using the steps above, you should be able to identify your PWM controllers and set fan speeds programmatically or using helper tools like fancontrol.