Featured image of post Fan Control on PVE

Fan Control on PVE

在 PVE 宿主机上用 nct6775 驱动与 systemd 服务固定机箱风扇转速:识别 PWM 通道、编写开机生效的调速脚本,并附实测 PWM 与转速对照表

Fan Control on PVE

Tested on: ASUS TUF GAMING B550M-PLUS / AMD Ryzen 5 5600 / Nuvoton NCT6798D

1. Load the Driver

apt update && apt install lm-sensors
sensors-detect             # Accept defaults, say yes to write to /etc/modules
modprobe nct6775
sensors                    # Verify fan RPM and temperature readings appear

2. Identify the Active PWM Channel

pwmconfig automatically maps each PWM control to the fan it actually drives, saving guesswork.

apt install fancontrol     # pwmconfig ships with fancontrol
pwmconfig

Answer y to switch each PWM channel to manual mode. The tool will briefly stop each fan and measure RPM changes. Sample output:

Testing pwm control hwmon3/pwm2 ...
  hwmon3/fan2_input ... speed was 2872 now 675
    It appears that fan hwmon3/fan2_input is controlled by pwm hwmon3/pwm2

    PWM 255 FAN 2842    PWM 120 FAN 1726
    PWM 240 FAN 2760    PWM 105 FAN 1553
    PWM 225 FAN 2626    PWM 90  FAN 1351
    PWM 210 FAN 2532    PWM 75  FAN 1166
    PWM 195 FAN 2385    PWM 60  FAN 942
    PWM 180 FAN 2295    PWM 45  FAN 789
    PWM 165 FAN 2136    PWM 30  FAN 566
    PWM 150 FAN 2002    PWM 0-28 FAN ~490
    PWM 135 FAN 1849

Exit with Ctrl+C or answer n to skip remaining channels once you’ve found the one controlling your target fan.

3. Create the Fixed-Speed Script

The script resolves the hwmon device by name at runtime, so it survives reboots and kernel updates without changes.

cat > /root/pve-fan-fixed.sh << 'EOF'
#!/bin/bash
HWMON=$(grep -l nct6798 /sys/class/hwmon/hwmon*/name | grep -oP 'hwmon\d+')
[ -z "$HWMON" ] && exit 1
echo 1 > /sys/class/hwmon/"$HWMON"/pwm2_enable
echo 225 > /sys/class/hwmon/"$HWMON"/pwm2
EOF
chmod +x /root/pve-fan-fixed.sh

pwmN_enable values: 1 = Manual, 2 = Thermal, 5 = BIOS/ACPI (default)

4. Set Up the systemd Service

cat > /etc/systemd/system/pve-fan-fixed.service << 'EOF'
[Unit]
Description=Set fixed fan speed
After=systemd-modules-load.service

[Service]
Type=oneshot
ExecStart=/root/pve-fan-fixed.sh

[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now pve-fan-fixed.service

5. Adjusting the Speed

sed -i '/pwm2_enable/! s/echo [0-9]*/echo 225/' /root/pve-fan-fixed.sh
systemctl restart pve-fan-fixed.service

Or just nano /root/pve-fan-fixed.sh and change the number on the last line.


PWM to RPM Mapping

Data measured from your actual hardware via pwmconfig. Noise description is approximate.

PWM RPM Noise
255 2842 Full speed
225 2626 High ← Current
180 2295 Medium-high
150 2002 Medium
120 1726 Medium-low
105 1553 Quiet
80 ~1300 Quiet
60 942 Very quiet
30 566 Extremely quiet
0-28 ~490 Minimum

Uninstall

systemctl disable --now pve-fan-fixed.service
rm /etc/systemd/system/pve-fan-fixed.service /root/pve-fan-fixed.sh