How to Boot HyperV From a USB Flash Drive

How to Boot HyperV From a USB Flash Drive

Help us continue creating free content like this…


This video shows how to install Hyper-V to USB flash storage, and use it as a boot drive


Mirror 1 (Faster): HyperV2USB
Mirror 2: HyperV2USB

Don’t forget to subscribe on YouTube

Step 1: Create a VHD
On your technician computer, 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. This virtual disk will appear as the R: drive at the end of this procedure. The detach command will stop this virtual disk from appearing on the host. For more information about the DiskPart tool, see the DiskPart Command Reference.
In this example, you create a 12 GB fixed-type VHD. This is the recommended size for a VHD being deployed on a 16 GB USB flash drive. Be sure to leave space available in the VHD for future updates; also, a minimum of 25% of the UFD storage space should by reserved for wear leveling.

Create and configure an empty .vhd file using the DiskPart tool. At a command prompt, type:

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 a Microsoft Hyper-V Server 2012 R2 image

Use the ImageX tool to apply the .wim file to the primary partition of the VHD. At a command prompt, type:

cd <path to folder containing HyperV2USB folder>
cd HyperV2VHD
imagex /apply <path to wim> 1 r:\ 

(ex. imagex /apply install.wim 1 r:\)

Use the DiskPart tool to detach the virtual disk from you technician computer after applying the image. At a command prompt, type:

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

Step 3: Prepare the UFD
Before you can place a Hyper-V VHD on a USB flash drive, you must format it as an NTFS drive.
On the technician computer running a Windows 7 or Windows Server 2008 R2 operating system, insert your USB flash drive.
Use the DiskPart tool to determine which disk number is assigned to the UFD. At a command prompt, type:

list disk 
Identify the UFD and note the disk number.
select disk <Flash Drive disk number>  
create partition primary  
select partition 1  
format quick fs=ntfs  
assign letter=z  

The UFD partition is now set as z:\. This partition letter will be used in examples below.

Step 4: Copy files to the Flash Drive
Copy the VHD to the USB flash drive, and update the boot code to be compatible with Windows Boot Manager (Bootmgr).

copy <file path><UFD partition letter> 
For example:
copy c:\hvvhd\hyperV.vhd z: 

Use the Bootsect tool to update the master boot code on the UFD to be compatible with Bootmgr.

Ensure you are still in the correct directory via the command prompt

bootsect /nt60 z: /force /mbr 

Create a BCD store on the UFD
Attach the VHD to the technician computer to create a boot configuration data (BCD) store on the root of the UFD.

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

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

For example:
bcdboot r:\windows /s z: 

Step 6: Disable paging
Paging may cause the flash device to wear out sooner. We recommend that paging be disabled prior to deploying the UFD.
Microsoft Hyper-V Server 2012 R2 should be configured with paging disabled during the imaging process, if it will be installed onto a flash storage device rather than a traditional hard disk drive (HDD). Disabling paging can greatly reduce wear to the flash device, and extend the useful lifetime of the system. By default, paging is enabled on Microsoft Hyper-V Server 2008 R2, so it must be explicitly disabled if it is deployed onto a flash device.

Load the registry hive of the attached VHD on the USB flash drive into a temporary hive on the host system. At a command prompt, type:

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

Clear the Paging Files value in the registry. At a command prompt, type:

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

Delete the existing Page Files entry. At a command prompt, type:

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

Unload the temporary registry hive. At a command prompt, type:

reg unload HKLM\HyperVTemp 

Detach the VHD
The UFD can now be detached from the technician computer and deployed to a host server.

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