Windowsの中でLinuxが仮想的に構築できて便利な WSL2
なんとかかんとか動くようになって( genie とか sysemd とかいろいろ大変だったけど )一安心してたら、どうも時刻のズレが激しいことに気づく。
確認してみると systemd でサービスとして稼働する時刻同期サービス systemd-timesyncd.service がきちんと動いていなかった。
紆余曲折あってなんとかうまく稼働するようになったんだけど、apt で更新かけるとまたうまく同期しなくなってしまった。
備忘録として書き留めておくことに(物忘れが多くなってきたので…)
-----
■動作してないときの状況
systemctl で 稼働状況を確認すると
$ systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time SynchronizationLoaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Condition: start condition failed at Tue 2022-11-01 17:31:27 JST; 6h ago
└─ ConditionVirtualization=!container was not met
Docs: man:systemd-timesyncd.service(8)
10月 16 19:46:50 ********-wsl systemd[1]: Condition check resulted in Network Time Synchronization being skipped.
-----
■対処方法
ネットの海を検索してたどり着いたのが設定ファイルの一箇所をコメントアウトするという海外の記事。
試したけどうまくいかなかったりで試行錯誤した結果、これにたどり着いた。
$ cat /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
# SPDX-License-Identifier: LGPL-2.1+#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Network Time Synchronization
Documentation=man:systemd-timesyncd.service(8)
ConditionCapability=CAP_SYS_TIME
# ConditionVirtualization=!container ←この1行をコメントアウトする
DefaultDependencies=no
After=systemd-sysusers.service
Before=time-set.target sysinit.target shutdown.target
Conflicts=shutdown.target
(以下略)
書き換えたら Ubuntu を再起動(サービスだけ再起動でもいいんだろうけど念のため)
-----
これが本当に正解かどうかはわからないけど、ちゃんと稼働してるからまあいいか。
ただし apt で更新したときに戻っちゃうことがあるから、それだけは注意が必要!