LoginSignup
4
1

More than 1 year has passed since last update.

WSL上の Ubuntu 20.04 LTS を 22.04 LTS へアップグレードする

Last updated at Posted at 2022-08-15

はじめに

2022年8月11日にUbuntu 22.04.1 LTS がリリースされました。元々8月4日の予定でしたが、インストーラーイメージバグが見つかったとのことで1週間遅れての公開です。

22.04.1 LTS がリリースされたことで、20.04 LTS からのアップグレードも可能1となりました。今回はタイトルの通り、WSL上の Ubuntu 20.04.4 をアップグレードしたのでその手順を残します。

環境

  • Ubuntu 20.04.4 ( on Windows 11 Pro 21H2 の WSL2)
    ※ 重要なデータは事前に必ずバックアップを取りましょう!

手順

コマンドラインでアップグレードします。

1. 【事前準備】パッケージ最新化

パッケージ更新
sudo apt update
sudo apt upgrade
sudo apt autoremove

2. アップグレード実行

アップグレード実行
do-release-upgrade

# sudoなしでも実行可
# 内部でsudo相当の処理が行われ、必要に応じてパスワードが要求される

【参考】アップグレード実行時のメッセージ

操作が必要だった箇所とその周辺のメッセージを以下に記載します。

  • 「……」は省略箇所
  • 「## ~ ##」は操作が必要な個所(~が操作内容)
  • 空行は適宜削除
実行メッセージ1:sources.listを一部無効化するという確認
Some third party entries in your sources.list were disabled. You can
re-enable them after the upgrade with the 'software-properties' tool
or your package manager.

To continue please press [ENTER]   ## [Enter] 入力して継続 ##
実行メッセージ2:実行内容確認
1 installed package is no longer supported by Canonical. You can
still get support from the community.
4 packages are going to be removed. 91 new packages are going to be
installed. 604 packages are going to be upgraded.
You have to download a total of 257 M. This download will take about
1 minute with your connection.

Installing the upgrade can take several hours. Once the download has
finished, the process cannot be canceled.

 Continue [yN]  Details [d]    ## 念のため[d] を入力して実施内容の確認 ##

No longer supported: wslu
Remove (was auto installed) fuse libsemanage1 libtss2-esys0
  python3-twisted-bin
Install: binutils binutils-common binutils-x86-64-linux-gnu

  ……

:                             ## [q] を入力して詳細を閉じる ##
Continue [yN]  Details [d]    ## [y] を入力して継続 ##
実行メッセージ3:削除確認
Searching for obsolete software
Reading state information... Done
Remove obsolete packages?
68 packages are going to be removed.

 Continue [yN]  Details [d]    ## [y] を入力して継続 ##
実行メッセージ4:アップグレード完了
System upgrade is complete.
Action required
Exit all other instances of Ubuntu WSL before continuing.
Unsaved progress may otherwise be lost.

To continue please press [ENTER]   ## 他にWSLを実行していれば終了してから[Enter] ##

WSL restart required
Exit this instance of Ubuntu WSL.
The upgrade will then be complete.

To continue please press [ENTER]   ## [Enter] を入力して完了 ##
=== Command detached from window (Mon Aug 15 13:04:49 2022) ===

3. 再起動

アップグレードが完了したらwslを抜けます。その後、PowerShellもしくはコマンドプロンプト上でwsl -t <ディストリビューション名>を実行し、wslを再起動します。

実行例
#  ディストリビューションの一覧を表示
PS C:\Users\sadamu> wsl -l
Linux  Windows サブシステム ディストリビューション:
Ubuntu (既定)
  ……

# Ubuntuディストリビューションを再起動
PS C:\> wsl -t Ubuntu

4. 確認

再度wslに入り/etc/os-releaseファイルにてアップデートが完了していることを確認します。

/etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

【おまけ】少しだけハマった点

実はdo-release-upgrade実行が最初の方で止まって、先に進めない問題が発生していました。

止まった箇所
Invalid package information

After updating your package information, the essential package
'ubuntu-minimal' could not be located. This may be because you have
no official mirrors listed in your software sources, or because of
excessive load on the mirror you are using. See /etc/apt/sources.list
for the current list of configured software sources.
In the case of an overloaded mirror, you may want to try the upgrade
again later.

  ……

=== Command terminated with exit status 1 (Mon Aug 15 11:42:04 2022) ===
## [x] 入力して終了 ##

原因は以下の記事で書いた/etc/apt/sources.listの変更でした。幸い記事内にインストール直後の状態を記録していたので、/etc/apt/sources.listを元に戻すことで無事アップグレードが完了しました。

/etc/apt/sources.list(インストール直後、コメント・空行除去)
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse

なお、コメント・空行除去は以下のコマンドで行っています。

コメント・空行を除去してsources/list表示
cat /etc/apt/sources.list | sed -e "/^#/d" -e "/^$/d"

おわりに

バックアップは重要ですね。ともあれ、これで wsl -d Ubuntu を実行することでUbuntu 22.04.1 LTSを使用できる環境が整いました。

  1. LTSからLTSへのアップグレードは、アップグレード先LTSの最初のポイントリリースが出た後の実施を推奨しているようです。ポイントリリースを待たずにアップグレードするやり方もあります。

4
1
1

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
4
1