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
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.
Sysprep provides the following benefits:
For more information about sysprep visit How sysprep works ? and What is Sysprep ? that will give you clear idea about sysprepping a system.
The ImageX utility is part of WAIK. i.e. Windows Automated Installation Kit. You can download the WAIK for Windows 7 from here
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.
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)
Once finished the extracting the OS using ImageX it will look like this
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
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.
Well just after that run the following command to test if your boot entry is successfully created using C:\>bcdedit /v
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.
Happy Virtualization
Update 1: Thanks much Mark Shyn for pointing out method 1 correction.
Boot From VHD is only supported by Windows 7 and Windows Server 2008 R2. No downlevel OS support. That means you cannot boot Windows Vista or Windows Server 2008 using Boot From VHD option
i tried using boot 7 from vhd but it fragments to quickly so both it & vista are slow to boot
Portlock Leap Frog, makes it very easy to setup a VHD for booting or an existing VHD, even if you only have Vista or XP. Portlock Leap Frog will upgrade the boot manager to support VHD boot.
In your demonstration , in the middle of it .... you say
--------------------------
and then you say
My confuse is if I shutdown my windows 7 by sysprep , then how can I detach the X: ?
In the above
"launch the virtual machine running Windows 7"
I don't understand what is "the virtual machine" mean. I'm using an DVD installed Windows 7 , how can I sysprep it ?
If you won't mind , make this clear for me, thanks
This is very nice post. I followed steps and was able to boot into the VHD properly.
I am having trouble with Graphics. Detected adaptor is shown as Standard VGA adaptor. Why this is happening and how to solve this?
@Raymond
You are confusing with the process.
Preparing VHD file using Windows 7 or Windows Server 7 Media
-In this we are manually creating VHD, applying OS files using ImageX and then detach.
-In this we are actually working on the VM, then installing Windows 7 and syspreppint the OS. They copying that VHD frm the Hyper-V based VM to boot from VHD scenario.
@sam
You need to download and install display drivers in order to get the graphics.
In the Boot from VHD scenario we are accessing the hardware directly from the computer. So we need to install the appropriate drivers.
I suggest you can use Windows Update for display drivers.
Excuse me if this may sound a bit ignorant.
How exactly does VHD benefit you in contrast to using dual-booting ?
I mean why go with the fake virtual thing (i know its not fake) when you can go full blown and use a second partition to create another bootable OS?
If you have to restart your computer to go on to the VHD in essence it is like dual booting.
How would this application be used in an IT Enterprise environment ?
Thanks,
Steve
Hey, that's a nice post.
I followed you post and was able to boot my laptop from Windows 7 Ultimate VHD.
But after booting from VHD, my laptop dosent detects any WIFIs and hence i am not able to connect to internet.
Can you suggest me any resolution for that?
Thanks!
This seemed to work for a Win7 vhd install except when I booted to the vhd and ran thru setup - when I entered the license key for the Win7 DVD that I got the install.wim from, it said the key was invalid. This was my MSDN win7 download.
anyone know the solution to this? seems like the install.wim wasnt' built correctly on the dvd.
thanks
Which edition you downloaded?
Retail DVD contains Home Basic, Premium, Professional and Ultimate.
For Ultimate Edition Image Index is 5.
You need to use imagex /apply install.wim 5 X:/
Where 5 is edition id for ULTIMATE and X is Target drive.
Enterprise SKU not included in retail DVD. It comes in different media as VL.
How can I know {GUID}?
Thanks.
bcdedit /enum
This will list out the GUID
Windows Backup creates a .vhd file. Is it possible to boot from this vhd using the bcdedit parts of the above mentioned procedure?
Thanks
when .vhd is on C:
device vhd=[C:]\win7.vhd
osdevice vhd=[C:]\win7.vhd
works perfect.
but when move win7.vhd to D: (or E:)
->
bcdedit /set {guid} device vhd=[D:]\win7.vhd
bcdedit /set {guid} osdevice vhd=[D:]\win7.vhd
bootmgr error:
The configuration for an element within the object is invalid in the boot configuration data store.
The associated windows boot loader entry may not be available for selection until then problem is rectified by an administrator.
The windows boot configuration data (bcd) store file contains some invalid information.
Status : 0xc000000f
or
Status : 0xc000000e
so, how boot win7.vhd from D: or E: ??
Thnx