I recently found myself in the need to convert a Windows server installed with BIOS, to UEFI, in order to utilize virtualization-based security on the server. It’s not too complex a process, so I decided to write a script to solve this. I’m glad I did, as I learnt a lot about how disks, partitions, bios and uefi works. You can find the complete script on my GitHub. Feel free to use at your own risk. It’ s not flawless or perfect, but it does work.
The general outline of the steps in the script are:
- If Vmdk convert to Vhdx
- Mount source disk
- Find Windows and data partitions
- Mount source partitions
- Check if Windows Recovery Environment is disabled
- Create Wim images from the partitions
- Create a new disk
- Partition new disk with UEFI. Make enough space for source partitions to be applied.
- Mount and partition the new disk
- Mount new partitions and apply the Wim images
- Configure Windows to boot from EFI system partition
- Dismount and convert to Vmdk if that was the source format
Activities and errors are logged to the user’s appdata, and written to screen with the verbose stream.
Script is tested on a Windows 10 Enterprise workstation, and can reliably convert a normal sized, 60 GB disk with Windows Server 2019 installed, in under 5 minutes.
The script has dependencies to:
- PowerShell 5.1+
- Hyper-V PowerShell module
Edit: After first publishing this post I have also added functionality to convert WIM images to UEFI Vmdk/Vhdx. WIM images of online systems can be created with Disk2Vhd and Dism, which are free tools from Microsoft Sysinternals.
Note: When converting to Vmdk, the Vmdk is not in ESXi format, and will need to be converted if you plan on running the VM on an ESXi platform. See this KB from VMware.
The whole script is too long to paste here, so please check it out on my GitHub.