#!/usr/bin/env bash # gpufan -- sets manual fan speed on AMD Radeon GPU. For 5.x / 6.x Linux Kernel users running AMDGPU driver... # Author: Ben @ LostGeek . NET # Created 09/20/2025 # READ ME! How to use: # save as /usr/local/bin/gpufan then chmod +x # running "gpufan" will give temperature & fan rpm. gpufan followed by a number (1-100) # will manually set speed. "gpufan auto" will restore auto / driver control. # Detect hwmon directory automatically hwmon_path=$(find /sys/class/drm/card0/device/hwmon/ -name "pwm1" -printf '%h\n' | head -n1) [[ -z "$hwmon_path" ]] && { echo "GPU hwmon path not found."; exit 1; } pwm_file="$hwmon_path/pwm1" mode_file="$hwmon_path/pwm1_enable" fan_file="$hwmon_path/fan1_input" temp_file="$hwmon_path/temp2_input" # Use temp2_input as GPU temperature get_status() { pwm=$(<"$pwm_file") mode=$(<"$mode_file") # Read fan RPM, leave blank if not available if [[ -f "$fan_file" ]]; then fan_rpm=$(<"$fan_file" 2>/dev/null) [[ -z "$fan_rpm" ]] && fan_rpm="N/A" else fan_rpm="N/A" fi # Read GPU temperature if [[ -f "$temp_file" ]]; then temp_raw=$(<"$temp_file") temp=$(( temp_raw / 1000 )) else temp="N/A" fi percent=$(( pwm * 100 / 255 )) case "$mode" in 0) mode_str="Disabled" ;; 1) mode_str="Manual" ;; 2) mode_str="Auto" ;; *) mode_str="Unknown($mode)" ;; esac echo "Fan speed: $percent% (pwm=$pwm/255, RPM=$fan_rpm) | Mode: $mode_str | GPU Temp: ${temp}°C" } if [[ -z "$1" ]]; then # No argument → status get_status elif [[ "$1" == "auto" ]]; then echo "Returning fan control to driver (auto)..." echo 2 | sudo tee "$mode_file" >/dev/null get_status elif [[ "$1" =~ ^[0-9]+$ ]] && (( $1 >= 1 && $1 <= 100 )); then pwm=$(( $1 * 255 / 100 )) echo "Setting fan to $1% (pwm=$pwm)..." echo 1 | sudo tee "$mode_file" >/dev/null echo $pwm | sudo tee "$pwm_file" >/dev/null get_status else echo "Usage: gpu [<1-100>] | [auto] | [status]" exit 1 fi