Harold Wong's Blog with Geekie Thoughts and Insights

Virtualization, Cloud (Private, Public and Hybrid), Unified Communications and Thoughts on Sushi

Using Hyper-V to create a Base OS Image that can be used for VMs and Boot to VHD

Using Hyper-V to create a Base OS Image that can be used for VMs and Boot to VHD

  • Comments 2
  • Likes

I’m sure a lot of techie folks like me use virtualization quite a bit for testing and learning purposes. When we have to build Servers for many different scenarios, it sure is helpful to have a base Windows OS Image handy to start with. Even though it seems simple, I thought I would share my personal experience and “How To” steps to help those who are still somewhat new to this process. I happen to use Hyper-V for all of my virtualization stuff so my instructions will be based on this.

The first thing I take into consideration is the versions of Windows Operating Systems that I plan on using during my testing, learning and demos. Based on the different scenarios that I tend to evaluate, I happen to need the following:

· Windows Server 2003 R2 with SP2 (Enterprise Edition)
· Windows Server 2008 with SP2 (Enterprise Edition)
· Windows Server 2008 R2 with SP1 (Enterprise Edition)
· Windows 7 with SP1 (64 bit Ultimate Edition)

Since the process of building the image is pretty much the same for all above operating systems, I will focus on Windows Server 2008 R2 with SP1 in my example.

Here are my “How To” Steps:

1. Create a VHD for the Virtual Machine

a. Disk type: Dynamically Expanding
b. Size of Disk: 30 GB

vhdforbase

2. Create Virtual Machine

a. The number of virtual processors and amount of RAM is not important since I am only interested in the final VHD file. I usually assign at least 2048 MB so the install doesn’t take forever.
b. 1 Network Adapter
c. VHD created in step 1
d. Attach ISO for Server 2008 R2 SP1

3. Boot the Virtual Machine and perform a basic install of Windows Server 2008 R2 SP1 Enterprise Edition (GUI)

4. Once the installation is complete, I logon as Administrator and install the following components

a. .Net Framework (and associated dependencies)
b. Telnet Client
c. Latest updates from Windows Update
d. Any other software such as Foxit Software PDF Reader, etc.

5. Make the necessary configurations

a. Disable Shutdown Tracker
b. Disable IE Enhances Security Configuration
c. Any other configuration changes you want

6. Run “Sysprep /oobe /generalize /shutdown” from C:\Windows\System32\Sysprep

7. The VM will turn off after the command completes.

8. At this point, I copy off the VHD and give it a name that helps me identify the image (e.g. WS2008R2SP1EntBase.VHD). I also mark it as Read Only.

When I create VMs for testing / demos, I will create Differencing disks that point to the Base Image. If I will be installing applications that need a lot of disk space, I will also create a secondary VHD (Dynamically expanding of size 127 GB) and attach it as a SCSI Drive so that I have plenty of “space” to install stuff. I’m sure by now, you are wondering why I didn’t just create the base image drive to be 127 GB instead of 30 GB. The reason is that I can use a copy of the same image to configure my machine to Boot to VHD. When doing this, the size of the VHD (per the definition) becomes much more important. If I defined the VHD as a 127 GB drive, I need to have at least that much free space on my physical drive when I perform the Boot to VHD. Since I don’t have 1 TB drives that I’m using for my laptop, the 30 GB definition works out much better for me.

To configure my machine to Boot to VHD, I perform the following steps:

1. Copy the Windows Server 2008 R2 Base Image to C:\BootVHD

a. The directory name can be anything you want, but I like something descriptive.
b. I also like to rename the VHD file to something like “server2008r2sp1vhdboot.vhd”.
c. Make sure this file is not Read Only (remember that I usually set that on my base image upon creating the VHD file)

2. Issue the following commands from the Command prompt:

· bcdedit /copy {current} /d "Windows Server 2008 R2 SP1 (VHD Boot)"
· bcdedit /set {CLSID} device vhd=[c:]\bootvhd\server2008r2sp1vhdboot.vhd
· bcdedit /set {CLSID} osdevice vhd=[c:]\bootvhd\server2008r2sp1vhdboot.vhd
· bcdedit /set {CLSID} detecthal on

{CLSID} is replaced with the output from the first command

When I reboot my machine, I will have an additional OS Option (the one from the first command) in my list. I like to take advantage of this capability to have a multi boot environment without having to physically partition my hard drives. Generally, I will use this to test Server stuff that I really need to run directly on physical hardware versus a VM. I also use this method to have multiple installs of Hyper-V (one as a standalone and the others can be joined to a domain where the DC is running within a VM hosted on that Hyper-V). If I need to boot to Windows 7 on the physical machine, I can also take my Windows 7 base image and perform a Boot to VHD with that VHD file.

Harold Wong

Comments
  • can w2k3r2sp2 be booted from vhd?

  • Tony: No, it cannot.  The only Microsoft based Operating Systems that support Boot to VHD today are Windows Vista, Windows 7 and Windows Server 2008 R2.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment