2020年12月30日 星期三

如何在 VM 的 Server Core 上啟用 WSL2

在Server Core 啟用WSL2

啟用VM的巢狀虛擬化

注意: Guest OS 的版本要在 Windows Server build 18945 版本以上,這裡的範例是使用 Windows Server 2004的版本

在VM安裝完成後,第一步就是先啟用VM的巢狀虛擬化

以Hyper-V為例(使用powershell)

Get-VM "VM的名字" | Set-VMProcessor -ExposeVirtualizationExtensions $true

各種VM啟用的方式,參考資料如下

Hyper-V 參考這裡

VMware 參考 這裡這裡

VirtualBox 參考這裡

接下來是進到VM裡安裝WSL2的步驟

1.啟用 Microsoft-Windows-Subsystem-Linux 及 VirtualMachinePlatform 這2個功能

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

安裝完之後重新開機

Restart-Computer

2.下載 Linux 核心更新套件

Invoke-WebRequest -Uri https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile c:\wsl_update_x64.msi  -UseBasicParsing

下載完成後執行

c:\wsl_update_x64.msi

會有畫面出來讓你按下一步(我還以為Server Core都沒有UI咧)。
安裝完成之後重新開機

Restart-Computer

3.把 WSL 預設版本改成 WSL2

wsl --set-default-version  2

成功啟用會有下列訊息,正常只會出現一行 有關 WSL 2…
如果出現其他的表示沒有啟用成功

PS C:\> wsl --set-default-version 2
有關 WSL 2 的主要差異詳細資訊,請瀏覽 https://aka.ms/wsl2

4.到這裡 看要下載哪一個給WSL2 用的 Linux 發行版本

我是下載Ubuntu 20.04 這個版本

Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.zip -UseBasicParsing

5.下載完成之後解壓縮

Expand-Archive .\Ubuntu.zip .\Ubuntu

6.到解壓縮的目錄執行安裝檔 , 以Ubuntu 20.04為例是 ubuntu2004.exe

PS C:\> cd .\Ubuntu\
PS C:\Ubuntu> .\ubuntu2004.exe

7. 安裝完成之後需設定Linux 的帳號密碼

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: 
New password:
Retype new password:
passwd: password updated successfully

輸入exit 就會離開linux

8.檢查設定是否正常

PS C:\Ubuntu> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

參考資料
1.Enable the Windows Subsystem for Linux
2.Windows 10 上適用於 Linux 的 Windows 子系統安裝指南

沒有留言:

張貼留言