鍋の底

雑多な記録

Thinkpad X220 と thinkfan

こんなことで引っかかったのは僕だけなんだろうが、記録しておく。

はじめに

いつの頃からか Debian sid の thinkfan をアップデートすると、エラーでインストールが完了しなくなった。
パッケージのバグならそのうち直るだろうと思っていたのだけど、どうやら直らなそうなので、重い腰を上げて対処することにした。

エラーの内容

さて、dpkgのエラーメッセージはこんな感じ

E: Sub-process /usr/bin/dpkg returned an error code (1)
thinkfan (0.9.3-1) を設定しています ...
Job for thinkfan.service failed because the control process exited with error code.
See "systemctl status thinkfan.service" and "journalctl -xe" for details.
invoke-rc.d: initscript thinkfan, action "start" failed.
● thinkfan.service - simple and lightweight fan control program
Loaded: loaded (/lib/systemd/system/thinkfan.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2017-02-03 06:32:29 JST; 6ms ago
Process: 24484 ExecStart=/usr/sbin/thinkfan (code=exited, status=4)
CPU: 1ms

2月 03 06:32:29 tateshina systemd[1]: Starting simple and lightweight fan control program...
2月 03 06:32:29 tateshina systemd[1]: thinkfan.service: Control process exited, code=exited status=4
2月 03 06:32:29 tateshina systemd[1]: Failed to start simple and lightweight fan control program.
2月 03 06:32:29 tateshina systemd[1]: thinkfan.service: Unit entered failed state.
2月 03 06:32:29 tateshina systemd[1]: thinkfan.service: Failed with result 'exit-code'.
dpkg: パッケージ thinkfan の処理中にエラーが発生しました (--configure):
サブプロセス インストール済みの post-installation スクリプト はエラー終了ステータス 1 を返しました
処理中にエラーが発生しました:
thinkfan

つまり、thinkfanを起動しようとしたら、エラーで落ちた、と。
これだけじゃナンなので、エラーメッセージのとおりに、journalctlを実行。

$ sudo journalctl -xe

2月 03 06:22:30 tateshina thinkfan[23114]: thinkfan 0.9.1 starting...
2月 03 06:22:30 tateshina thinkfan[23114]: WARNING: Using default fan control in /proc/acpi/ibm/fan.
2月 03 06:22:30 tateshina thinkfan[23114]: WARNING: Using default temperature inputs in /proc/acpi/ibm/thermal.
2月 03 06:22:30 tateshina systemd[1]: thinkfan.service: Control process exited, code=exited status=4
2月 03 06:22:30 tateshina thinkfan[23114]: /proc/acpi/ibm/thermal: No such file or directory
2月 03 06:22:30 tateshina thinkfan[23114]: add_sensor: Error getting temperature.
2月 03 06:22:30 tateshina thinkfan[23114]: /proc/acpi/ibm/thermal: No such file or directory
2月 03 06:22:30 tateshina thinkfan[23114]: Error parsing temperatures:
2月 03 06:22:30 tateshina thinkfan[23114]: readconfig: Error getting temperature.
2月 03 06:22:30 tateshina systemd[1]: Failed to start simple and lightweight fan control program.

つまり、温度センサのファイルがないとのこと。
あぁ、やっぱりね。実は知ってて放置してた。

今まではあんまり問題がなかったのだけど、いよいよ解決しなければならぬ。

調査・対応

探すと、http://thinkwiki.de/Thinkfanがあった。
ドイツ語は読めないので、google先生に英語にしてもらう。

温度センサのファイルが見つからない場合、別のドライバを使う必要があるみたい。
手順は以下の感じ。

1. sudo sensors-detect *1
検出するかの質問にすべてEnter (YES)と答える。
最後の以下の質問にyesと答える。

Do you want to add these lines automatically to /etc/modules? (yes/NO)

ここで、X220 の温度センサは coretemp モジュールで良さそうということがわかった。
ここまでで、モジュールの読み込み準備は完了。

2. sudo systemctl start module-init-tools でカーネルモジュールをロードする。もしくはリブート。

3. 利用可能なセンサーを以下で特定

find /sys/devices -type f -name "temp*_input"

4. /etc/thinkfan.conf にsensor 行を記載
温度設定の前

sensor /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp2_input
sensor /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp3_input
sensor /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input
sensor /sys/devices/virtual/hwmon/hwmon0/temp1_input

5. 最後に systemctl start thinkfan.service で起動。エラーなし。

おわりに

さて、以上でdpkgのエラーも解消して、アップデートが完了するようになった。
今まで温度に応じて動いていなかったファンが、頻繁にフル回転するようになってやかましい。
が、正しい動きだよなぁ、これ。

システムの不可状態をモニタするために、gnome-shellの拡張を復活させようかな、ということで、gnome-shell-extension-system-monitorパッケージを入れてみた。
良さそうなので、しばらく様子を見てみる。

*1:lm-sensorsパッケージ内にある