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

・Windows ServerにMicro Softを使用せずWSLを導入したい
WSLを有効化
下記コマンドよりWSLの有効化を行います。
すでに有効化している場合は下記の画像のように表示されます。
まだ有効化していない場合再起動を求められますので、再起動しましょう。
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

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

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

使い方
次回以降使用する場合は、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
- タグ:
- EC2