Windows 7: Boot from VHD First Impression: Part 2

Windows 7: Boot from VHD First Impression: Part 2

Rate This
  • Comments 61

Hello,

In my previous post i.e. Windows 7: Boot from VHD First Impression: Part 1 we seen creating and attaching the VHDs. Using the Disk Management or Diskpart utility we can attach the existing VHDs. In this part we will actually cover the boot from VHD feature.

We will cover the different ways by which we can actually boot from VHD file. In order to boot from VHD, the bootloader needs to support boot from VHD file. So, what are the basic benefits of having VHD Booting.

You can use Boot for VHD feature in your test environment or development where you want to try out different applications or devices, which is not possible in Virtual Environment.

Booting from VHDs means booting the machine as if running from primary hard disk so your operating system will leverage all the hardware available in your system like Graphics, Wireless, USB etc. which is not possible in most of the virtual environment.

This is good for multi-boot environment where you want to run multiple operating systems on same machine without losing the performance. This is possible by VHD booting. As every VHD is like a Hard disk with primary partition; so you can create multiple VHDs with operating systems installed onto it.

In this discussion we will cover the following key points.

  • Booting a Windows 7 VHD or Windows Server 7 (aka Windows Server 2008 R2) VHD
  • Preparing VHD file using Windows 7 or Windows Server 7 Media or existing VHD running Hyper-V
  • Adding the VHD entry in Boot Menu for VHD Boot and then Boot from VHD

 

Booting a Windows 7 VHD or Windows Server 7 (aka Windows Server 2008 R2) VHD

This feature is only supported by the Windows 7 client VHD and Windows Server 7 aka Windows Server 2008 R2 VHD.

In order to boot from VHD we need to prepare the VHDs using any of the two methods.

  1. The first method is obtaining the existing Windows 7 or Windows Server 7 DVD VHD and make sure it is sysprepped to clear all the hardware information. So why sysprep ?

    Benefits of Sysprep

    Sysprep provides the following benefits:

    • Removes system-specific data from Windows. Sysprep can remove all system-specific information from an installed Windows image, including the computer security identifier (SID). The Windows installation can then be captured and installed throughout an organization.
    • Configures Windows to boot to Audit mode. Audit mode enables you to install third-party applications and device drivers, as well as to test the functionality of the computer.
    • Configures Windows to boot to Windows Welcome. Configures a Windows installation to boot to Windows Welcome the next time the computer starts. In general, you configure a system to boot to Windows Welcome immediately before delivering the computer to a customer.
    • Resets Windows Product Activation. Sysprep can reset Windows Product Activation up to three times.

    For more information about sysprep visit How sysprep works ? and What is Sysprep ? that will give you clear idea about sysprepping a system.

  2. Applying a WIM Image directly to the VHD file using ImageX utility. The ImageX utility can be used to extract the required operating system edition directly to the attached VHD file in Windows 7

The ImageX utility is part of WAIK. i.e. Windows Automated Installation Kit. You can download the WAIK for Windows 7 from here

Preparing VHD file using Windows 7 or Windows Server 7 Media or existing VHD running in Hyper-V

 

From my previous post create a new VHD and attach it using Disk Management. Now, you will have newly attached X: created with label 'Windows7', which is of size 20 GB.

Now, you will require the 'install.wim' file from the Windows 7 Media or Windows Server 7 Media. Along with that we will require ImageX utility.

In order to extract image to the X: we will use the following syntax.

image

 

d:\imagex>imagex /apply d:\install.wim 1 x:\

In the above syntax we can see we have used 'd:\install.wim' followed by '1' and 'X:\' (this is the attached VHD.)  Now this 1 denotes Image Index i.e. edition of the Operating System.

As you can see I have used the 'install.wim' file from the Media of Windows Server 7 Beta and 1 denotes Enterprise Edition.

In order to check the Image Index we will use the following command

d:\imagex>imagex /info "d:\Download\Windows Server 7 R2\install.wim" (i.e. the location of the install.wim file)

image

Once finished the extracting the OS using ImageX it will look like this

image

Once the image is applied to particular drive in our case X:\. Detach the X: Drive from the Disk Management. Now your VHD file is ready to boot.

 

Preparing the VHD file using Windows Server 2008 Hyper-V

If you have Windows Server 2008 running Hyper-V, launch the virtual machine running Windows 7 or Windows Server 7 aka Windows Server 2008 R2 and the run the following command

c:\windows\system32\sysprep>sysprep /generalize /shutdown

sysprep

After running the above command in the virtual machine, this will launch the System Preparation Tool 3.14. Select the checkbox for 'Generalize' and click on OK.

Once the sysprep is completed the virtual machine will be shutdown and ready for booting. You can copy that VHD now.

Note: Sysprep does not work on upgrade. You need to have Clean Installed Windows 7

 

Adding the VHD Entry in Boot Menu and then Boot from VHD

Now that we have successfully created VHD files. The last step is adding boot entry for the VHD file in your Windows 7 or Windows Server 7 using BCDEdit.exe tool.

For this step open the Elevated Command Prompt with Administrator Privileges and type the following commands.

C:\>bcdedit /copy {current} /d "My New VHD Description"

Note: This will Return the GUID of the Loader Object that you will use to replace <guid> below
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>

Note: vhd=[driveletter:]\<directory>\<vhd filename> is the new syntax supported for BCDEdit.exe to locate VHD File and Bootmgr will locate the partition containing the VHD File to boot from.
C:\>bcdedit /set <guid> detecthal on

Note:

Following is the attached screenshot of the my machine. In this case I have Windows 7 as the default OS and I have added the VHD File in the Boot Entry.

bcd

Well just after that run the following command to test if your boot entry is successfully created using C:\>bcdedit /v

image

 

Similarly, if you want to add multiple VHDs into Boot entry you can use the following lines to the command prompt

C:\>bcdedit /copy {current} /d "New VHD Description"
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> detecthal on

Note:  detecthal is used to force windows to auto detect the Hardware Abstraction Layer.

If you want to delete any existing VHD entry from the Boot Menu you can always use the command C:\>bcdedit /delete <guid> /cleanup This deletes the specified operating system entry from the store and removes the entry from the display order.

Well, we are ready to Boot from VHD. Once you restart the computer you will see additional entry in Boot Menu along with the default Windows 7 or Windows Server 7 OS.

Here is the screenshot from newly booted Windows Server 2008 R2 Beta from VHD. I have installed Desktop Experience Pack and enabled Aero Glass.

win 7 server

Happy Virtualization

Update 1: Thanks much Mark Shyn for pointing out method 1 correction.

Leave a Comment
  • Please add 2 and 5 and type the answer here:
  • Post
  • Can boot from VHD if there is no operating system on the disk.

    I can format the disk and create system partition, place all the boot files and then place the VHD..will this work?

  • @Andriy - First delete currently configured GUID using BCDEDIT /delete {GUID}

    Then move the VHD to D: or E: and then recreate the Boot Entry using BCDEDIT command.

    @Surins - Yes, you can use Boot from VHD if there is no OS on the the DISK. You will need a system partition and other partition for storing VHD File. Refer this file for more info

    http://technet.microsoft.com/en-us/library/dd799299(WS.10).aspx

  • >First delete currently configured GUID using BCDEDIT /delete {GUID}

    >Then move the VHD to D: or E: and then recreate the Boot Entry using BCDEDIT command.

    I did this. but get again Status:0xc000000e

    bcdedit.exe /create /d "w7vhd-E:" /application osloader

    bcdedit/set {guid} device vhd=[E:]\win7.vhd

    bcdedit/set {guid} path \windows\system32\wi

    nload.exe

    bcdedit /displayorder {guid} /addlast

    BTW D:&E: in on raid0 GPT disk. could it cause this problem?

  • Very nice post, thank you. I have an working WIN7 environment where I have created a couple of VHD's to boot from (WS2008; WIN7; HYPER-V Server) by creating them from scratch.

    Is it possible to take an existing Hyper-V vhd's, aka. one of the demo hyper-v's from MS (WS2008R2), copy them to the HDD and insert them in the boot loader directly so you can boot them?

  • can i boot from the windows 2008 vhd file which has created by windows 2008 backup utility ?

  • Hi, nice post.

    I am having the same problem as Andriy, can you explain the detailed steps of resolving his problem?

    Thank you :)

  • hi Aviraj i have a few question

    1. suppose i have win 2008 R2 server. and i created vhd and installed windows xp64 in it. so basically my xp64 is virtualized and running inside 2008 r2.

    2. now suppose i follow your instruction, sys-prep it and boot it with direct access to hardware.

    q1) what will happen to my installed files and programs in xp64 vhd?

    q2) Now if i boot again from my server 2008 R2, and virtual boot from this vhd, will i be able to run it as a virtual guest os?

    q3) Now i want to migrate to new hardware. And suppose my new hardware is also running windows server 2008 R2, will i be able to boot and use the vhd in my new system ?

    i am very interested to know what is possible

  • Hello Suneel,

    First of all, boot from VHD is supported only for Windows Server 2008 R2 and Windows 7. This is by architure only that it supports booting from VHD directly. NO DOWNLEVEL OS SUPPORT i.e. you can't boot Vista, 2008, XP, 2003 or any other downlevel OS using VHD Boot.

    You will have to run the guest os withing Virtualized s/w such as Hyper-V or Desktop Virtualization S/W like VPC or Win VPC etc.

  • With the launch of Microsoft's newest technology known as Windows 7 last October 22, 2009, a lot of computer users are trying to wonder about hardware and software updates that they might need to upgrade to Windows 7. Do you wonder how it is to find and install this version's printer driver for your HP printers?

    <a href="http://printerinkcartridges.printcountry.com/printer-ink-cartridges-how-to-do-troubleshooting/how-to-find-and-install-windows-7-printer-driver-for-your-hp-printers/">How to Find and Install Windows 7 Printer Driver for Your HP Printers</a>

  • I have a bunch of VHD with old demos on them, will this work or do the guest OS needs to be Windows Server 2008 R2 (as I understand from the post)?

  • @Aviraj

    This doesn't see to work with Windows Ultimate N edition (downloaded from MSDN). I get error either "Windows cannot configure Hardware.." or after sysprep "An error occurred .. Windows will restart and try" both ending in a infinite loop...

    Any ideas?

    Regs

    Ravindran

  • As per the VHD BOOT FAQ

    http://technet.microsoft.com/en-us/library/dd440865(WS.10).aspx

    Native boot from VHD is only available with Windows 7 Enterprise, Windows 7 Ultimate and all versions of Windows Server 2008 R2.

  • Great article, but the one question I can't find the answer to is this.

    If I have a VHD already created by VMWare, Virtual PC or Parallels, of my currently installed OS and applications, can I use that to boot into?

    Thanks,

    Jeff

  • No that will not work, you can try sysprepping the VHD that might work.

    In my blog I have given example of using VHD from Hyper-V VM by sysprepping it.

    Also, boot from vhd works only with Windows 7 Ultimate & Enterprise Edition along with Windows Server 2008 R2. No downlevel OS support.

  • @Andriy and @Joyee,

    I had the same issue, and my problem was that the device where I had the VHD stored was a second HDD.  That second HDD was not enabled for booting in the BIOS.  Once I added the physical HDD containing the VHD to the boot list, everything worked fine.

    http://blogs.msdn.com/brchris/archive/2010/05/06/windows-server-2008-r2-native-boot.aspx

    Hope that helps,

    Brien

Page 3 of 5 (61 items) 12345