Title: [Guide] Automated Silent Fan Control Script for Converted EMC / Mellanox SX60xx (SX6018) Switches on MLNX-OS 3.6+
Background & Hardware
- Hardware: Mellanox SX6018 (18-port FDR InfiniBand / VPI switch, running in Ethernet mode).
- Origin: Originally an OEM EMC-branded switch, successfully converted to pure Mellanox firmware structure.
- Firmware Version: Mellanox MLNX-OS v3.6.8012 (PPC M460EX architecture).
As many homelabbers know, running enterprise gear like the SX6018 at home brings a massive downside:
jet-engine fan noise. While standard conversion guides get the switch running on pure MLNX-OS, finding a robust, automatic way to quiet down the fans without risking hardware overheating can be tricky—especially since the root filesystem (/etc) is
Read-Only in MLNX-OS, breaking standard rc.local persistence methods.
Here is a fully tested, elegant solution using native internal database tools (mdreq) to dynamically control the fan speed based on the core CPU/ASIC temperature (
T2), complete with a hard safety ceiling and persistent startup.
How the Script Works
- Temperature Monitoring: Instead of parsing messy text logs, it queries the internal MLNX-OS database directly for the CPU_BOARD_MONITOR (T2) core temperature (/system/chassis/temperature/state/MGMT/CPU_BOARD_MONITOR/t2/temperature).
- Dynamic Curve:
- Below 70°C, it locks the fans to an ultra-silent 18% (~4300 RPM).
- Above 70°C, it gently ramps up speed by 2% for every 1°C increase.
- Hard Ceiling (Apartment/Homelab Friendly): It enforces a strict maximum speed cap of 45%. It will never spike to 100% unexpectedly and wake you up at midnight.
- Persistence: It uses user-space crontab @reboot hooks to survive reboots gracefully without hitting Read-Only partition walls.
Step-by-Step Implementation Guide
Step 1: Access the Switch Shell
Log into your switch via SSH or serial console, enter privileged mode, and drop into the hidden Linux shell:
codeText
enable
_shell
Step 2: Create the Dynamic Fan Script
Create and populate the script inside the persistent /config directory by running the following block in your shell:
codeBash
cat << 'EOF' > /config/fan_dynamic.sh
#!/bin/bash
# --- CONFIGURATION (HOMELAB / SILENT MODE) ---
BASE_TEMP=70 # Up to 70°C on T2, fans stay at ultra-quiet minimum (18%)
MIN_SPEED=18 # Minimum fan speed in % (~4300 RPM)
MAX_SPEED=45 # HARD CEILING: Never exceed 45% to prevent midnight noise!
STEP_PERCENT=2 # Gentle ramp-up by 2% for every 1°C above 70°C
CHECK_INTERVAL=30 # Check loop interval in seconds
# Startup safety sleep to let the internal management database settle
sleep 45
while true; do
# 1. Fetch exact core temperature (T2) directly from MLNX-OS database
RAW_TEMP=$(/opt/tms/bin/mdreq -v query get - /system/chassis/temperature/state/MGMT/CPU_BOARD_MONITOR/t2/temperature 2>/dev/null)
TEMP=${RAW_TEMP%%.*}
# Fallback safety default if query fails
if [ -z "$TEMP" ] || ! [[ "$TEMP" =~ ^[0-9]+$ ]]; then
TEMP=68
fi
# 2. Calculate dynamic fan speed
if [ "$TEMP" -le "$BASE_TEMP" ]; then
SPEED=$MIN_SPEED
else
DIFF=$((TEMP - BASE_TEMP))
SPEED=$((MIN_SPEED + (DIFF * STEP_PERCENT)))
fi
# 3. Enforce strict safety boundaries (18% to 45%)
if [ "$SPEED" -lt "$MIN_SPEED" ]; then
SPEED=$MIN_SPEED
elif [ "$SPEED" -gt "$MAX_SPEED" ]; then
SPEED=$MAX_SPEED
fi
# 4. Apply speed natively via mdreq for chassis fans (1 to 4) and power supply (PS2)
/opt/tms/bin/mdreq action /system/chassis/actions/set-fan-speed fan_module string "/FAN/FAN" fan_number int8 1 fan_speed int8 $SPEED set_max uint8 45 >/dev/null 2>&1
/opt/tms/bin/mdreq action /system/chassis/actions/set-fan-speed fan_module string "/FAN/FAN" fan_number int8 2 fan_speed int8 $SPEED set_max uint8 45 >/dev/null 2>&1
/opt/tms/bin/mdreq action /system/chassis/actions/set-fan-speed fan_module string "/FAN/FAN" fan_number int8 3 fan_speed int8 $SPEED set_max uint8 45 >/dev/null 2>&1
/opt/tms/bin/mdreq action /system/chassis/actions/set-fan-speed fan_module string "/FAN/FAN" fan_number int8 4 fan_speed int8 $SPEED set_max uint8 45 >/dev/null 2>&1
/opt/tms/bin/mdreq action /system/chassis/actions/set-fan-speed fan_module string "/PS2/FAN" fan_number int8 1 fan_speed int8 $SPEED set_max uint8 45 >/dev/null 2>&1
# Log current status to system logs for tracking
logger "FAN_CONTROL: Temp=${TEMP}C, TargetSpeed=${SPEED}%"
# Sleep before next check
sleep $CHECK_INTERVAL
done
EOF
Step 3: Make it Executable
Grant execution permissions to your script:
codeBash
chmod +x /config/fan_dynamic.sh
Step 4: Set Up Persistent Autostart (Bypassing Read-Only /etc)
Because /etc is read-only in MLNX-OS, standard startup hooks will fail. Instead, configure user-space crontab to trigger the script seamlessly on boot:
codeBash
(crontab -l 2>/dev/null; echo "@reboot sleep 60 && /config/fan_dynamic.sh &") | crontab -
You can verify the configuration was saved successfully by running:
codeBash
crontab -l
Testing and Verification
- You can test the script manually in the background right now:
codeBash
/config/fan_dynamic.sh &
- Check real-time actions via system logs:
codeBash
tail -f /var/log/messages
You should see entries like: FAN_CONTROL: Temp=68C, TargetSpeed=18%.
Enjoy your silent, converted Mellanox switch! Huge thanks to the STH community for mapping out the initial EMC-to-Mellanox conversion paths.