LoginSignup
22
31

More than 1 year has passed since last update.

従来版WSLから、ストア版WSLに更新する方法

Last updated at Posted at 2022-11-27

はじめに

従来版WSLから、ストア版WSLに更新する手順をまとめました。一言にすればこれだけです。

$ wsl --update

特に引継ぎ作業をする必要もなく、インストール済みのOSはそのまま利用することができます。

標準でsystemdがサポートされるようになったため、genieや、Distrodの追加インストールは不要になりました。
(さらに、Windows10ではLinuxのGUI(WSLgが搭載)が利用可能になっています。)

手順の内容

  • OS組み込みの従来版WSLから、ストア版WSLに更新する

    • インストール済みのOSは引き続きそのまま利用できます
  • Microsoft StoreからOSをインストールする

    • AlmaLinux8をインストールする
  • ストア版ではsystemdが利用できるようになりましたが、設定変更が必要

    • /etc/wsl.conf に設定を追加して有効化されることを確認します
  • 前提

    • Windows11(windows10でも大丈夫なはず)
    • WSLが利用できる状態になっていること

インストール済みのOS

$ wsl -l -v
  NAME       STATE           VERSION
* Ubuntu     Running         2
  CentOS7    Stopped         2

バージョン確認。--versionオプションが無効(従来版)であることを確認する

$  wsl --version
コマンド ライン オプションが無効です: --version
Copyright (c) Microsoft Corporation. All rights reserved.

使用法: wsl.exe [Argument] [Options...] [CommandLine]
~~~以下略~~~
  • ストア版のインストールは下記コマンドを実行する
$ wsl --update
  • インストール中の様子(1分程度で完了しました)
    image

  • インストール完了
    image

  • インストール完了後、バージョンを確認。詳細なバージョンが表示されるようになります

$ wsl --version
WSL バージョン: 1.0.0.0
カーネル バージョン: 5.15.74.2
WSLg バージョン: 1.0.47
MSRDC バージョン: 1.2.3575
Direct3D バージョン: 1.606.4
DXCore バージョン: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windowsバージョン: 10.0.22000.1281

動作確認

  • インストール済みのOSは引き続き認識されていました
$ wsl -l -v
  NAME       STATE           VERSION
* Ubuntu     Stopped         2
  CentOS7    Stopped         2
  • Ubuntuを起動

特に変わることなく利用できました

$ wsl.exe -d Ubuntu

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"

AlmaLinux8をインストール

  • ストアアプリからAlmalinux8で検索してインストール
    image

  • ユーザ名とパスワードを入力

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: tkykn
Changing password for user tkykn.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Installation successful!
  • AlmaLinuxがインストールされたことを確認
$ cat /etc/os-release
NAME="AlmaLinux"
VERSION="8.5 (Arctic Sphynx)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.5"
PLATFORM_ID="platform:el8"
PRETTY_NAME="AlmaLinux 8.5 (Arctic Sphynx)"

systemdを利用できるように設定変更する

  • 初期状態ではsystemdが動作していないことを確認
$ systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
  • /etc/wsl.conf ファイルを編集する(ファイルがなかったため新規作成して書き込み)
sudo vi /etc/wsl.conf

下記内容を書き込んで保存する

[boot]
systemd=true

一旦シャットダウン(wsl.exe --shutdown)後、AlmaLinuxを再起動してからsystemdが有効になっていることを確認する

$ systemctl status
● DESKTOP-0IMGJGP
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Sun 2022-11-27 16:43:59 JST; 7s ago
   CGroup: /
           ├─init.scope
           └─system.slice
             ├─apache2.service
             ├─systemd-udevd.service
             ├─cron.service
  ~~~以下略~~~
22
31
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
22
31