7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2 を PowerShellで有効にする

Last updated at Posted at 2020-06-07

機能の有効化

まず、Microsoft-Windows-Subsystem-Linuxの確認

 Get-WindowsOptionalFeature -Online -FeatureName *linux*

FeatureName      : Microsoft-Windows-Subsystem-Linux
DisplayName      : Linux  Windows サブシステム
Description      : ネイティブなユーザー モードの Linux シェルおよびツールを Windows で実行するためのサービスと環境を提供します。
RestartRequired  : Possible
State            : Enabled
CustomProperties :
                   ServerComponent\Description : ネイティブなユーザー モードの Linux シェルおよびツールを Windows で実行するためのサービスと環境を提供します。
                   ServerComponent\DisplayName : Linux  Windows サブシステム
                   ServerComponent\Id : 1033
                   ServerComponent\Type : Feature
                   ServerComponent\UniqueName : Microsoft-Windows-Subsystem-Linux
                   ServerComponent\Deploys\Update\Name : Microsoft-Windows-Subsystem-Linux

WSL を使っていればおそらくこちらは既に State : Enabledとなっていることでしょう。
もう一つ、VirtualMachinePlatformの確認

 Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

FeatureName      : VirtualMachinePlatform
DisplayName      : 仮想マシン プラットフォーム
Description      : 仮想マシンのプラットフォーム サポートを有効にします
RestartRequired  : Possible
State            : Disabled
CustomProperties :

こちらはState : Disabledだったので、有効化します。

 Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All
この操作を完了するために、今すぐコンピューターを再起動しますか?
[Y] Yes  [N] No  [?] Help (default is "Y"):

再起動して準備完了

WSL2 カーネルの更新

WSL 2 Linux カーネルの更新 にダウンロードリンクがあります。
こちらから更新プログラムパッケージをダウンロードしてインストールします。
2020-06-07.png

WSL2に切り替える

既定をWSL2にしたい場合はこちら

wsl --set-default-version 2

まずは既定は従来のWSL、一部ディストリビューションをWSL2に切り替えて使いたかったので、一部だけ切り替えます。

 wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         1
  kali-linux      Running         1
  WLinux          Stopped         1
  Ubuntu          Stopped         1
  openSUSE-42     Stopped         1

ここのNAMEに書いてある名前をそのまま間違えずに入力してください。

 wsl --set-version Ubuntu-18.04 2
変換中です。この処理には数分かかることがあります...
WSL 2 との主な違いについては、https://aka.ms/wsl2 を参照してください
変換が完了しました。

しばらく待つと変換が完了します。

 wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2
  kali-linux      Running         1
  WLinux          Stopped         1
  Ubuntu          Stopped         1
  openSUSE-42     Stopped         1

WSLのバージョンは同様にしていつでも切り替えることが出来ます。

おまけ

ところで、WSL2はHyper-Vが有効でないと動かないと思っていましたし、書いてあるのですが
Hyper-VがDisabledの状態で、WSL2は起動出来ているようですし、VirtualBoxとの共存が出来ました
image.png

また、WSLとWSL2でkernelを使い分けているみたいですね
image.png
image.png

参考リンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?