Windows 7 supports VHD natively and it has lots of benefits. We have already posted Native VHD Support in Windows 7, which covers “What’s new in Windows 7 for VHDs. In this blog post, we’ll explore some practical use of VHDs, like Create/Attach/Detach/Format VHDs and make bootable VHD of Windows 7.

Windows 7 VHD acts like the same Real OS(Windows 7 on physical machine). It has some sort of limitation but it is excellent addition to Windows 7 and help for IT Pro, Devs and Testers. The Goals for Native Support for VHDs in Windows Server 2008 R2 and Windows 7 are as follows:

  1. Simplify the experience of creating, managing, and deploying Windows images across both physical and virtual machines using a single image format and common tools.
  2. Enable systems to have multiple instances of Windows installed without using separate disk partitions for more flexibility to change server application workloads as needed.
  3. Enable efficient development and testing for software that requires an isolated test environment using a common image that runs on either a physical or virtual machine

Lets come to the point and start it.

Required:

I have created a folder called VHD on root of C: drive and copied Windows Server 2008 R2’s install.wim and will use the folder to create VHD as well. So the location of files etc. may differ.

How To:

1. Run elevated Command Prompt and launch Diskpart utility. On DISKPART prompt, execute the following commands one by one.

create vdisk file=C:\VHD\W08R2x64.VHD Maximum=25000 Type=Fixed

It creates a VHD file named “W08R2x64.VHD” with maximum size of 25000MB. It is the time taking process. There are two type of VHDs can be created.

Dynamic: The size of VHD increases as data is written to it.

Fixed: The size of VHD is fixed and doesn’t increase as data is written to it.

attach vdisk

Attaches the VHD to disk list, you can check it by executing list disk.

sel disk 1

Selects disk which has ID#1, for more info see the results of list disk command.

create part primary

It creates a primary partition and usages all available space of VHD i.e. 25000MB or approx 24GB.

format fs=ntfs quick

Quick format the partition with NTFS file system.

assign

Assign a drive letter to the partition. for instance G:

active

Mark as the active partition. finally exit and leave the diskpart.

Creating VHD

Once you are done. you’ll see an extra drive in Computer i.e. the partition of VHD, because the vdisk is still attached.

The partition of VHD

2. Now run elevated Deployment Tools Command Prompt (If UAC is enabled)

Start > All Programs > Microsoft Windows AIK > Deployment Tools Command Prompt and execute the following command to copy the Windows 7 to VHD partition.

imagex /apply C:\VHD\Install.wim /check 3 G:\

Copy the OS files(which has Index#3) to G: drive(VHD partition). Where /check

To know about Index, you can execute the following command imagex /info C:\VHD\Install.wim which will display WinInfo with all available index associated Windows editions.

ImageX

3. Now we need to use diskpart once more to detach the VHD.

Detach VHD First command selects VHD and second one detaches.

4. Now we are to add boot entry in BCD using bcdedit.exe command, which is so easy as A,B,C.

bcdedit /copy {current} /d “Windows Server 2008 R2 – VHD”

Here we are copying BCD data, because both OS are same. The command creates a copy all settings of currently running Windows i.e. Windows 7. It also adds boot entry with an unique identifier. See {47aa7c3d-833d-11de-afc5-dec4cb4d83bb}. It may differ PC to PC.

Now we need to modify device and osdevice for VHD’s boot entry which Unique ID is {47aa7c3d-833d-11de-afc5-dec4cb4d83bb}

bcdedit /set {47aa7c3d-833d-11de-afc5-dec4cb4d83bb} device vhd=[C:]\VHD\W08R2x64.VHD

and

bcdedit /set {47aa7c3d-833d-11de-afc5-dec4cb4d83bb} osdevice vhd=[C:]\VHD\W08R2x64.VHD

Add boot entry to BCD

5. Now reboot your PC and perform few essential part of installation, like installing device drivers, updating registry and services, creating User account and set regional date/time/languages etc. When you are done… Your Windows 7 VHD is ready to use.

10 responses to “Create a bootable Windows 7 VHD (Virtual Hard disk)”

  1. Lin Lin Avatar

    When I am using this command: bcdedit /copy {current} /d “Windows Server 2008 R2 – VHD ” says
    “A description for the new entry must be specified.
    Run “bcdedit /? ” for commed line assistance.
    The parameter is incorrect.”

  2. KeNSei Avatar

    Hello!!!

    I can’t find sources folder and Install.wim in DVD WAIK for Windows 7/Windows Server 2008 R2.

    can anyone halp me plz?

    THNX!!!

    1. Admin Avatar

      install.wim is not in WAIK DVD, It can be found in Windows 7/Windows Server 2008 R2 DVDs/ISOs.

  3. AH Avatar

    When you using this command: bcdedit /copy {current} /d “Windows Server 2008 R2 – VHD”
    you copy the GUID from current Windows installation.

    This GUID is used for the VHD.

    But what do you think will happen if you want to delete the VHD from the boot menu using:

    bcdedit /delete {GUID} ?? 

  4. Rose Avatar

    How do you delete a bootable VHD properly? When I delete the .vhd file under c:, at next reboot, error message screen appears at predesktop saying ” The windows boot configuration date (BCD( store file contains some invalid information..

    Object GUID:
    description:
    status..

    The associated windows boot loader entry may not be available for selection until the problem is rectified by an administrator”

    How do i delete a VHD properly so this error would not appear??

    Thank you.

  5. armani sunglasses Avatar

    nice share, good

    article, very usefull for me…thank you

  6. Railsroller Avatar

    Is it possible to create a VHD file of my current Win XP SP3 and boot on it in a PC running windows 7 ?

    Thank you !

    1. Author Avatar

      Windows XP deosn’t support VHD natively. You can create Windows XP SP3 VHD or can download Windows XP Mode and Virtual Windows PC/Virtual PC 2007 to run Windows XP SP3 Virtual Machine on Windows 7.

  7. Daren Avatar

    With Portlock Leap Frog ( http://www.portlock.com/products/leap_frog/) a preconfigured VHD can easily be added to the boot entry even with Windows XP or Vista. NO AIK or OPK is needed. Portlock Leap Frog will automatically upgrade the boot manager to support VHD boot. Portlock Leap Frog will also setup or create a VHD and a bootable OS within it such as Windows 7 ultimate or Windows 2008 R2 ( windows 7 server).
    http://www.portlock.com/support/knowledge_base/download_windows_7_vhd.aspx

  8. ArvindK Avatar

    Thanks, great share and very important and needed feature of Windows 7 by Microsoft.

Leave a Reply

Your email address will not be published.