DEV Community

vast cow
vast cow

Posted on

Controlling CPU Fan Speed on Mac mini 5,2 with Ubuntu 24.04

If you have a Mac mini 5,2 (Mid 2011) running Ubuntu 24.04, a convenient setup is to use applesmc + mbpfan. mbpfan 2.4.0 is also included as a standard package in Ubuntu 24.04 (Noble). Ubuntu Packages

The Linux applesmc driver provides Intel Mac temperature sensors and fan control via sysfs. GitHub

1. First, check applesmc

sudo modprobe applesmc
sudo modprobe coretemp

lsmod | grep -E 'applesmc|coretemp'
Enter fullscreen mode Exit fullscreen mode

Next, check the fan interface.

SMC=$(find /sys/devices/platform -maxdepth 1 -type d -name 'applesmc.*' -print -quit)
echo "$SMC"

ls -l "$SMC"/fan*
Enter fullscreen mode Exit fullscreen mode

For example, if you see something like this, you can control it.

fan1_input
fan1_manual
fan1_max
fan1_min
fan1_output
Enter fullscreen mode Exit fullscreen mode

Be sure to check fan1_min and fan1_max.

cat "$SMC/fan1_min"
cat "$SMC/fan1_max"
cat "$SMC/fan1_input"
Enter fullscreen mode Exit fullscreen mode

The values will vary depending on the Mac, so it is safer not to assume values like 1800-5500 RPM.


2. Manually change the rotation speed

You can first test it temporarily at, for example, 3000 RPM.

echo 1 | sudo tee "$SMC/fan1_manual"
echo 3000 | sudo tee "$SMC/fan1_output"
Enter fullscreen mode Exit fullscreen mode

Current actual rotation speed:

cat "$SMC/fan1_input"
Enter fullscreen mode Exit fullscreen mode

After a few seconds, it should be around 3000 RPM.

On Intel Macs in Linux, the method of setting fan1_manual=1 and then writing the target RPM to fan1_output is used. Ask Ubuntu

Return to automatic control

This is important.

echo 0 | sudo tee "$SMC/fan1_manual"
Enter fullscreen mode Exit fullscreen mode

If you leave it in manual mode and fix it at a low rotation speed, the rotation speed will not increase even when the CPU/GPU load increases.


3. Recommended: Use mbpfan to link to temperature

On Ubuntu 24.04,

sudo apt update
sudo apt install mbpfan lm-sensors
Enter fullscreen mode Exit fullscreen mode

Enable:

sudo systemctl enable --now mbpfan
Enter fullscreen mode Exit fullscreen mode

Check status:

systemctl status mbpfan
Enter fullscreen mode Exit fullscreen mode

mbpfan reads the CPU temperature from coretemp and changes the fan speed via applesmc. GitHub

Configuration:

sudo nano /etc/mbpfan.conf
Enter fullscreen mode Exit fullscreen mode

For example, for Mac mini 5,2, I would first try the following as a gentle setting.

[general]

low_temp = 55
high_temp = 65
max_temp = 80

polling_interval = 1
Enter fullscreen mode Exit fullscreen mode

For the fan's min/max, mbpfan can use the values reported by applesmc. If you want to specify it explicitly,

cat "$SMC/fan1_min"
cat "$SMC/fan1_max"
Enter fullscreen mode Exit fullscreen mode

and then

min_fan1_speed = 2000
max_fan1_speed = 5500
Enter fullscreen mode Exit fullscreen mode

Set it using the actual values of your machine. mbpfan's default setting also specifies that it refers to /sys/devices/platform/applesmc.768/fan*_min and fan*_max. GitHub

After changing:

sudo systemctl restart mbpfan
Enter fullscreen mode Exit fullscreen mode

4. Monitor temperature and RPM in real time

sensors
Enter fullscreen mode Exit fullscreen mode

Or,

watch -n 1 sensors
Enter fullscreen mode Exit fullscreen mode

If you want to see the fan RPM directly:

watch -n 1 "cat $SMC/fan1_input; sensors"
Enter fullscreen mode Exit fullscreen mode

macmini5,2 ubuntu24.04でcpuファンスピードをコントロールしたい

Macmini5,2(Mid 2011)+ Ubuntu 24.04 なら、applesmc + mbpfan が扱いやすい構成です。Ubuntu 24.04(Noble)にも mbpfan 2.4.0 が標準パッケージとしてあります。(Ubuntu Packages)

Linux の applesmc ドライバは Intel Mac の温度センサーとファン制御を sysfs 経由で提供しています。(GitHub)

1. まず applesmc を確認

sudo modprobe applesmc
sudo modprobe coretemp

lsmod | grep -E 'applesmc|coretemp'
Enter fullscreen mode Exit fullscreen mode

次にファンのインターフェースを確認します。

SMC=$(find /sys/devices/platform -maxdepth 1 -type d -name 'applesmc.*' -print -quit)
echo "$SMC"

ls -l "$SMC"/fan*
Enter fullscreen mode Exit fullscreen mode

例えば、以下のようなものが出れば制御できます。

fan1_input
fan1_manual
fan1_max
fan1_min
fan1_output
Enter fullscreen mode Exit fullscreen mode

fan1_minfan1_max を必ず確認してください。

cat "$SMC/fan1_min"
cat "$SMC/fan1_max"
cat "$SMC/fan1_input"
Enter fullscreen mode Exit fullscreen mode

Mac によって値は違うので、1800~5500 RPM などと決め打ちしない方が安全です。


2. 手動で回転数を変更する

まず一時的に 3000 RPM などでテストできます。

echo 1 | sudo tee "$SMC/fan1_manual"
echo 3000 | sudo tee "$SMC/fan1_output"
Enter fullscreen mode Exit fullscreen mode

現在の実回転数:

cat "$SMC/fan1_input"
Enter fullscreen mode Exit fullscreen mode

数秒すると 3000 RPM 前後になっているはずです。

Linux 上の Intel Mac では、fan1_manual=1 にしてから fan1_output に目標RPMを書く方法が使われています。(Ask Ubuntu)

自動制御に戻す

これは重要です。

echo 0 | sudo tee "$SMC/fan1_manual"
Enter fullscreen mode Exit fullscreen mode

手動モードのまま低回転に固定すると、CPU/GPU負荷が上がっても回転数が上がらなくなります。


3. おすすめ:mbpfan で温度連動

Ubuntu 24.04 なら、

sudo apt update
sudo apt install mbpfan lm-sensors
Enter fullscreen mode Exit fullscreen mode

有効化:

sudo systemctl enable --now mbpfan
Enter fullscreen mode Exit fullscreen mode

状態確認:

systemctl status mbpfan
Enter fullscreen mode Exit fullscreen mode

mbpfancoretemp からCPU温度を読み、applesmc 経由でファン速度を変更します。(GitHub)

設定は:

sudo nano /etc/mbpfan.conf
Enter fullscreen mode Exit fullscreen mode

例えば私は Macmini5,2 なら、まず穏当な設定として次のあたりから試します。

[general]

low_temp = 55
high_temp = 65
max_temp = 80

polling_interval = 1
Enter fullscreen mode Exit fullscreen mode

ファンの min/max は applesmc が報告する値を mbpfan が利用できます。明示的に設定したい場合は、

cat "$SMC/fan1_min"
cat "$SMC/fan1_max"
Enter fullscreen mode Exit fullscreen mode

を確認してから、

min_fan1_speed = 2000
max_fan1_speed = 5500
Enter fullscreen mode Exit fullscreen mode

のように実機の値を使って設定します。mbpfan の標準設定も /sys/devices/platform/applesmc.768/fan*_minfan*_max を参照する仕様です。(GitHub)

変更後:

sudo systemctl restart mbpfan
Enter fullscreen mode Exit fullscreen mode

4. 温度とRPMをリアルタイム監視

sensors
Enter fullscreen mode Exit fullscreen mode

または、

watch -n 1 sensors
Enter fullscreen mode Exit fullscreen mode

ファンRPMも直接見たいなら:

watch -n 1 "cat $SMC/fan1_input; sensors"
Enter fullscreen mode Exit fullscreen mode

Macmini5,2 なら私ならこうします

常用は mbpfan、手動の fan1_output は動作確認用にします。

最初に、次の結果を貼ってもらえれば、Macmini5,2 の実機値に合わせて /etc/mbpfan.conf を具体的に作れます。

uname -r
lsmod | grep -E 'applesmc|coretemp'
SMC=$(find /sys/devices/platform -maxdepth 1 -type d -name 'applesmc.*' -print -quit)
echo "$SMC"
for f in "$SMC"/fan*; do echo -n "$f = "; cat "$f"; done
sensors
Enter fullscreen mode Exit fullscreen mode

特に fan1_min / fan1_max とアイドル時・負荷時CPU温度が分かれば、「静音寄り」「冷却寄り」のファンカーブを決められます。

Top comments (0)