5

【茶包射手日記】無法在 Azure VM 使用 WSL、Android 模擬器

 9 months ago
source link: https://blog.darkthread.net/blog/hyper-v-on-azure-vm/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【茶包射手日記】無法在 Azure VM 使用 WSL、Android 模擬器-黑暗執行緒

在 Azure VM 的 Windows 11 啟用 WSL 出現錯誤,訊息顯示與主機硬體沒啟用 Intel Virtualization Technology (VT-x) 有關:

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80370102
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/enablevirtualization
Press any key to continue...
Fig1_638255441771603755.png

WSL 依賴 Hyper-V,需要 CPU 硬體支援並在 BIOS 啟用虛擬化技術,但 Azure VM 沒法設 BIOS 啊~ 查了一下,Azure 在很多年前就支援了 Nested Virtualization,部分 VM Size 支援在 Azure VM 上使用 VT-x 應用,執行 Hyper-V、Docker,跑手機模擬器等等。查詢 VM Size 文件,可由 Nested Virtualization 項目判斷是否支援:

Fig2_638255441775261873.png

聽起來很簡單吧?網路上相關問題也都是說選對 VM Size 就行了,但我改了好幾種 VM Size 也確認文件說有支援 Nested Virtualization,但怎麼都無法成功。

終於在一篇Q&A找到答案。

當 VM Size 及作業系統有支援的話,Azure VM 預設採用可信啟動(Trusted Launch) 模式,可帶來一些安全強化,像是安全開機(防止被惡意軟體植入)、vTPM(Trusted Platform Module,硬體保護等級的金鑰管理) 參考:Trusted launch for Azure virtual machines,VM 的安全模式可從 Azure Portal 確認:

Fig3_638255441777151146.png

查了一下,2022 年 12 月起 Azure VM 改為預設 Trusted Launch VM,是半年前的事,這可以解釋為什麼我查到的大部分文件都說選對 VM Size 就行了,沒什麼人提到這點。安全類型需要在建立 VM 時決定:

Fig4_638255441779261198.png

重點來了,可信啟動模式會導致某些功能會失效

  • Azure Site Recovery
  • Azure Automanage
  • Ultra disk, Premium SSD v2
  • Managed Image
  • Nested Virtualization (most v5 VM sizes supported)

BINGO!

有個 Set-AzVMSecurityProfile 指令貌似可以修改,但實測無效,必須重建 VM。另一方面,為了在 VM 使用虛擬化停用比較安全的可信啟動不是好主意。以為卡住之際,發現我漏看重要訊息,前面提到可信啟動不支援功能時說法為 Nested Virtualization (most v5 VM sizes supported),意思是 v5 版本的 VM 可以支援,因查到早期文件提到支援 Nested Virtualization 的 VM 都是 Dv3、Ev3、Dv4,我直覺也就在這幾種主機上打轉,傻傻地錯過 Dv5。

答案就這麼簡單,換成 Dv5 VM (Standard_D4ds_v5),封印解除。

Fig5_638255441781330347.png

順便學會一招,在 VM 內部呼叫 169.254.169.254 WebAPI Azure Instance Metadata Service,可以取得 VM 資訊:

(Invoke-RestMethod -Headers @{"Metadata"="true"} -URI http://169.254.169.254/metadata/instance/compute?api-version=2019-03-11 -Method get).vmSize

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK