Using Hyper-V to Emulate EFI

QEMU and OFMV are nice on linux but how about using Hyper-V to test EFI development in windows? While developing some EFI modules in Rust I wanted to test them on my primary windows enviornment without a lot of jumping through hoops. I have a hyper-v vm with windows 10 installed my EFI application will end up being a bootloader for so why not use that VM as my development platform? After installing windows on a Gen2 Hyper-V VM if you look at settings->firmware you’ll notice that the first boot item is specifically targeting a Microsoft provided boot manager. I my case I’d rather boot a shell and go from there.


Boot up Windows in your hyper-v vm (efi-dev), open admin powershell, and mount the system partiton:

mountvol s: /s
cd S:\EFI\

Now lets copy in some efi files to run. I had copied my built files over to the VM in the C:\dev\efi-shell\ folder. To copy them to the system partition:

mkdir test

cd .\test

copy C:\dev\efi-shell\shell.efi .\

bcdedit /set "{bootmgr}" path "\EFI\test\shell.efi"
bcdedit /set "{bootmgr}" description "shell"

You should now be able to reboot the system in the efi shell! You can verify in the host Hyper-V manager by looking at the Firmware-> Boot Order. You should see shell.efi as the value for the file boot entry and if it’s not for some reason move it to the top of the boot order.

To get back to windows from the shell:

blk1:

/EFI/Microsoft/Boot/bootmgfw.efi

Enjoy!