Learn how to make a VHDX bootable in Hyper-V using Disk2vhd, a utility that creates VHD versions of physical disks for use in virtual machines.
If you have a physical server running Windows Server 2012 R2 Essentials and you want to migrate it to a virtual machine on Hyper-V, you might use Disk2vhd, a utility that creates VHD (Virtual Hard Disk) versions of physical disks. However, you might encounter a problem when you try to boot the VHDX file in Hyper-V: it won’t boot and it might show an error message like “Boot failed. EFI SCSI Device.” This is because the VHDX file lacks the boot manager that is required for UEFI booting. In this article, we will show you how to fix this problem and make your VHDX bootable in Hyper-V.
Table of Contents
- What is Disk2vhd and How Does It Work?
- Why Does the VHDX File Not Boot in Hyper-V?
- How to Make the VHDX File Bootable in Hyper-V?
- Step 1: Create a new VHDX file with the same size as the EFI system partition on the physical disk
- Step 2: Attach the new VHDX file and the original VHDX file to a Hyper-V generation 2 virtual machine
- Step 3: Boot the virtual machine from a Windows installation media or a Windows PE drive
- Step 4: Use Diskpart to create a FAT32 partition on the new VHDX file and assign it a drive letter
- Step 5: Use Robocopy to copy the contents of the EFI system partition from the physical disk to the new VHDX file
- Step 6: Use Bcdboot to create the boot files on the new VHDX file and update the boot configuration data (BCD) store
- Step 7: Use Bcdedit to modify the BCD store and set the correct device and osdevice values for the boot entry
- Step 8: Detach the new VHDX file and the original VHDX file from the virtual machine
- Step 9: Attach the new VHDX file as the first IDE disk and the original VHDX file as the second IDE disk to the target Hyper-V generation 2 virtual machine
- Step 10: Boot the target virtual machine from the new VHDX file and verify that the operating system loads correctly
- Frequently Asked Questions (FAQs)
- Question: What is the difference between VHD and VHDX?
- Question: What is the difference between BIOS and UEFI?
- Question: What is the difference between MBR and GPT?
- Summary
What is Disk2vhd and How Does It Work?
Disk2vhd is a utility that creates VHD versions of physical disks for use in Microsoft Virtual PC or Microsoft Hyper-V virtual machines. The difference between Disk2vhd and other physical-to-virtual tools is that you can run Disk2vhd on a system that’s online. Disk2vhd uses Windows’ Volume Snapshot capability, introduced in Windows XP, to create consistent point-in-time snapshots of the volumes you want to include in a conversion. You can even have Disk2vhd create the VHDs on local volumes, even ones being converted (though performance is better when the VHD is on a disk different than ones being converted).
Disk2vhd has a simple user interface that lists the volumes present on the system and allows you to select the ones you want to include in the VHD. It will create one VHD for each disk on which selected volumes reside. It preserves the partitioning information of the disk, but only copies the data contents for volumes on the disk that are selected. This enables you to capture just system volumes and exclude data volumes, for example.
Disk2vhd supports both VHD and VHDX formats. VHD is the older format that is compatible with Virtual PC and Hyper-V generation 1 virtual machines. VHDX is the newer format that supports larger disk sizes and other features, but it is only compatible with Hyper-V generation 2 virtual machines. Disk2vhd detects the type of disk (MBR or GPT) and automatically selects the appropriate format. However, you can also manually choose the format by using the command-line options.
To use VHDs produced by Disk2vhd, you need to create a virtual machine with the desired characteristics and add the VHDs to the VM’s configuration as IDE disks. On first boot, a VM booting a captured copy of Windows will detect the VM’s hardware and automatically install drivers, if present in the image. If the required drivers are not present, you need to install them via the Virtual PC or Hyper-V integration components. You can also attach to VHDs using the Windows 7 or Windows Server 2008 R2 Disk Management or Diskpart utilities.
Why Does the VHDX File Not Boot in Hyper-V?
The reason why the VHDX file created by Disk2vhd does not boot in Hyper-V is that it lacks the boot manager that is required for UEFI booting. UEFI (Unified Extensible Firmware Interface) is a standard that defines the interface between the operating system and the firmware. UEFI supports more advanced features than the legacy BIOS, such as secure boot, faster boot time, larger disk support, and graphical user interface. UEFI also requires a different boot process than BIOS, which involves a boot manager, a boot loader, and an EFI system partition.
The boot manager is a program that runs in the UEFI environment and presents a menu of boot options to the user. The boot manager can be located in the firmware, on a removable device, or on a hard disk. The boot manager loads the boot loader, which is a program that loads the operating system kernel and other files. The boot loader can be located on the same partition as the operating system, or on a separate partition. The EFI system partition is a special partition that contains the boot manager, the boot loader, and other files required for UEFI booting. The EFI system partition is formatted with FAT32 and has a specific GUID in the partition table.
When you use Disk2vhd to create a VHDX file from a physical disk that uses UEFI booting, the utility does not copy the EFI system partition to the VHDX file. This is because the EFI system partition is not assigned a drive letter by Windows and is not visible in the Disk2vhd user interface. Therefore, the VHDX file does not have the boot manager that is needed to start the boot process. When you try to boot the VHDX file in Hyper-V, the firmware cannot find the boot manager and fails to boot.
How to Make the VHDX File Bootable in Hyper-V?
To make the VHDX file bootable in Hyper-V, you need to add the EFI system partition to the VHDX file and configure the boot manager to point to the correct boot loader. There are different ways to do this, but we will show you one possible method that involves the following steps:
- Create a new VHDX file with the same size as the EFI system partition on the physical disk.
- Attach the new VHDX file and the original VHDX file to a Hyper-V generation 2 virtual machine.
- Boot the virtual machine from a Windows installation media or a Windows PE drive.
- Use Diskpart to create a FAT32 partition on the new VHDX file and assign it a drive letter.
- Use Robocopy to copy the contents of the EFI system partition from the physical disk to the new VHDX file.
- Use Bcdboot to create the boot files on the new VHDX file and update the boot configuration data (BCD) store.
- Use Bcdedit to modify the BCD store and set the correct device and osdevice values for the boot entry.
- Detach the new VHDX file and the original VHDX file from the virtual machine.
- Attach the new VHDX file as the first IDE disk and the original VHDX file as the second IDE disk to the target Hyper-V generation 2 virtual machine.
- Boot the target virtual machine from the new VHDX file and verify that the operating system loads correctly.
Step 1: Create a new VHDX file with the same size as the EFI system partition on the physical disk
On your technician PC, use Hyper-V Manager or PowerShell to create a new VHDX file with the same size as the EFI system partition on the physical disk. The EFI system partition is usually 100 MB or 260 MB, depending on the Windows version and the disk layout. You can check the size of the EFI system partition on the physical disk by using Disk Management or Diskpart. For example, if the EFI system partition is 100 MB, you can use the following PowerShell command to create a new VHDX file named EFI.vhdx with the same size:
New-VHD -Path C:\EFI.vhdx -SizeBytes 100MB -Dynamic
Step 2: Attach the new VHDX file and the original VHDX file to a Hyper-V generation 2 virtual machine
On your technician PC, use Hyper-V Manager or PowerShell to create a new Hyper-V generation 2 virtual machine with the desired characteristics. Then, attach the new VHDX file and the original VHDX file to the virtual machine as IDE disks. For example, you can use the following PowerShell commands to create a new virtual machine named VM1 and attach the VHDX files:
New-VM -Name VM1 -Generation 2 -MemoryStartupBytes 2GB
Add-VMHardDiskDrive -VMName VM1 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 0 -Path C:\EFI.vhdx
Add-VMHardDiskDrive -VMName VM1 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 1 -Path C:\windows.vhdx
Step 3: Boot the virtual machine from a Windows installation media or a Windows PE drive
On your technician PC, use Hyper-V Manager or PowerShell to connect a Windows installation media or a Windows PE drive to the virtual machine as a DVD drive. Then, start the virtual machine and press any key to boot from the DVD drive. For example, you can use the following PowerShell command to connect a Windows installation ISO file to the virtual machine:
Set-VMDvdDrive -VMName VM1 -Path C:\Windows.iso
Step 4: Use Diskpart to create a FAT32 partition on the new VHDX file and assign it a drive letter
On the virtual machine, when you see the Windows Setup screen, press Shift+F10 to open a Command Prompt window. Then, use Diskpart to create a FAT32 partition on the new VHDX file and assign it a drive letter. For example, you can use the following commands to create a FAT32 partition on disk 0 and assign it the letter S:
diskpart
select disk 0
clean
convert gpt
create partition efi size=100
format fs=fat32 quick label=EFI
assign letter=S
exit
Step 5: Use Robocopy to copy the contents of the EFI system partition from the physical disk to the new VHDX file
On the virtual machine, use Robocopy to copy the contents of the EFI system partition from the physical disk to the new VHDX file. You need to know the drive letter of the original VHDX file that contains the Windows system partition. You can use Diskpart or Disk Management to check the drive letter. For example, if the drive letter of the original VHDX file is C, you can use the following command to copy the contents of the EFI system partition from the physical disk to the new VHDX file:
robocopy C:\Windows\System32\Recovery S:\ /s /e
Step 6: Use Bcdboot to create the boot files on the new VHDX file and update the boot configuration data (BCD) store
On the virtual machine, use Bcdboot to create the boot files on the new VHDX file and update the boot configuration data (BCD) store. The BCD store is a database that contains the boot settings and options for Windows. Bcdboot copies the boot files from the Windows system partition to the EFI system partition and creates a new BCD store on the EFI system partition. You need to specify the Windows system partition and the EFI system partition as parameters. For example, if the drive letter of the original VHDX file is C and the drive letter of the new VHDX file is S, you can use the following command to create the boot files and update the BCD store:
bcdboot C:\Windows /s S: /f UEFI
Step 7: Use Bcdedit to modify the BCD store and set the correct device and osdevice values for the boot entry
On the virtual machine, use Bcdedit to modify the BCD store and set the correct device and osdevice values for the boot entry. The device and osdevice values specify the location of the boot loader and the operating system files. By default, Bcdboot sets these values to the drive letter of the Windows system partition, which is not correct for UEFI booting. You need to change these values to the partition identifier of the Windows system partition, which is a GUID that uniquely identifies the partition. You can use Diskpart to find the partition identifier of the Windows system partition. For example, if the drive letter of the original VHDX file is C, you can use the following commands to find the partition identifier:
diskpart
select disk 1
select partition 1
detail partition
exit
The output of the detail partition command will show the partition identifier, which is a string like {c12a7328-f81f-11d2-ba4b-00a0c93ec93b}. You need to copy this string and use it in the Bcdedit command. For example, if the partition identifier is {c12a7328-f81f-11d2-ba4b-00a0c93ec93b}, you can use the following command to modify the BCD store and set the correct device and osdevice values:
bcdedit /store S:\EFI\Microsoft\Boot\BCD /set {default} device partition={c12a7328-f81f-11d2-ba4b-00a0c93ec93b}
bcdedit /store S:\EFI\Microsoft\Boot\BCD /set {default} osdevice partition={c12a7328-f81f-11d2-ba4b-00a0c93ec93b}
Step 8: Detach the new VHDX file and the original VHDX file from the virtual machine
On your technician PC, use Hyper-V Manager or PowerShell to stop the virtual machine and detach the new VHDX file and the original VHDX file from the virtual machine. For example, you can use the following PowerShell commands to stop the virtual machine and detach the VHDX files:
Stop-VM -Name VM1
Remove-VMHardDiskDrive -VMName VM1 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 0
Remove-VMHardDiskDrive -VMName VM1 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 1
Step 9: Attach the new VHDX file as the first IDE disk and the original VHDX file as the second IDE disk to the target Hyper-V generation 2 virtual machine
On your technician PC, use Hyper-V Manager or PowerShell to attach the new VHDX file as the first IDE disk and the original VHDX file as the second IDE disk to the target Hyper-V generation 2 virtual machine. The target virtual machine is the one that you want to run the migrated Windows Server 2012 R2 Essentials operating system. For example, if the target virtual machine is named VM2, you can use the following PowerShell commands to attach the VHDX files:
Add-VMHardDiskDrive -VMName VM2 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 0 -Path C:\EFI.vhdx
Add-VMHardDiskDrive -VMName VM2 -ControllerType IDE -ControllerNumber 0 -ControllerLocation 1 -Path C:\windows.vhdx
Step 10: Boot the target virtual machine from the new VHDX file and verify that the operating system loads correctly
On your technician PC, use Hyper-V Manager or PowerShell to start the target virtual machine and boot from the new VHDX file. You should see the Windows Boot Manager menu with the option to boot Windows Server 2012 R2 Essentials. Select this option and verify that the operating system loads correctly. You might need to install the Hyper-V integration services and update the drivers for the virtual hardware. You might also need to activate the operating system and change the computer name and IP address.
Frequently Asked Questions (FAQs)
Question: What is the difference between VHD and VHDX?
Answer: VHD and VHDX are file formats for virtual hard disks. VHD is the older format that is compatible with Virtual PC and Hyper-V generation 1 virtual machines. VHDX is the newer format that supports larger disk sizes, data corruption protection, and performance improvements, but it is only compatible with Hyper-V generation 2 virtual machines.
Question: What is the difference between BIOS and UEFI?
Answer: BIOS and UEFI are firmware interfaces that initialize the hardware and boot the operating system. BIOS is the legacy interface that has been used for decades, but it has some limitations, such as 16-bit code, 1 MB address space, and MBR disk partitioning. UEFI is the modern interface that supports more advanced features, such as 64-bit code, larger address space, GPT disk partitioning, secure boot, faster boot time, and graphical user interface.
Question: What is the difference between MBR and GPT?
Answer: MBR and GPT are disk partitioning schemes that define how the disk space is divided into logical partitions. MBR is the older scheme that uses a master boot record at the beginning of the disk to store the partition table and the boot code. MBR can only support up to four primary partitions or three primary partitions and one extended partition, and each partition can be up to 2 TB in size. GPT is the newer scheme that uses a globally unique identifier partition table at the beginning and the end of the disk to store the partition information and a backup. GPT can support up to 128 primary partitions and each partition can be up to 18 EB in size.
Summary
In this article, we have shown you how to make a VHDX bootable in Hyper-V using Disk2vhd, a utility that creates VHD versions of physical disks for use in virtual machines. We have explained the steps to create a new VHDX file with the EFI system partition, copy the boot files from the physical disk to the new VHDX file, and modify the BCD store to point to the correct boot loader. We have also answered some frequently asked questions about the concepts and terms related to this topic. We hope this article has been helpful for you to migrate your physical server to a virtual machine on Hyper-V.
Disclaimer: This article is for informational purposes only and does not constitute professional advice. The author and the publisher are not liable for any damages or losses that may result from following the instructions or using the tools mentioned in this article. Always backup your data and test the procedures before applying them to your production environment.