Jump to content

How to Native Boot to VHD of Hyper-V Virtual Machine


Sylence

Recommended Posts

First a quote from Microsoft Developer Network's (MSDN) support article:

 

Quote

Native Boot allows you to create a virtual hard disk (VHD), install Windows to it, and then boot it up, either on your PC side-by-side with your existing installation, or on a new device.

A native-boot VHD can be used as the running operating system on designated hardware without any other parent operating system. This differs from a scenario where a VHD is connected to a virtual machine on a computer that has a parent operating system.

VHDs can be applied to PCs or devices that have no other installations of Windows, without a virtual machine or hypervisor. (A hypervisor is a layer of software under the operating system that runs virtual computers.) This enables greater flexibility in workload distribution because a single set of tools can be used to manage images for virtual machines and designated hardware.

You can also deploy the VHD to a PC that already has Windows installed on it, and use a boot menu to select between the existing version of Windows, or the version on the VHD.

 

 

As you most probably already use Hyper-V and have a version or two of Windows installed on its virtual machines (judging by the fact that you found here), we can use a shortcut simplifying the process and use already existing VHD files of your Windows virtual machines.

There's nothing wrong in running your Windows virtual machines as intended in Hyper-V. However, sometimes you might want unrestricted access to physical hardware on your host machine. Native boot gives you exactly that: when a VHD with Windows installed on it is used for native boot in a dual / multiple boot scenario, it will no longer use Hyper-V emulated, virtualized hardware devices but is instead as any operating system installed directly to physical hardware.

In this tutorial we will add a Windows 10 Pro virtual machine's virtual hard disk file to my Windows 10 boot menu, to be able to choose which of the two Windows systems will be started when the machine will be booted. 

The tutorial might look a bit complicated but I assure you, this is really easy and fast. You set up your virtual machine's VHD for native boot in a minute :).

 

 

 

Notice that you can use the method told in this tutorial on both BIOS (MBR) and UEFI (GPT) systems, mounting both MBR partitioned Generation 1 VHD files and GPT partitioned Generation 2 VHD files regardless if the host is MBR or GPT partitioned.
A VHD from Generation 2 UEFI vm can boot natively on a BIOS (MBR) host, and a VHD from Generation 1 BIOS vm boots without an issue on UEFI (GPT) host.
This method can be used to natively boot VHD files from Hyper-V virtual machines running Windows 8.1, Windows 10, Windows Server 2012 R2 or Windows Server 2016.

 

 

 

Part One

 Preparations

 

A Hyper-V virtual machine when created and before any checkpoints have been made consists of one VHD or VHDX file, a Virtual Hard Disk file. Later on when you for security or other purposes make checkpoints, Hyper-V adds a so called child VHD to the vm. As geeks love difficult words, we say this vm is from now on using differencing disk. It means that we have a base disk (also called parent disk), in Hyper-V usually a .vhdx file, and for that base a child disk with extension .avhdx, letter A coming from word automatic meaning it is managed automatically by Hyper-V without user interaction. In other words, keep your hands away, don't move, rename or delete them manually, only use Hyper-V Manager for any changes.

Here's a screenshot of a typical Hyper-V vm (#1) and its checkpoints (#2), I have also pasted an extract from my virtual hard disk folder into this screenshot (#3):

 

Click image for larger version. 

Name:	2016_06_16_19_37_371.png 
Views:	573 
Size:	140.3 KB 
ID:	85427
 
I created the vm and installed Windows in a .vhdx file (yellow highlight). When I made first checkpoint, the differencing data was stored in first .avhdx file (blue highlight), next checkpoint created again a differencing .avhdx to store changes since first checkpoint and so on.

To get our vm to boot natively outside Hyper-V, we need to merge existing checkpoints (child disks) to base disk (parent). Native boot with a VHD or VHDX file is only possible if it has no child disks. Unfortunately this also means that when you remove the VHD or VHDX from native boot menu and continue using it in Hyper-V, you no longer have any checkpoints and can't restore the vm to earlier state.

Think how important your checkpoints are, you wont get them back once deleted and merged to parent!



1.1) If the vm you want to use in native boot has any checkpoints, select the first checkpoint, right click and select Delete Checkpoint Subtree to remove all checkpoints. Hyper-V merges the data they contain to base disk and finally removes the child disks:

 


Click image for larger version. 

Name:	2016_06_16_19_56_462.png 
Views:	385 
Size:	98.6 KB 
ID:	85428


1.2) You can leave the .vhd or .vhdx file in its current location, or copy it to another drive. You can even copy the virtual hard disk to another computer and use it on that computer for native boot. If your intention is to continue using it also in Hyper-V in addition to native boot, leave it where it is

1.3) Download and install the free Macrium Reflect. Although mostly known of its disk imaging and cloning capabilities, Macrium also offers the easiest way to fix Windows boot records. We will use it later in Part Four to reset Windows boot records and boot menu

Macrium Reflect Free download: Macrium Reflect Free

 

 

 

 

 Part Two 

 Add VHD to boot menu



2.1) Open your virtual hard disks folder, default location if you have not changed it in Hyper-V settings is C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks

2.2) Double click the VHD file you want to boot natively and add to boot menu. This mounts the VHD on your host system. In this example I have copied the virtual hard disk to another computer and double click it to mount it to the host system:

 

 

Name:  2016_06_16_20_38_031.png
Views: 15678
Size:  26.9 KB

 

 

2.4) Windows now mounts all partitions of this disk to host. Because the Hyper-V vm on this disk was setup as Generation 1 (BIOS / MBR partitioning), my host now shows two new drives, drive G: which is the system reserved partition of Windows 10 installation on that virtual hard disk, and drive H: which is the Windows partition of that installation:

 

 

Click image for larger version. 

Name:	2016_06_16_20_42_562.png 
Views:	372 
Size:	69.4 KB 
ID:	85432
 

 

Notice that the VHD will be automatically unmounted when we restart in step 2.9; it only needs to be mounted now to be added to boot menu, later on there's no need to mount it.

2.5) Old school geek as I am, I always need to check. I open drive H: to see it really contains the virtual Windows 10 installation I want to use in native boot:

 

Name:  2016_06_16_20_44_303.png
Views: 13651
Size:  28.3 KB
 

 

2.6) Open an elevated (admin) Command Prompt, type bcdboot H:\Windows and press Enter (replace drive letter H with actual drive letter for the mounted virtual hard disk containing Windows):

 

Name:  2016_06_16_20_51_171.png
Views: 15685
Size:  16.8 KB
 

 

2.7)  To prepare for the unexpected, to easily restore the default boot records let's not continue before we have added Macrium Rescue WinPE system to the boot menu. Start Macrium Reflect, open Other tasks menu, select Add Recovery Boot Menu Option:

 

 

Name:  2016_06_16_20_58_481.png
Views: 15703
Size:  42.7 KB
 

2.8) Select Windows PE 10.0 menu and click OK, accept all possible prompts:

 

Name:  2016_06_16_21_04_522.png
Views: 15810
Size:  29.2 KB
 

2.9) Restart Windows. You will be shown the Windows 10 boot menu

 

Click image for larger version. 

Name:	2016_06_16_21_19_533.png 
Views:	780 
Size:	99.7 KB 
ID:	85440
 
Optional:

Click image for larger version. 

Name:	2016_06_16_21_21_174.png 
Views:	443 
Size:	85.5 KB 
ID:	85441
Click image for larger version. 

Name:	2016_06_16_21_22_455.png 
Views:	447 
Size:	77.2 KB 
ID:	85443
 

2.10) The physical PC, a laptop in this case has now been booted with a virtual hard disk from a Hyper-V virtual machine. It now uses the physical hardware and can access all host machine resources. Our virtual Windows is now physical (blue highlighted disk), with access to original host Windows hard disks (yellow):

 

Click image for larger version. 

Name:	2016_06_16_21_39_536.png 
Views:	337 
Size:	357.2 KB 
ID:	85445
 

2.11) If we check Disk Management we will see that the VHD was added as last hard disk, in this case Disk 3. Checking its properties we can clearly see that we are dealing with a virtual disk:

 

Click image for larger version. 

Name:	2016_06_16_21_44_347.png 
Views:	476 
Size:	181.4 KB 
ID:	85447
 

OK, let's boot back to host, the original Windows installation by restarting and selecting it from boot menu

2.12) For your own comfort it might be a good idea to rename boot menu operating systems, the boot menu showing two identical "Windows 10" entries can be confusing. To do that open an elevated (admin) Command Prompt, type bcdedit and hit Enter.

Boot records will be shown. Scrolling down the list you will find an entry titled Windows Boot Loader for each of our three operating systems. We are interested in three details on each entry: Identifier (yellow highlight in below screenshot), Device (blue) and Description (green):

 

Click image for larger version. 

Name:	2016_06_16_22_08_261.png 
Views:	530 
Size:	85.7 KB 
ID:	85454


2.13) As we have two identical "Windows 10" entries, lets change the VHD entry's name to something more descriptive. Checking the Device type in all three entries we can see that our VHD's Identifier is {default}.

The command syntax to change the boot menu description is bcdedit /set {Identifier} description "AnyName". In this example I changed its name to My VHD with command bcdedit /set {default} description "My VHD":

Click image for larger version. 

Name:	2016_06_16_22_26_051.png 
Views:	420 
Size:	85.8 KB 
ID:	85456



Looking better, easier to understand which entry starts what OS:

 

Click image for larger version. 

Name:	2016_06_16_22_29_082.png 
Views:	381 
Size:	48.6 KB 
ID:	85457
 
 
 
 
Part Three
 Remove VHD from boot menu
 
 

3.1) I played with another VHD, this time Windows 8.1 but would like to remove it now from boot menu:

 

Click image for larger version. 

Name:	2016_06_16_22_55_421.png 
Views:	512 
Size:	59.1 KB 
ID:	85460
 

3.2) Open elevated (admin) Command Prompt, type bcdedit and hit Enter, browse to Windows Boot Loader entry you want to remove, note the identifier (Windows 8.1 VHD identifier highlighted):

 

Name:  2016_06_16_23_14_211.png
Views: 15729
Size:  29.1 KB
 

3.3) Type bcdedit /delete {Identifier}, hit Enter to remove the VHD from boot menu:

 

Name:  2016_06_16_23_28_021.png
Views: 13735
Size:  10.0 KB
 
Note   Note
There are three different identifiers: The chosen default OS has identifier {default}, the current OS you are signed in at the moment is {current}. All other entries have a long hexadecimal identifier, as in this example the Windows 8.1 VHD identifier above. 

Typing these long hexadecimal strings is both boring and also might easily be typed wrong. In Command Prompt you can just select the string with mouse and hit Enter to copy it to Clipboard, then paste it to your command.
 
 
 
 
 
Part Four
Troubeshooting, reset boot menu
 

4.1) Anything can happen. A restart can suddenly show this when you select an OS from boot menu (in screenshots current Windows 10 recovery prompt and old style legacy prompt which can be shown depending on if you have manually changed to legacy boot menu, or added Windows 7 or older OS on multi boot system):

 

 
 
Click image for larger version. 

Name:	image.png 
Views:	312 
Size:	213.1 KB 
ID:	136141

Click image for larger version. 

Name:	2016_06_16_23_34_261.png 
Views:	536 
Size:	32.1 KB 
ID:	85471
 

 

This does not happen often but when it happens you might be unable to boot to any of the installed operating systems except Macrium WinPE rescue system which we added to boot menu in steps 2.7 and 2.8.

In modern prompt, press F9 to open boot menu. In old style prompt press Enter. You can now select another operating system from menu, or use Macrium to fix boot records as told below (if you did not add Macrium to Windows Boot Menu, restart your PC now booting from Macrium boot disk / USB and continue from 4.3).

4.2) Select Macrium Reflect System Recovery and hit Enter:

 

 

Click image for larger version. 

Name:	image.png 
Views:	750 
Size:	271.7 KB 
ID:	136140

Click image for larger version. 

Name:	2016_06_16_23_49_012.png 
Views:	405 
Size:	29.9 KB 
ID:	85478
 

 

 

4.3) When Macrium has started, select Fix Windows boot problems top left:

 

 

Name:  2016_06_16_23_52_163.png
Views: 16252
Size:  33.3 KB
(Screenshot from a BIOS system, process exactly the same in UEFI.)
 

 

4.4) Click Next:

 

Name:  2016_06_16_23_53_044.png
Views: 15759
Size:  30.7 KB
 

 

4.5) Click Next:

 

Name:  2016_06_16_23_54_156.png
Views: 15714
Size:  32.3 KB
 

 

4.6) Click Finish:

 

 

Name:  2016_06_16_23_55_017.png
Views: 15810
Size:  32.7 KB
 

 

4.7) Click Yes:

 

 

Name:  2016_06_16_23_55_528.png
Views: 15719
Size:  9.5 KB

 

4.8) Windows boot records have been reset, your original physical Windows 10 installation will start, no boot menu is shown.

To continue playing with native boot you have to add your VHD files again as well as the Macrium rescue boot option as told in Part Two.
 

 

Note   Note
When boot records have been reset with Macrium as told in Part Four above, your Hyper-V virtual machines might not start telling you that one of the Hyper-V components is not running:
Name:  2016_07_02_11_18_511.png
Views: 15481
Size:  32.3 KB

By reseting boot records Macrium has caused the hypervisor not to work properly. Luckily this is not an issue, we can fix it easily. Simply give this command in an elevated Command Prompt and restart your Hyper-V host PC:
 
Code:
bcdedit /set hypervisorlaunchtype auto

Hyper-V virtual machines will again run without issues.
 
information   Information
You can naturally also reset your boot records whenever you want to, when you no longer want to boot to your VHD files. 

Notice that you can update Windows on the natively booted VHD normally, install software, do everything else but you cannot upgrade it to next builds:
Name:  2016_06_18_02_31_291.png
Views: 15583
Size:  24.1 KB
 
When / if you want to upgrade, boot to your original host OS, run the VM in Hyper-V and upgrade. When done you can again boot to it using the method told in this tutorial.

 
 
 
Link to comment
Share on other sites


  • Replies 2
  • Views 1.3k
  • Created
  • Last Reply

With this method you can install countless OSes in a single partition without them conflicting with each other. you can also hot switch between each of them if you use Bare Metal version of Hyper-V which is called Hyper-V server, preferably version 2016 or 2019. 

Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...