I’ve titled this post as “Running Windows from a USB flash drive” because the same principles should be equally applicable to all Windows 7-based operating systems (and even Vista if the Windows 7 bootloader is used) but my specific scenario was based on Hyper-V Server 2008 R2.
I got this working a few hours after Windows 7, Server 2008 and Hyper-V Server 2008 R2 were released to manufacturing but I was still using release candidate code – fingers crossed it still works with the final release!
Boot from VHD is a fantastic new technology in Windows 7/Server 2008 R2 and derivative operating systems and I’ve often wondered if it’s possible to use it to run Hyper-V from a USB flash drive (just like the “embedded” version of VMware ESXi offered by some OEMs). Well, as it happens it is – and this post describes the steps I had to take to make it work.
First of all, I needed to create a virtual hard disk and install an operating system onto it. As Keith Combs noted, there are various ways to do this but only one is supported; however there is also a handy video on TechNet which takes you through the steps of creating a VHD and booting from it.
Using the TechNet video as a guide, I issued the following commands from the command prompt to create my virtual hard disk and apply an image from the Hyper-V Server 2008 R2 release candidate DVD:
diskpart
create vdisk file=driveletter:\virtualharddisk.vhd maximum=15000 type=expandable
select vdisk file=driveletter:\virtualharddisk.vhd
attach vdisk
list disk(make a note of the disk number.)
select disk disknumber
create partition primary
select partition 1
active
format fs=ntfs quick
assign
exit(note the drive letter for the newly mounted VHD.)
imagex /info dvddrive:\sources\install.wim(identify the correctentry.)
imagex /apply dvddrive:\sources\install.wim /check imageindex vhddrive:\
diskpart
select vdisk file=driveletter:\virtualharddisk.vhd
detach vdisk
exitAt this point, Hyper-V Server had been imaged into my new VHD, which could then be copied to the USB flash drive.
Next, to load the VHD from the Boot Manager, I edited the boot configuration data (which is what would be required in a standard boot from VHD scenario); however, as I found later, a different set of actions is needed for booting from the USB flash drive.
bcdedit /copy {current} /d "Hyper-V Server 2008 R2"
bcdedit(make a note of the GUID for the newly created entry.)
bcdedit /set {guid} device vhd=[usbdrive:]\virtualharddisk.vhd
bcdedit /set {guid} osdevice vhd=[usbdrive:]\virtualharddisk.vhd
bcdedit /set {guid} detecthal on
bcdedit /set {guid} description "Hyper-V Server 2008 R2"It’s worth understanding that the use of drive letters (which are transient in nature) does not cause a problem as the BCD Editor (bcdedit.exe) extracts the data about the partition and saves it in the BCD store (i.e. it does not actually save the drive letter).
After rebooting, Hyper-V Server loaded from my USB flash drive and ran through the out of box experience. At this stage I had Hyper-V Server running off the flash drive but only if my original Windows installation (with the boot manager) was available and, as soon as I removed the hard disk (I wanted to be sure that I was booting off the flash drive with no other dependencies), then the whole thing collapsed in a heap. Thanks to Garry Martin, I checked my BIOS configuration and made sure that USB device boots were enabled (they were not) but I then spent about a day playing around with various BCD configurations (as well as various attempts to fix my BCD with bootrec.exe) until I stumbled on a post from Vineet Sarda (not for the first time, based on the comments that include one from yours truly a few weeks back!) that discusses booting from VHD without a native operating system.
Following Vineet’s example, I booted my system into Windows 7 (I could have used the Windows Recovery Environment), reformatted the USB flash drive before copying my VHD image back onto it, and issued the following commands:
diskpart
select vdisk file=usbdrive:\virtualharddisk.vhd
attach vdisk
list volume
exit(note the drive letter for the newly mounted VHD.)
bcdboot vhddrive:\Windows /s usbdrive: /v(i.e. copying the BCD from the operating system image contained within the VHD, to the physical USB drive. Note that, when running on a live system it is important to specify the target drive for the BCD in order to avoid overwriting the live configuration.)
I then shut down the system, removed the hard disk and booted from the USB flash drive, after which the Windows Boot Manager loaded an operating system from within the VHD.
Looking at my BCD configuration (shown here for reference), I can see the source of my many hours of confusion – the Boot Manager resides on the physical media (my USB key – which was allocated drive D: in this case) and loads an operating system from the virtual disk that is given another drive letter (in this case C:):
Windows Boot Manager
——————–
identifier {bootmgr}
device partition=D:
description Windows Boot Manager
locale en-us
inherit {globalsettings}
default {current}
resumeobject {27f66313-771a-11de-90bb-00037ab36ab6}
displayorder {current}
toolsdisplayorder {memdiag}
timeout 30
Windows Boot Loader
-------------------
identifier {current}
device partition=C:
path \windows\system32\winload.exe
description Hyper-V Server 2008 R2
locale en-us
inherit {bootloadersettings}
osdevice partition=C:
systemroot \windows
resumeobject {27f66313-771a-11de-90bb-00037ab36ab6}
nx OptOut
detecthal Yes
It took a while to boot (my flash drive was a freebie is not the fastest in the world) but, once loaded into memory, Hyper-V Server seemed to run without any noticeable delay. I figure that, as long as the workload is stored on another disk this should not present any problems and, given suitably fast flash memory, it ought to be possible to improve boot times as well. Running a full Windows operating System (e.g. Windows 7) in this manner is an entirely different matter - very few USB flash drives will be able to stand the constant writes and further testing would be required.
Now that I have Hyper-V Server running from an inexpensive USB flash drive with no reliance on my PC's internal hard disk, all I need to do is inject the correct network drivers and I will have a virtualisation solution for colleagues who want to run a full hypervisor on their corporate notebooks, without deviating from the company's standard client build.
Additional information
The following notes/links may provide useful background information:
- Boot Configuration Data Editor Frequently Asked Questions on Microsoft TechNet.
- Note that the boot from VHD functionality in Windows 7/Windows Server 2008 R2 does not support the use of BitLocker or hibernation.

Technology
19 Comments
grrrr – bcdedit /set {guid} device vhd=[usbdrive]:\virtualharddisk.vhd throws an error.
The device is not valid…
Any ideas?
Hey Keni – good to hear from you!
Yes, it’s a typo I think – the : should be inside the [] (e.g. [c:]\virtualharddisk.vhd
I’ll go back and correct the original post.
The other thing that might make a difference is whether your USB drive is detected as an HDD or an FDD. Mine was picked up as USB 2.0 HDD but diskpart still sees it as a removable drive.
Arghhh! Now a Microsoft blog has publicised a free tool for doing all the heavy lifting! Pity I can’t get back all the time I spent on this last week :-(
Hallo,
I have used this excelent HowTo on preparing external USB HDD installation of Win 7 x64 RTM. Diskpart, imagex, bcdboot – everything without any reported problem. But – Win 7 is booting, doing BSOD and automatically rebooting (grrr, no time to read BSOD, stupid default setting in MS install image…). Again, Safe boot and the problem is loading System32\Disk.sys (Why System32 on x64??). Some delay and reboot…
Any idea, please?
@Anonymous – not sure what’s causing your BSOD but try mounting the VHD and looking for details in a folder called %SystemRoot%\Minidump. There are various tools that will help to analyse the dump but they tend to work on a running system… which doesn’t help you much.
Pingback: Hyper-V Server 2008 R2 ã® Flash Media Boot ã«ã¤ã„㦠- SE ã®é›‘記
Pingback: markwilson.it » Injecting network drivers into a Hyper-V Server (or Windows Server) installation
Mark, hope you don’t mind me asking, but I followed your guide, worked a treat (I used an old 40gb laptop disk, inside a bus powered drive enclosure, small and quite quick!). But I cant of been reading the download page properly (Microsoft), because I have ended up with RC code of Hyper-V R2. Can’t seem to find the download for it, although it is RTM`d I believe. We are not MSDN, just Action Pack if that makes a difference (although as it is free I don’t see why this is a problem).
Oh and I read your blog religiously, I know you dont make any money out of it, so I appreciate the effort you go to.
Hi Ian, thanks for your comments – I enjoy working on the projects like this one… keeps me from losing my technical skills!
You’re right that, even though Hyper-V Server 2008 R2 is now released, Microsoft is still only offering the RC on the website. If it’s like Windows 7 and Server 2008 R2 then they are drip feeding the new releases into different channels over a few weeks – it went onto MSDN/TechNet last week, and I think Volume License customers have it too now… I guess the public download will follow soon.
Mark
hmmm, weird i get the bsod as well.
It starts booting and then just bsod and reboots. Trying in safe mode it gets to disk.sys and then bsod’s.
Did anyone that has had this ever resolve it i wonder.
Thanks
Rob.
One of my colleagues was having trouble getting this working off a bootable USB HDD a few days back (BSODs) – I don’t know how he got on (i.e. if he resolved it) but the difference between that and what I did is that it’s a bootable HDD – i.e. not flash masquerading as a HDD.
I suspect the BSOD is because as control is switched from the Windows bootloader to Windows, it’s failing to find a driver for the USB-SATA bridge and failing. If you could locate the correct mass storage driver and inject that into your VHD then you might resolve the problem.
Note that this is just a suggestion, I have not confirmed it.
Just a follow up in case anyone is interested. Hyper-V r2 appears to have become available for the general “hoi polloi” to download.
http://www.microsoft.com/downloads/details.aspx?familyid=48359dd2-1c3d-4506-ae0a-232d0314ccf6
So, i will update my USB boot disk and start testing again.
Hey Mark,
Thanks for the great instructions! I followed them using a copy of Windows 7 Ultimate instead of Hyper-V, and found that it would not boot off USB. Windows would start loading, but it would BSOD and reboot. After a lot of searching I found a utility called PWBoot (http://www.boot-land.net/forums/index.php?showtopic=6851) that was originally written for Vista. The problem is that you must run PWBoot from in the OS itself.
I copied the VHD to an internal hard disk, added it to my local bootloader, and went through the OOBE. Once I was at the desktop I ran PWBoot, rebooted into my primary OS and copied the VHD back onto the USB drive. It worked like a charm! I now have a fully functional Native Windows 7 Ultimate VHD on my USB hard drive. Also note that this will only work with Enterprise and Ultimate. I initially tried it with Professional and it gave me a licensing error (Pro cannot run in a VHD).
Thanks again, and hopefully this information is helpful to someone!
Thanks fot that Lund, I too had the auto-reboot (no BSOD though) when starting the OOBE from a VHD image. Will try your suggestion of PWBoot.
Thanks for sharing
Microsoft’s Ben Amstrong has now posted his advice on booting Hyper-V 2008 R2 from USB, including reference to this tool that does a lot of the heavy lifting.
Pingback: markwilson.it » Windows native boot from VHD roundup
Hi I was wondering that you can show me how to load Windows server 2008 or V from a FLASHDRIVE. I didnt know that you can actually do that. Do you have to have a certain type of USB drive or….????Hope to hear from you soon.
Hey
I know this is an old post but I’ve just come across it now and wanted to say thank you.
Also, I can confirm that PWBoot does resolve the 0x7B BSOD error when launching the Win 7 VHD from a USB stick, as suggested by Lund. The tool itself has since been updated, so you don’t even need to boot to the VHD locally first – just attach the VHD (through diskpart or diskmgmt.msc) and point the tool at that drive. Works flawlessly.
~Adz