Copy a Microsoft Virtual Machine VHD/Increase VHD size using Windows Automated Installation Kit

Copy a Microsoft Virtual Machine VHD/Increase VHD size using Windows Automated Installation Kit

Jan 03 2007 - Explore expanding VHDs for development, using Microsoft Virtual Server and WAIK for copying onto larger VHDs when space ran low.

6 min read

Attention needed

This article is a bit old, but some still find it helpful. Links to URL's that are no longer available have been removed.

I have a standard set of Virtual Machines images that I do much of my development with. For the most part, I created the virtual machines and their associated virtual drives using the default settings. As I'm using Microsoft Virtual Server 2005 R2 (x86), the default size for a new virtual drive is 16 GB (this changes with Service Pack 1 to 126 GB). This has been plenty of space and all things have ran well, until I started to install the Microsoft .NET Framework 3.0, Visual Studio 2005 Extensions for Windows Workflow Foundation, Vista and .NET 3.0 SDK, Visual Studio 2005 Extensions for .NET 3.0, and much more. I didn't run all the way out of space, but I was getting close. So I needed to expand my virtual hard drive.

At the moment, there isn't a feature in Microsoft Virtual Server 2005 R2 (not even with the Service Pack 1 beta) to expand the size of a virtual hard drive. So begins the challenge…

Since I couldn't make a modification to the original virtual hard drive (VHD) in order to increase the amount of space, I would need a way to copy the contents of the original VHD and store that data on a new VHD. There were two options that I looked into. The first was to leverage the new feature available in Microsoft Virtual Server 2005 R2 Service Pack 1 named, "Offline VHD Mounting". This enables me to mount a VHD drive as a local drive on my workstation and access it like a physical drive. So in theory, I could simply copy and paste the content. I tried this out with not much success. The issue I ran into was trying to mount to a newly created VHD. To be fair, I didn't spend much time working through this issue as I quickly dove into my second option.

The next approach was to leverage the newly released Windows Automated Installation Kit: (Link no longer available from Microsoft)

The Windows Automated Installation Kit (WAIK) is a deployment and imaging technology the enables IT administrators to take snapshots of a base image, deploy the image, and even directly edit the image while in its compressed form. There ton's of cool stuff in there and I encourage you to read the following article to learn more:

There are many advantages to leveraging WAIK to solve this problem:

  1. It's a freely available download from Microsoft and fully supported
  2. It's a core deployment technology for Windows Vista and soon Windows "Longhorn" server
  3. Windows XP and Windows Server 2003 are supported clients for deployment

Another very interesting component of WAIK is the WindowsPE component. WindowsPE enables you to create a bootable CD the provides support for network connections, manage the disk partitions, and (of course) kick off a capture or attach (aka deploy) an image. Here's a great article to learn more:(Link no longer available from Microsoft)

Before you get started, make sure you download and install the following software components:

  • Microsoft Virtual Server 2005 R2: (Link no longer available from Microsoft)
  • Windows Automated Installation Kit: (Link no longer available from Microsoft)

OK, so let's get down to how I used WAIK to create a copy of a VHD with an increased disk size. In the steps provided below, I provide the steps I took and the command line arguments that I used. This doesn't mean that this is the only way it can be done, but points out what I used to get the results I was looking for and that matched my configuration/environment. Also, many of the WAIK steps noted below can be found in the "Getting_Started_ITPro.rtf" document provided as part of the WAIK.

  1. Make a WinPE Image

    cd Program Files\Windows AIK\Tools\PETools\

    copype.cmd x86 c:\winpe_x86

    copy "c:\program files\Windows AIK\Tools\x86\imagex.exe" c:\winpe_x86\iso\

    Oscdimg -n c:\winpe_x86\ISO c:\winpe_x86\winpe_x86.iso -n -bc:\winpe_x86\etfsboot.com

  2. Using Virtual Server Manager, map the WinPE ISO to the target Virtual Machine
  3. On your workstation (or other server on the network), create a new folder share. We'll use this as the location to store our WIM file which will be an image of our VHD.
    1. Name: wim
    2. Share Permissions and folder permissions set to allow for rights
  4. Boot the Virtual Machine (WinPE will then start)
  5. From within the WinPE command line environment (running inside of the target VM)-Create a connection to the share

    net use z: \\computername\wim /user:computername\username

  6. Capture the image.
    1. Change to the "d:" drive
    2. Capture the image

    imagex.exe /compress fast /capture c:\ z:\myimage.wim "my image" /verify

  7. Using Virtual Server Manager, create a new VHD. Don't forget to change the default size of the VHD.
  8. Using Virtual Server Manager, edit the configuration of the target virtual machine. Within the "Hard Disks" settings, remove the original drive and assign the new VHD. Save the changes.
  9. Boot the Virtual Machine (WinPE will then start)
  10. Partition and format the new VHD

    diskpart

    select disk 0

    clean

    create partition primary

    select partition 1

    active

    format

    exit

  11. Map a drive to the share where we stored the captured image

    net use z: \\computername\wim /user:computername\username

  12. Apply the image previously captured to the new VHD

    imagex.exe /apply z:\myimage.wim 1 c:

  13. Remove WinPE ISO from VM
  14. Restart VM

At this point, you should be all set. What you'll now have on your local hard drive is your original VHD (not assigned to an Virtual Machine), a WIM file which is a snapshot of your original VHD, and a new VHD (larger in size) with the content from the Original VHD.

I've had this up and running for a few days now without any issues. I hope this helps and I plan on doing some more posts on this subject as I start to use it more

Comments

Feel free to leave a comment below. Keep in mind that all comments are moderated and will be approved before being published.