WSL2で時刻がずれる


apt updateでエラー

WSL2のubuntu 20.04でapt updateをしたら以下のエラーが発生した。

$ sudo apt update
[sudo] password for nomura:
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Reading package lists... Done
E: Release file for http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 3d 2h 52min 14s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 3d 2h 52min 25s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 3d 2h 52min 46s). Updates for this repository will not be applied.

いろいろと調べてみると時刻がずれていると発生するエラーらしい。

$ date
Fri Jan  1 06:21:14 JST 2021

現在の時刻は2021/01/04 11:00です。
ハードウェアの時刻に合わせてみる。

$ sudo hwclock -s
$ date
Mon Jan  4 11:06:15 JST 2021

Windowsの時計と比べて5分くらいずれているが、これで再度apt updateをしてみる。

$ sudo apt update
[sudo] password for nomura:
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Fetched 324 kB in 3s (121 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

成功しました。

PowerShellなどからwslを再起動してもなおるみたいです。
#PCをスリープしたりしているとWSLの時刻がずれていくらしい。

> wsl --shutdown