LoginSignup
0
0

More than 1 year has passed since last update.

WSL2のaptが失敗したけど時刻を合わせたら直った

Posted at

※既存記事のよせあつめ記事

以前まではaptが問題なく通っていたが、いつからかapt installapt updateですらエラーが出るようになってしまっていた。

apt installは404で失敗する。ものによってはインストール自体は上手くいってそうだが、最後に何かエラーっぽい出力が出る、というのもある。

$ sudo apt install xxxx
...
After this operation, 547 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 xxxx-xxxx-xxx amd64 xxxxxxxx
Err:1 http://security.ubuntu.com/ubuntu jammy-updates/main amd64 xxxx-xxxx-xxx amd64 xxxxxxxx
  404  Not Found [IP: 185.125.190.36 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/o/xxxxxxxx.deb  404  Not Found [IP: 185.125.190.36 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

apt updateis invalid not yetの旨。

~$ sudo apt update
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1395 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main Translation-en [510 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 c-n-f Metadata [30.3 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [129 kB]
Get:9 http://archive.ubuntu.com/ubuntu jammy/restricted Translation-en [18.6 kB]
Reading package lists... Done
E: Release file for http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease is not valid yet (invalid for another 13h 1min 53s). Updates for this repository will not be applied.
E: Release file for http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease is not valid yet (invalid for another 13h 1min 42s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease is not valid yet (invalid for another 13h 2min 17s). Updates for this repository will not be applied.

でググっていたところ、「source.listの更新」や「proxy設定忘れ」などの対処方法があったが、「時刻合わせで直る」みたいなのを発見した。確かにupdateのほうのエラーにはnot valid yet (invalid for another XXh)とか書いてある。
https://teratail.com/questions/365651
https://snowsystem.net/other/windows/wsl2-ubuntu-error-time-setting/


で、WSL2は時刻がいろんなタイミングでずれていくらしい。WSL1はWindowsホストと同じ時刻をみる仕組みだったとか。
https://qiita.com/moriai/items/f633e01728d8d062adb1

よって、上記記事のntpdateの方法でnictのNTPに合わせる形で対処。WSL Ubuntuはntpdateが入っていないのでapt installで入れてみる
…ってこれもaptだから入らない可能性は高いな、まあ入らなければ手作業で時刻合わせりゃいいだろう。

$ sudo apt install ntpdate
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
...
Failed to retrieve available kernel versions.

Failed to check for processor microcode upgrades.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

成功した感が薄いが、ntpdateは実行できたので実行。

$ ntpdate
usage: ntpdate [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...
$ sudo ntpdate ntp.nict.jp
XX XXX HH:MM:DD ntpdate[10218]: step time server 133.243.238.164 offset +50631.536037 sec

この後再度apt updateなどでOK。
時刻ズレ起因のエラーはいろんなところでいろんな文言で出現するので、「時刻ずれで起きる現象一覧」みたいなものがあるとググり人には便利かもなとは思う やらんけど

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0