How to Boot Hyper-V From a USB Flash Drive

How to Boot Hyper-V From a USB Flash Drive

This guide demonstrates how to install Microsoft Hyper-V to USB flash storage and use it as a boot drive.

Note: The download linked at the bottom of this page includes Hyper-V 2012, however this same method will also work for Hyper-V 2019. To use Hyper-V 2019 instead, you will need to download it seperately and overwrite the Hyper-V 2012 image (install.wim) found in the HyperV2USB download used in this guide.

Before You Begin

  1. Download the HyperV2USB package.
  2. Extract the HyperV2USB compressed archive
  3. Note the location of the extracted contents (you will need to navigate here from the command prompt)

Step 1 – Create a VHD

Create a directory for your VHD, and then use the DiskPart tool to create, attach, partition, and format a new virtual hard disk. You can attach a VHD by using the attach vdisk command, which adds the .vhd file as a disk to the storage controller on the host computer.

In this example, a 12 GB fixed-type VHD will be created, which is the recommended size for a VHD being deployed on a 16 GB USB flash drive. The letter “R” will be assigned to the primary partition created on the new VHD.

TIP: A minimum of 25% of the USB flash drive storage space should be reserved for wear leveling.

To create and configure an empty .vhd file using the DiskPart tool, open the command prompt and type the following:

mkdir c:\hvvhd 
create vdisk file=c:\hvvhd\hyperV.vhd maximum=12288 type=fixed
select vdisk file=c:\hvvhd\hyperV.vhd  
attach vdisk  
create partition primary  
assign letter=r  
format quick fs=ntfs label=hyperV  

Step 2 – Apply the Microsoft Hyper-V Image

Ensure you have exited DiskPart, then Navigate to the folder containing the extracted contents of the HyperV2USB download.
* If you want to use Hyper-V 2019 instead, now would be the time to overwrite the Hyper-V 2012 image (install.wim) with the 2019 image. As mentioned earlier, you will need to download Hyper-V 2019 seperately.

cd <path to folder containing HyperV2USB folder>
cd HyperV2VHD

Next, the Hyper-V image needs to be applied to the VHD using the ImageX tool.

imagex /apply <image file> 1 r:\ 

imagex /apply install.wim 1 r:\

Use the DiskPart tool to detach the virtual disk after applying the image.

select vdisk file=c:\hvvhd\hyperV.vhd  
detach vdisk  

Step 3 – Prepare the USB Flash Drive

Before you can place the Hyper-V VHD on a USB flash drive, you must format it as an NTFS drive.

Insert the USB flash drive and use the DiskPart tool to determine which disk number is assigned to it.

list disk 

Identify the disk number assigned to the USB flash drive and type the following within DiskPart.

select disk <flash drive disk number>  
create partition primary  
select partition 1  
format quick fs=ntfs  
assign letter=z  

In this example, the USB flash drive partition is now set as “z:”, which will be used throughout the rest of this guide.

Step 4 – Copy the VHD to the USB Flash Drive and Update the Master Boot Code

Next, the VHD needs to be copied to the USB flash drive. Ensure you have exited DiskPart, then type the following in the command prompt:

copy <VHD path\filename> <USB flash drive partition letter>

copy c:\hvvhd\hyperV.vhd z: 

Upon completion of copying the VHD to the flash drive, use the Bootsect tool to update the master boot code on the USB flash drive to be compatible with Bootmgr.

Ensure you are still in the correct directory in the command prompt, then type the following:

bootsect /nt60 z: /force /mbr 

Step 5 – Create a BCD store on the USB Flash Drive

Using DiskPart, attach the VHD that was just copied to the USB flash drive, then create a boot configuration data (BCD) store on the root of the flash drive.

select vdisk file=z:\HyperV.vhd  
attach vdisk

bcdboot <VHD Partition Letter>\windows /s <USB Partition Letter> 

bcdboot r:\windows /s z: 

Step 6 – Disable Paging

Paging may cause the flash device to wear out sooner. It is recommended that paging be disabled prior to deploying the USB flash drive. Disabling paging can greatly reduce wear to the flash device, and extend the useful lifetime of the system.

By default, paging is enabled, so it must be explicitly disabled if it is deployed onto a flash device.

Ensure you have exited DiskPart; at the command prompt, type the following:

reg load HKLM\HyperVTemp r:\windows\system32\config\system 

*Loads Registry Hive

reg add “HKLM\HyperVTemp\ControlSet001\Control\Session Manager\Memory Management” /v PagingFiles /t REG_MULTI_SZ /d “” /f  

*Clears paging file value

reg delete “HKLM\HyperVTemp\ControlSet001\Control\Session Manager\Memory Management” /v ExistingPageFiles /f  

*Deletes ExistingPageFiles entry

reg unload HKLM\HyperVTemp

*Unloads Registry Hive

Step 7 – Detach the VHD

select vdisk file=z:\hyperV.vhd  
detach vdisk  

The USB flash drive can now be removed from the computer and deployed to a server.

Mirror 1 (Faster): HyperV2USB
Mirror 2: HyperV2USB

Did you find this page helpful?

PID: 20190130-00001