Windows Server2022にMicrosoftを使わないでWSL1を使用できるようにする。

EC2アイキャッチ画像

・Windows ServerにMicro Softを使用せずWSLを導入したい

WSLを有効化

下記コマンドよりWSLの有効化を行います。
すでに有効化している場合は下記の画像のように表示されます。

まだ有効化していない場合再起動を求められますので、再起動しましょう。

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
WSL有効化

WSLのインストール

下記コマンドよりWSLインストールを行います。また合わせてWSL1にバージョンを設定します。

wsl --install
wsl --set-default-version 1

Ubuntu22をインストール

下記のリンクよりディストリビューションをダウンロードします。
今回の場合「Ubuntu 22.04 LTS」をダウンロードしました。

https://learn.microsoft.com/ja-jp/windows/wsl/install-manual#downloading-distributions

次にダウンロードしたファイル(私の場合”Ubuntu2204-221101.AppxBundle”)をwindows環境に送付します。
どこでもいいですが C:\Users\Administrator に送付しました。

次に先ほどのダウンロードファイルをzipファイルに変更し展開します。
windows serverなのでリモートデスクトップ接続を行いGUIで操作しても良いですが、power shellからのやり方を紹介します。

Rename-Item Ubuntu2204-221101.AppxBundle Ubuntu.zip
Expand-Archive .\Ubuntu.zip .\Ubuntu

※下記のエラーが出た人は、下記コマンドで実行してください

‘Rename-Item’ is not recognized as an internal or external command, operable program or batch file.

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -Command Rename-Item Ubuntu2204-221101.AppxBundle Ubuntu.zip
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -Command Expand-Archive .\Ubuntu.zip .\Ubuntu

解凍したUbuntuへ移動

cd Ubuntu
dir
Ubuntu一覧

今回は「Ubuntu_2204.1.7.0_x64.appx」を使いますので、こちらをまたzipファイルにリネームして解凍

Rename-Item Ubuntu_2204.1.7.0_x64.appx Ubuntu_2204.1.7.0_x64.zip
Expand-Archive Ubuntu_2204.1.7.0_x64.zip Ubuntu2204
zipファイルにリネーム

解凍先へ移動し、exeファイルを実行すれば、ユーザー名とパスワードを問われると思うので入力すれば完了です。

ubuntu実行画面

使い方

次回以降使用する場合は、Powershellまたはcmdから「WSL」と入力すれば実行できます。

実行画面

参考資料

https://qiita.com/fararrow/items/1007c850d81022799420

https://learn.microsoft.com/ja-jp/windows/wsl/install-manual#downloading-distributions

https://learn.microsoft.com/ja-jp/windows/wsl/install-on-server

https://stackoverflow.com/questions/29778121/powershell-is-not-recognized-as-an-internal-or-external-command-operable-progr