Native boot from VHD on a Windows XP computer

This content is 14 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

Guest PostLike almost every other corporate in the world, where Mark and I work there is a standard build deployed to everyone. The default in our particular organisation is a 32-bit Windows XP OS regardless of the capabilities of the laptop or desktop it is deployed to. Over the years, this has caused a number of problems that have required an increasing number of “exemptions” from standard policy to allow people to run a different Windows version or platform.

Whilst this hasn’t been too much of a problem for the majority of the Architects that Mark and I work with – after all, we’re fairly self-sufficient when it comes to supporting our environments and are infinitely capable of collectively dreaming up ever more creative workarounds for the things that don’t work – it isn’t a solution that’s manageable at scale.

Then, along came Windows 7 and Windows Server 2008 R2 and with them came the introduction of a great new feature – Native Boot from VHD. With a little configuration, this has enabled us to leave the existing Windows XP corporate build in place, and to deploy a 32-bit or 64-bit Windows 7 (Enterprise or Ultimate) or 64-bit Windows Server 2008 R2 build side-by-side, crucially without having to make any changes to the Windows XP build or the existing disk partitioning scheme.

To achieve this, we created a new Windows 7 or Windows Server 2008 R2 bootloader, and “chained” the original Windows XP bootloader from it. At boot, this allows us to select a Native Boot from VHD into, for example, a 64-bit Windows Server 2008 R2 Enterprise build, or to select the chained bootloader which allows us to boot into the corporate Windows XP build.

Of course, you’ll need to create your VHD-contained Windows 7 or Windows Server 2008 R2 OS build and put it to your local disk, and this post doesn’t go into that detail, but once you have done that, the steps below will allow you to create a new bootloader and chain your existing Windows XP corporate build from it.

To begin, boot your computer using your Windows 7 or Windows Server 2008 R2 installation media.

When you reach the Install Windows screen, select your preferences in the Language to installTime and currency format, and Keyboard or input method boxes, and then click Next.

Do not click Install now. Instead, click Repair your computer.

The search for supported operating systems will fail, and the System Recovery Options dialog box appears with the Restore your computer using a system image that you created earlier option selected. Click Next.

The Re-image your computer tool will fail to find a system image and will display a dialog informing you of this. Click Cancel on the dialog, and then Cancel again on the main tool window.

The System Recovery Options menu appears. Click Command Prompt.

To write the new Windows 7 or Windows Server 2008 R2 bootloader:

BOOTSECT /NT60 C: /FORCE /MBR

To create a BCD store from the Windows VHD:

DISKPART
SELECT VDISK FILE=C:\BOOTVHDS\W2K8R2ENTX64.VHD
ATTACH VDISK
ASSIGN LETTER=X
EXIT
BCDBOOT X:\WINDOWS /S C:

Set up the VHD native boot:

BCDEDIT /SET {default} DEVICE VHD=[LOCATE]\BOOTVHDS\W2K8R2ENTX64.VHD
BCDEDIT /SET {default} OSDEVICE VHD=[LOCATE]\BOOTVHDS\W2K8R2ENTX64.VHD
BCDEDIT /SET {default} DETECTHAL ON

Set up the legacy boot:

BCDEDIT /CREATE {ntldr} /d "Chain Legacy Bootloader"
BCDEDIT /SET {ntldr} DEVICE PARTITION=C:
BCDEDIT /SET {ntldr} PATH \ntldr
BCDEDIT /DISPLAYORDER {ntldr} -ADDLAST

To put things back to normal, should you ever need to:

BOOTSECT /NT52 C: /FORCE /MBR

48 thoughts on “Native boot from VHD on a Windows XP computer

  1. Were all the steps before the command prompt just for getting to the command prompt? If so you know the key combination CTRL+F10 summons a command prompt anytime during Windows Setup.

    Err… or it could be ALT+F10 or SHIFT+F10. Not 100% positive, but it’s one of those. This has worked since Vista’s Windows Setup.

  2. Good catch Dan. I actually use a Windows PE boot disk but was conscious that not everyone would have access to one of those, so I checked the Microsoft website for official instructions to get to the Command Prompt. You are of course correct that hitting Shift+F10 at the initial install screen will also take you to the same place and save some time.

  3. i couldn’t get past “ASSIGN LETTER=X” it keeps giving me an error saying “NO VOLUME SELECTED”

    any thoughts?

  4. trialUnplugged – after you’ve used ATTACH VDISK try LIST VOLUME to see what volumes are available. Can you see anything that looks like it would be your VHD file?

  5. @trialUnplugged – it sounds as though the VHD failed to mount for you – try list volume and see which volumes are available then select volume volumenumber to select it, then you should be able to continue with the drive letter assignment.

  6. Great! I got it to work! Thanks for the feedback, guys! I’m typing from a new win7 vhd within a winxp partition!

    You guys rock!

  7. Thanks for the blog! Since you installed this on your work laptop, could you tell me whether it was easy to remove? Is there a way to only have the boot menu show up if you press a certain key during bootup so that if a technician reboots my machine they don’t see it and blame me?

  8. Hi Piere, it is very easy to remove, just use the last command in the post and this reverts back to the standard NLTDR. There is no way to stop it appearing in the boot menu though.

  9. @Alexey – I don’t believe that VHD boot is supported from a network share; however, based on a conversation I had with Garry (and as yet untested), you might be able to use the VHD as an iSCSI target and, if your network hardware supports it, boot from that.

  10. When try boot Win 7 vhd on xp machine after selecting windows 7 from boot menu it starts show start windows 7 and after 2 second bloue dump error comes and it restarts. VT is enabled.System coniguration : 2gb RAM , 75 gb hdd, 2 partitions c=20gb and d=remaining.
    Please help Urgent.

  11. @varun – you shouldn’t need Intel VT for this – the disk is virtualised, not the operating system instance. If you’re getting a BSOD, what does it say? Chances are it’s unsupported storage (SATA drivers), or HAL (non-ACPI).

  12. Hi,

    I am unable to boot Windows 7 vhd on windows xp as base machine.After booting the system i get boot menu where windows 7 and windows xp are shown.After selecting Win7 vhd ‘Start windows’ screen comes and shows blue dump error.

    I have created VHD using Microsoft VPC 2007.
    System configuration : Base OS Windows xp , 1 gb RAM, 74 GB HDD.

  13. @varun – if you mount the .VHD file, you can find the dump file (typically C:\Windows\memory.dmp, or one of the files in C:\Windows\Minidump); however your other comment gives me a clue. You can’t just take a VM from Virtual PC and native boot to it. You either need to sysprep it, or create a new VHD and apply the OS image to it. Check out my Running Windows from a USB flash drive and Windows native boot from VHD roundup posts for details – or watch this video.

  14. @varun – booting a VHD created using Virtual PC won’t work unless you use SYSPREP first. Launch your VHD in Virtual PC, then run C:\Windows\System32\Sysprep\Sysprep.exe and select the check box for [b]Generalize[/b] and then select [b]Shutdown[/b] from the [b]Shutdown Options[/b] drop down box.

  15. 1. annot get pass the “ASSIGN LETTER=X” it keeps giving me an error saying “NO VOLUME SELECTED” And also in command prompt if you look above my CMD dir is Administrator: X:\windows\system32\cmd.exe so I cannot use X: since its already in use.

    2. Do I need to already have XP installed on the computer for this to work? Right now I have an empty hard drive that is clean. Can someone please HELP soon…

    3. Also the above command BCDBOOT X:\WINDOWS /S C: how can change that so it can work on my box since I cannot assign X: because its already taken. And even after creating a .vhd the volume remains the same 149GB. (still only one volume but another disk that says unallocated space which is my .vhd) I can’t name a disk or can?

  16. @Jay – did you select the vdisk? Not having selected a disk would produce the error you mention in point 1. Also, if X: is in use, you can use another letter. Re: point 2, yes, this post assumes you want to use the Windows 7 native boot from VHD on a Windows XP computer – if you have a blank hard disk, then go ahead and install Windows 7.

  17. Thanks for replying me so quickly. I had windows 7 installed but I can do it again. Are you aware that windows 7 creates a second “system partition? In this command, “BCDBOOT X:\WINDOWS /S C:” is X: the vdisk? what is C:? Knowing what they refer will help me write that command better since my letters are somewhat different.

    2. Now just to make sure what I’m trying to do is the same with what you are teaching, let me share my issue with you. XP loses support in 2014 or 2018 I think. My corporation wants a dual boot setup where your primary boot partition is Windows 7 and your vdisk is xp. Not sure if that is possible? I’m assuming that’s what this blog addresses.

  18. And also when I follow the same command BCDBOOT X:\WINDOWS /S C: (X being the vdisk right? and C: being the root C: that windows 7 uses right? My vdisk is E: so I do the command BCDBOOT E:\WINDOWS /S C: and I get an error saying “Failure when attempting to copy boot fles”

  19. Ok I finally got ALL the steps to work. Thanks Mark. You can neglect the other question but PLEASE I NEED HELP WITH THIS QUESTION… Now how do I install Windows XP on that vdisk that I created?

  20. @Jay – glad you got this to work; however it sounds as though this isn’t the right solution for you. This is about booting Windows 7 from a virtual hard disk on a Windows XP computer – which would give you a dual boot scenario but not what you describe.

    You might find James Bannan’s article on dual-booting Windows XP and Windows 7 more useful – alternatively, if you install Windows Virtual PC on a Windows 7 machine, you can run Windows XP in a virtual machine.

  21. I have the same issue trialUnplugged but am unable to resolve it; I am able to confirm I’ve successfully selected and attache my vdisk file, but get the error message:

    “There is no volume specified.
    Please select a volume and try again.”

    When I LIST VOLUME all it shows are my DVD (Volume 0), and HD (Volume 1)…

  22. @waika – if the list volume doesn’t show your vdisk (only the hard disk and the DVD), then you didn’t attach it correctly. Please check that you have issued all the commands correctly.

  23. Hi Mark, thank you for your reply, I appreciate it! I did ATTACH VDISK correctly as I get a confirmation to that effect and the Windows installer sees it; but LIST VOLUME does not, and I’m not able to ASSIGN it a drive letter…

    What’s odd is I went ahead and installed Windows 7 and it all worked just fine without even ASSIGN-ing a drive letter; perhaps it’s because I’m doing this on Sever 2003 (SP2 sans R2), but both entires are in the boot menu, and both operating systems load correctly…

    Odd huh?

  24. @Waika – from what you describe, it sounds like you are just dual-booting Windows 7 and Windows Server 2003 R2 – not running Windows 7 booting from within the .VHD.

  25. No, Windows 7 is installed in the vhd, the only thing directly installed on the primary partition is Server 2003 SP2… I’ve done this before with Vista and Server 2008, and similar for over a decade with Linux via UMSDOS and loop-back root file systems so I’m not blowing smoke up your ass, and do know what I’m saying and doing… It appears there’s some undocumented behavior with respect to Server 2003…

  26. I can’t get past “Diskpart”. When I do the “Select vdisk file=path to vhd” command, Diskpart says an error has occurred and it can’t find the .vhd. Do I have to select the physical disk that the .vhd is on, first, with some command??

  27. @tony You only need to use the full path to the vhd, e.g. “select vdisk file=c:\boot\test.vhd”. What is the error message? Are you definitely using Windows 7 or Windows Server 2008 R2 boot media?

  28. Garry
    I finally got it all working, however I added a few points that newbies might find helpful. You can read through and see the expanded detail.

    1) Copy .vhd file to your boot c:

    2) Power down computer and disconnect all bootable hard drives except the above one you copied the .vhd file to (pull data cables).

    3) Boot your computer using your Windows 7 or Windows Server 2008 R2 installation media. When you reach the Install Windows screen, Press Shift F10 to get a command prompt.

    4) Check and see if your .vhd file is now on the c: by doing –> c:, dir (at the command prompt). If yes, continue, if no, all bootable HDs are not disconnected. Power down and disconnect then reboot with Win7 DVD.

    5) To write the new Windows 7 or Windows Server 2008 R2 bootloader:

    BOOTSECT /NT60 C: /FORCE /MBR

    To create a BCD store from the Windows VHD:

    DISKPART
    SELECT VDISK FILE=C:\VHD_Folder\Win7.VHD
    ATTACH VDISK
    LIST VOLUME (to get drive letter of .vhd mounted file. Use this letter in place of the X in the below BCDBOOT command).
    EXIT
    BCDBOOT X:\WINDOWS /S C:

    Set up the VHD native boot:

    BCDEDIT /SET {default} DEVICE VHD=[C:]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} OSDEVICE VHD=[C:]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} DETECTHAL ON
    BCDEDIT (to verify the above got added to boot list)

    Set up the legacy boot:

    BCDEDIT /CREATE {ntldr} /d “Chain Legacy Bootloader”
    BCDEDIT /SET {ntldr} DEVICE PARTITION=C:
    BCDEDIT /SET {ntldr} PATH \ntldr
    BCDEDIT /DISPLAYORDER {ntldr} -ADDLAST
    BCDEDIT (to verify the above got added to boot list)

    To put things back to normal, should you ever need to:

    BOOTSECT /NT52 C: /FORCE /MBR

    Notes – the command “ASSIGN LETTER=X” is not needed because the “Attach vdisk” command mounts and assigns a drive letter. The “dir” command verifies this as shown in the procedure.

    I had to disconnect all bootable hard drives to get this to work. When I booted with the Win7 disk, at the command prompt I would see my bootable drive listed as d:, not c:. I tried entering d: in the commands but it did not take for some reason… so I just disconnected all other drives and it then worked.

  29. Whoops, a couple of errors in my “Notes”

    Notes – the command “ASSIGN LETTER=X” is not needed because the “Attach vdisk” command mounts and assigns a drive letter. The “List Volume” command verifies this as shown in the procedure.

    I had to disconnect all bootable hard drives, EXCEPT THE ONE I WANT TO USE, to get this to work. When I booted with the Win7 disk, at the command prompt I would see my bootable drive listed as d:, not c:. I tried entering d: in the commands but it did not take for some reason… so I just disconnected all other drives and it then worked.

  30. Now I’m trying to make an image of this partition and copy it to an esata drive so I can boot into either XP or 7 from there in an emergency. I used drive snapshot and it allowed me to boot into WinXP from this esata HD, but it would not boot into the .vhd Win7 for some strange reason. When I copied the image drive snapshot made to this esata drive I did select to restore original partitions but it still doesn’t allow the Win7 .vhd to boot. Still reading and trying other software.

  31. Well, I’ve been having fun trying to get an image made with drive snapshot to boot without any win7 dvd fixes to the bcd. After I image then reboot with the win7 dvd I can get both xp and win7 to boot by deleting then rewriting this part –

    BCDEDIT /SET {default} DEVICE VHD=[C:]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} OSDEVICE VHD=[C:]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} DETECTHAL ON

    Now there is a trick that a lot of guys are using if they have win7 not installed in a vhd. They are editing their bcd and changing it to this before they image the partion —

    bcdedit /set {bootmgr} device boot
    bcdedit /set {current} device boot
    bcdedit /set {current} osdevice boot

    Ok, I know that works, many guys have done it. It’s called generalizing. The “boot” is the hard drive that is being booted, whatever it is. It’s GUID is irrelevant. Now this is what I want for the Win7 .vhd. There must be a way to enter that “boot” into the path for our vhd. Maybe like this —

    BCDEDIT /SET {default} DEVICE VHD=[boot]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} OSDEVICE VHD=[boot]\VHD_Folder\Win7.VHD
    BCDEDIT /SET {default} DETECTHAL ON

    I’m sure that’s wrong but you know what I mean! If we can figure this out making an image of this drive with WinXP and Win7 vhd will be easy. As of now I have to repair with the Win7 DVD like I said above.

  32. @tony – not sure I understand the comment completely, but does [LOCATE] not give you what you are looking for? Some people have assumed that you should replace [LOCATE] with the drive letter, but [LOCATE] is a literal string to help find the VHD on removable media. As I understand it, it will check for a matching file system hit on the directory structure and name, and use the first one it comes across, regardless of the *actual* drive letter. Did you assume [LOCATE] was a placeholder and rather than literally typing it, you replaced [LOCATE] with [C:] in your BCDEDIT entries?

  33. Yes, Garry, [locate] does work. I think the problem is with the GUID which {default} is a win7 shortcut to the actual mult-digit GUID. Like I said if I erase that section and re-enter it exactly the same then it solves my boot problem. I guess I should take note of the actual GUIDs, before I re-write it then after to see if they have changed. I’m pretty sure they will have. I’ll let you know.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.