This document provides step-by-step instructions to test the UEFI version of MiniVisor on Hyper-V.
The readers are expected to be able to build MiniVisor already. If not, please go through Building and Debugging first.
To follow this instruction, the reader must have a 64bit Windows 10 ISO image to set up a new virtual machine on Hyper-V.
Alternatively, the reader can use an existing virtual machine as long as it has the same configurations as specified in this instructions.
The instructions are largely divided into the following steps:
- Setting up a new virtual machine
- Creating a bootable virtual drive to boot into the UEFI shell
- Testing with the virtual machine
-
From Hyper-V Manager, create a new machine. This instruction assumes the virtual machine is named as "Windows 10 UEFI".
-
Complete setup. There is no special requirement for Windows installation. No Windows Update is required.
-
Shutdown the virtual machine and open the settings of it.
-
Give the name of the disk file. This instruction assume it is named as "FAT.vhdx".
-
Select "Create a new blank virtual hard drive" and specify the size. 1GB is big enough.
-
Then, move up the new hard drive at the top of the boot order list.
-
Start PowerShell with the administrators privileges.
-
Run the follow command to mount the new drive.
PS> Mount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\FAT.vhdx"
-
Open Disk Management.
PS> diskmgmt.msc
-
It should prompt for initialization of the disk. Select "MBR (Master Boot Record)".
-
On Disk Management, right click the new disk and select "New Simple Volume".
-
Click [Next]. This instruction assumes the drive letter D: is assigned to it.
-
Now, D:\ should be accessible to place files into the new hard drive.
-
Download pre-compiled the UEFI shell from the EDK2 repository (Download). This instruction assumes the file is downloaded as
%USERPROFILE%\Downloads\Shell.efi
-
Deploy the UEFI shell as
Bootx64.efi
, so it can be started automatically.> cd /d D:\ > mkdir EFI\Boot > copy %USERPROFILE%\Downloads\Shell.efi EFI\Boot\Bootx64.efi
-
Build MiniVisor and place the compiled file into the D drive.
> cd /d C:\edk2 > edksetup.bat > build -w -a X64 -t VS2019 -b NOOPT -p MiniVisorPkg\Builds\Platform\EFI\MiniVisorPkg.dsc > copy /y C:\edk2\Build\MiniVisor\NOOPT_VS2019\X64\MiniVisorDxe.efi D:\
-
Finally, dismount the hard drive and enable nested virtualization by running the following command on PowerShell with administrators privileges.
> Dismount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\FAT.vhdx" > Set-VMProcessor -VMName "Windows 10 UEFI" -ExposeVirtualizationExtensions $true
We are going to test MiniVisor on the virtual machine next.
-
Start the virtual machine. It should enter to the UEFI shell.
-
Find the file system that contains
MiniVisorDxe.efi
. In this example, it was infs2:
. Then load it.> fs2: > load MiniVisorDxe.efi
-
Then, find the file system that has the
EFI\Boot\bootx64.efi
and execute it. In this example, it was infs0:
.> fs0: > EFI\Boot\bootx64.efi
This should boot Windows successfully.
-
Existence of MiniVisor can be confirmed with
CheckHvVendor.exe
.
To iterate testing workflow, build the MiniVisor then run the following command on PowerShell.
PS> Mount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\FAT.vhdx"
PS> Copy-Item C:\edk2\Build\MiniVisor\NOOPT_VS2019\X64\MiniVisorDxe.efi -Destination D:\
PS> Dismount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\FAT.vhdx"
PS> Start-VM -Name "Windows 10 UEFI
This copies the newly built MiniVisorDxe.efi into the hard drive and then starts the virtual machine.
Also, to automate commands in the UEFI shell, one can place a file named startup.nsh
containing commands in the D drive to execute automatically.
Just like with VMware, serial output can be used.
-
Run the following command on PowerShell with the administrators privileges.
PS> Set-VMComPort -VMName "Windows 10 UEFI" -Path \\.\pipe\com_1 -Number 1
-
Build MiniVisor with the
-D DEBUG_ON_SERIAL_PORT
flag.> build -w -a X64 -t VS2019 -b NOOPT -p MiniVisorPkg\Builds\Platform\EFI\MiniVisorPkg.dsc -D DEBUG_ON_SERIAL_PORT
-
Open serial connection for
\\.\pipe\com_1
at baudrate 115200. As an example with PuTTY, it should look like this.It should show a blank screen.
-
Once the MiniVisor is loaded, serial logs should show up on the PuTTY windows.
-
Configure the virtual machine with a single processor. Multi processor system is unsupported.
- This is partly because the MP protocol is not implemented on Hyper-V UEFI, but even if it were, nested virtualiation on Hyper-V does not support the wait-for-SIPI guest activity state. This is very different from any bare-metal I tested, and MiniVisor does not work on such MP systems.
- For this reason, I strongly encourage everyone to test on VMware and bare-metal. Not working with MP system is like not working with pointer in the C programing language.
-
Debugging is not as easy as the case with QEMU+KVM or VMware due to lack of GDB debugging (ie, emulation of hardware debuggers). The authors recommend using those environment instead for this reason.
-
Kudos to Sinaei (@Intel80x86) for documenting tricks to run a custome hypervisor on Hyper-V.