How to install Windows Server 2008 R2 with Hyper-V and Windows 7 on the same partition

Blogger Colin Smith explains how to install Windows Server 2008 R2 with Hyper-V and Windows 7 on the same disk partition by booting from a VHD that contains the entire WS2K8R2 OS within a single, portable file.

Typically, dual-booting multiple operating systems requires repartitioning a disk, which isn't always desirable, especially if you already have a multi-boot environment with Windows and Linux. What I am proposing is booting from a VHD - a virtual hard disk that contains the entire Windows Server 2008 R2 OS installation within a single, portable file hosted by your Windows 7 file system.

What's different about this post from the other boot-from-VHD posts out there? Admittedly, I did learn how to create and install into VHD from some of the TechNet posts, but they focus on creating VHDs from within the WinPE console. Unfortunately, most of us work in Windows, not WinPE. So, what I have attempted here is to show you how to create the VHD from Windows 7 (or Windows Server 2008 R2), so that you can create VHDs for other purposes in addition to just an OS install. Additionally, I'll try to provide some other scenarios where you might want to consider using VHDs.

Why would you want to boot from a VHD?

There are several reasons:

There is no requirement to repartition your hard drive, which in itself tends to waste disk space since most partitions are typically over provisioned.

It simplifies image management for both VMs and physical systems as the same VHDs can be repurposed for both use cases.

You can move the VHD to a Hyper-V server or port it to another virtualization platform like ESX, Virtual Box, Xen , etc., that supports VHDs.

The VHD can be configured to be thin provisioned. This means that you can set the maximum size of the VHD and it will appear to the guest OS as a full partition, but in the host OS, it will only consume as much disk space as required to contain the entire guest OS. The VHD will grow in size up to the maximum as blocks are written to (allocate on write).

You can remove the entire OS by simply removing a single file and updating your boot menu.

It allows you to boot easily from an external device like an eSATA drive (USB or remote storage are not supported for Windows 7 or Windows Server 2008 R2 - Hyper-V Server is supported on USB/Flash )

You can easily back up the entire OS as a single file (like you would a VM).

You can have versioned OSs using a differencing disk to create a parent child relationship between VHDs. This can be very disk space friendly if you manage many images.

Note: In the examples below, I am doing everything on drive C: and assigning drive letter Q: to the VHD but you can use any drive that Windows 7 has available.

Preparing the VHD

First we'll need to create a VHD on the Windows 7 system using the DISKPART command:

1. From the Start->All Programs->Accessories right-click the Command Prompt and select "Run as Administrator" - DISKPART will launch and you will be put into the DISKPART CLI shell.

2. Let's have a look at what volumes DISKPART can see. Type:

list vol↵

Take note of what you see.

3. To create a minimal size VHD that can grow to a maximum size of 15000MB type:

create vdisk file=c:\win2k8r2.vhd maximum=15000 type=expandable↵

4. To set the focus of DISKPART to the newly created VHD type:

select vdisk file=c:\win2k8r2.vhd↵

5. To attach the virtual disk to the system type:

attach vdisk↵

6. We will need a primary partition within the virtual disk to make the VHD bootable; type:

create partition primary↵

7. Although the partition can be formatted as part of the Windows Server installation, I prefer to do it now. To format the partition with the NTFS file system, type:

format fs=ntfs quick label="NewVHD"↵

8. We don't really need to assign a drive letter to the VHD at this point since during the install of Windows Server, it will get a different drive letter anyway, but it makes it more convenient to investigate the VHD from Windows 7. Assign the drive letter Q: to the new partition by typing:

assign letter=q: ↵

9. Let's have a look at what volumes DISKPART can see now. Type:

list vol↵

You should see the new volume available with a size of 14GB.

10. To exit the DISKPART shell type:

exit↵

11. To exit the command shell type:

exit↵

12. Use Windows Explorer to see what size the file c:\win2k8r2 that contains the VHD is. It should be around 80MB. It will grow from here as we add contents to the volume.

13. For fun use right click Computer from the Start Menu and you should see drive Q: mounted. You can check the properties of drive Q: by right clicking it.

Installing Windows Server

Now we are ready to install Windows Server 2008 R2 onto the newly formatted partition within the VHD. I'll provide general instructions here, just highlighting the differences from a standard installation.

1. Boot from the Windows Server 2008 R2 ISO. At the screen that prompts you to select a language press SHIFT+F10 to access the WinPE console.

2. To launch the DISKPART CLI shell:

diskpart↵

3. Let's have a look at what volumes DISKPART can see. Type:

list vol↵

4. To set the focus of DISKPART to the previously created VHD, type:

select vdisk file=c:\win2k8r2.vhd↵

5. To attach the virtual disk to the system, type:

attach vdisk↵

6. Let's have a look at what volumes DISKPART can see. Type:

list vol↵

7. To exit the DISKPART shell, type:

exit↵

8. To exit the WinPE shell, type:

exit↵

9. Return to the Windows Server 2008 R2 setup and select Custom (advanced) as the installation type, not Upgrade.

10. When prompted for the installation location, select the newly formatted volume that has the label NewVHD.

11. Perform the remainder of the installation as usual.

12. When you reboot you will notice that you get a boot menu allowing you to select the OS of your choice. Select Windows Server 2008 R2.

13. Turn on the Hyper-V role.

Now you have a dual boot Windows 7 and Windows Server 2008 R2 system that can also run the Hyper-V role even though it is not installed in its own partition of a physical disk.

At this point, you could migrate your Windows 7 installation to a VHD so that both of your operating systems are booting from VHDs. If you choose this route, the Disk2vhd tool might prove useful.

You could also use the VHD that you just installed Windows Server into as a Hyper-V (or ESX) virtual machine (you will need to recreate or modify the BCD store first).

By the way, the size of the VHD you created will probably be around 6 GB when viewed from the Windows 7 instance.

Related Topics:

About Colin Smith

Colin Smith is a Microsoft SCCM MVP who has been working with SMS since version 1.0. He has over 20 years of experience deploying Microsoft-based solutions for the private and public sector with a focus on desktop and data center management.

Full Bio

Colin Smith is a Microsoft SCCM MVP who has been working with SMS since version 1.0. He has over 20 years of experience deploying Microsoft-based solutions for the private and public sector with a focus on desktop and data center management.