Skip to content

WSL2のUbuntu 20.04を22.04にアップデートする

はじめに

そういえばWSL2で動いているUbuntuってバージョンアップしなくていいのか?(反語)と思って調べてみたところ、現在使用しているUbuntu 20.04.6は、2025/04に既にサポートが終了していた。このまま放置するのはとても良くない。

そんな訳で、今回の目的は以下の通りである。

  • WSL2で動いているUbuntu 20.04を、次のLTSである22.04にアップデートする。
  • 22.04へのアップデートによりOpenSSL 3.xが使用できるようになるので、OpenSSL 3.xをNginxに適用する。

アップデートの前に

Ubuntuのバージョン確認

現在のバージョンはlsb_release -aで調べた。出力されたUbuntu 20.04.6 LTSの通り、現在のバージョンは20.04.6である。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

Ubuntu 20.04のバックアップ

Ubuntuの更新をする前に、現在動いているUbuntu 20.04環境のバックアップを取得しておく。

wsl -l -vでNAMEを確認した上で、それをwsl --exportに渡す。これで丸っと環境をエクポートできた。戻し方は失敗した際に調べよう。

PS> wsl --shutdown
PS> wsl -l -v
  NAME              STATE           VERSION
* Ubuntu-20.04      Stopped         2
  docker-desktop    Running         2
PS> wsl --export Ubuntu-20.04 D:\ubuntu-20.04-backup.tar
エクスポートが進行中ですこれには数分かかる場合があります (1142 MB): ./var/snap/lxd/common/lxd/unix.socket: pax format cannot archi (5108 MB)

この操作を正しく終了しました

Ubuntu 20.04を22.04に上げる

バックアップは取ったので、次はUbuntu 20.04を22.04にアップデートする。

アップデート実行

AIが言うにはsudo do-release-upgradeを打つだけ、とのことだっただが、更新できないと言われる。

$ sudo do-release-upgrade
Checking for a new Ubuntu release
In /etc/update-manager/release-upgrades Prompt
is set to never so upgrading is not possible.

release-upgradesを更新

更新できない原因は、メッセージの通り/etc/update-manager/release-upgradesPrompt=neverになっていることだった。

sudo vi /etc/update-manager/release-upgradesで編集し、Prompt=ltsに変更する。

$ cat /etc/update-manager/release-upgrades
# Default behavior for the release upgrader.

[DEFAULT]
# Default prompting and upgrade behavior, valid options:
#
#  never  - Never check for, or allow upgrading to, a new release.
#  normal - Check to see if a new release is available.  If more than one new
#           release is found, the release upgrader will attempt to upgrade to
#           the supported release that immediately succeeds the
#           currently-running release.
#  lts    - Check to see if a new LTS release is available.  The upgrader
#           will attempt to upgrade to the first LTS release available after
#           the currently-running one.  Note that if this option is used and
#           the currently-running release is not itself an LTS release the
#           upgrader will assume prompt was meant to be normal.
Prompt=lts

アップデート再実行

再度sudo do-release-upgradeを実行して、今度は無事にバージョンアップが完了した。

途中で何度かyNの選択肢が出るが、全てyを入れた。さすがに少し時間がかかった。体感的には5分くらいだったと思う。

$ sudo do-release-upgrade

(中略)

To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.

Continue [yN]

Ubuntuのバージョン確認

改めてlsb_release -aを実行すると、出力がUbuntu 22.04.5 LTSになっている。成功だ!

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.5 LTS
Release:        22.04
Codename:       jammy

Nginx起動確認

Nginxについても、systemdから問題なく自動起動している。

$ sudo systemctl status nginx
● nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2026-08-02 21:36:56 JST; 48s ago
(中略)
Aug 02 21:36:56 rio2 systemd[1]: Starting nginx - high performance web server...
Aug 02 21:36:56 rio2 systemd[1]: Started nginx - high performance web server.

NginxにOpenSSL3.xを適用する

Ubuntu 22.04にバージョンを上げたことで、OpenSSL 3.xが使えるようになっているはずだ。これをNginxに適用する。

OpenSSLのバージョン確認

openssl versionで確認すると、OpenSSLは3.0.2が入っている。

$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)

NginxのOpenSSL確認

だが、nginx -Vで確認すると、NginxはOpenSSL 1.1.1fのままになっている。

$ nginx -V
nginx version: nginx/1.28.0
built by gcc 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
built with OpenSSL 1.1.1f  31 Mar 2020
(後略)

Nginxをjammy向けに更新する

Nginxの使うOpenSSLを上げないと意味がない。ここはAIの言う通り、順に調べてみよう。

原因調査開始

/etc/apt/sources.list.d/nginx.listhttp://nginx.org/packages/ubuntu focal nginxのままになっているのが原因のようだ。

focalはUbuntu 20.04のコードネームのため、それはそうだという感じ。Ubuntu 22.04のjammyに変更が必要だ。

$ grep -R "nginx.org" /etc/apt/sources.list /etc/apt/sources.list.d/
/etc/apt/sources.list.d/nginx.list.distUpgrade:deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu focal nginx
/etc/apt/sources.list.d/nginx.list:deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu focal nginx
/etc/apt/sources.list.d/nginx.list.save:deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu focal nginx

nginx.listを更新する

sudo vi /etc/apt/sources.list.d/nginx.listで編集し、focaljammyに変更する。

deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu jammy nginx

apt updateを確認する

大丈夫そうだ。このままNginxを更新する。

$ sudo apt update
Get:1 http://nginx.org/packages/ubuntu jammy InRelease [4025 B]
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:5 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages [54.7 kB]
Hit:6 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 58.7 kB in 1s (39.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.

OpenSSL 3.0.2適用完了

sudo apt install --reinstall nginxをすると、OpenSSL 3.0.2が適用できているのが確認できた。

Nginxのバージョンもnginx/1.30.4に上がっている。

$ nginx -V
nginx version: nginx/1.30.4
built by gcc 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04.3)
built with OpenSSL 3.0.2 15 Mar 2022
(後略)

Nginx起動失敗

だが、今度はNginxの起動が失敗している。Nginxのバージョンを上げたことで、GeoIP2のモジュールが動かなくなっているのが原因のようだ。改めてngx_http_geoip2_module.soのビルドが必要なので、過去に自分が書いた記事を参考にして慌てて再ビルドした。

Nginxのバージョンが変わっているのでwget https://nginx.org/download/nginx-1.30.4.tar.gzに変えた。他は./configureのパラメータを変えるだけで、ほぼそのまま同じ手順を使えた。何事も手順を残しておくのは大切だね。

$ sudo systemctl status nginx
× nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2026-08-02 22:29:44 JST; 3min 54s ago
       Docs: https://nginx.org/en/docs/
    Process: 2027 ExecStart=/usr/sbin/nginx -c ${CONFFILE} (code=exited, status=1/FAILURE)
        CPU: 3ms

Aug 02 22:29:44 rio2 systemd[1]: Starting nginx - high performance web server...
Aug 02 22:29:44 rio2 nginx[2027]: nginx: [emerg] module "/etc/nginx/modules/ngx_http_geoip2_module.so" version 1028000 >
Aug 02 22:29:44 rio2 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Aug 02 22:29:44 rio2 systemd[1]: nginx.service: Failed with result 'exit-code'.
Aug 02 22:29:44 rio2 systemd[1]: Failed to start nginx - high performance web server.

起動成功

ngx_http_geoip2_module.soを差し替えることで、今度はNginxの起動に成功した。これは日曜の夜にやる作業じゃなかった。

$ sudo systemctl status nginx
[sudo] password for dezikomoe:
● nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2026-08-02 23:36:25 JST; 23min ago
(後略)