Home > Uncategorized > Copy/Increase a VHD using VHDMount

Copy/Increase a VHD using VHDMount

So after my first post on the subject of “expanding a VHD” by actually copying the contents of a VHD image using WAIK (Copy a Microsoft Virtual Machine VHD/Increase VHD size using Windows Automated Installation Kit), I got some good feedback on my laziness of not going down the VHDMount method. So I took a bit of time tonight to work through that scenario.

A key new feature in Service Pack 1 for Microsoft Virtual Server 2005 R2 is the availability of a new tool named, “Offline VHD Mounting”. It’s a command-line utility that allows you to mount a Virtual Hard Drive (VHD) as a local drive on a host server. The great advantage to doing it this way versus using an imaging technology (like I did using ImageX.exe as part of the WAIK), is that you don’t need the overhead of taking a snapshot, deploying, rebooting, etc. You simply need to mount the original image, mount the new image, and then do a copy.

Before we get started, please make sure that you have downloaded and installed the following

So here are the steps I took to “expand a VHD” by coping the contents from the original to a new VHD that was created at a much larger maximum size.

  1. Ensure the Virtual Machine (VM) that holds the original VHD is currently stopped.
  2. Mount the original image
    1. Open a Command Prompt and change directories

      cd “C:\Program Files\Microsoft Virtual Server\Vhdmount\”

    2. Mount the original image (the path I have below reflects my deployment.

      vhdmount.exe /m F:\Images\Configs\DepA-Web02\DepA-Web02.vhd V

  3. Create a new VHD – Using the Virtual Server Administration Website, create a new Virtual Hard Drive (VHD) that has the new storage capacity that you feel you’ll need.
    1. Click Start > All Programs > Microsoft Virtual Server > Virtual Server Administration Website
    2. From the Virtual Disks menu, select “Dynamically Expanding Virtual Hard Disk” or “Fixed Sized Virtual Hard Disk
    3. Provide the new hard drive name and location. You may also notice that the default size for a VHD is no longer 16 GB, but is now 127 GB.
    4. Click the Create button
  4. Mount the new VHD (same steps as step #2, but you need to point to the new VHD location)
  5. Once the new VHD is mounted, I wasn’t able to actually see it using File Explorer. As any new drive, virtual or physical, it has yet to be partitioned and formatted. So the next step is to create a partition and format the new VHD. This (as is everything else) is done on the host machine. There are two ways that we can perform this task: The GUI way using the “Disk Management” MMC Snap-in or the command-line way using the “DiskPart” utility. Below are the steps using DiskPart
    1. Open a Command Prompt and execute:

      diskpart

    2. Find the disk number for the new image. It should have a “Size” and “Free” value that are the same number AND should be the size of the VHD that you created.

      list disk

    3. Now we’ll create the partition on the drive (the disk number for my new VHD was 4, but you should use the number that you found from the above command) and assign it a drive letter

      select disk 4

      clean

      create partition primary

      assign letter=w

      exit

    4. The next step is to format the new drive

      format w: /FS:NTFS /Q

    5. Finally, we’ll go back into diskpart and activate the partition

      diskpart

      select disk 4

      select partition 1

      active

      exit

  6. At this point, we now have a VHD drive ready to be used. So now we’ll simply start copying all of the contents from the original image to the new image. (This will take a while…)
    1. Using the default xcopy command within Windows, we’ll copy all of the contents

      xcopy v:\ w:\ /E/H/K/O

  7. Once the copying is complete, we should now unmount the drives
    1. Open a Command Prompt and change directories

      cd “C:\Program Files\Microsoft Virtual Server\Vhdmount\”

    2. Mount the original image

      vhdmount.exe /u v

      vhdmount.exe /u w

  8. We’re now ready to point the target Virtual Machine from the original VHD to the new VHD.
    1. Click Start > All Programs > Microsoft Virtual Server > Virtual Server Administration Website
    2. From the “Virtual Machines” menu on the left side, hover over the “Configure” section and then click on the target Virtual Machine from the pop out window.
    3. Click on the “Hard Disks” configuration section link
    4. We don’t “really” need to remove and add a new hard drive. What we’ll do instead is point the old path to the new path in the “Fully qualified path to file” section for the appropriate disk. Then click OK.
  9. We’re all done! Now you can start up you VM and it should now be using your new VHD, but with the previous (and I’m sure lots of time invested in created) content. But don’t delete you VHD just yet. I’d give it a few days or hours of testing before you delete the original VHD to save space.

I’m sure most of this could be scripted out and perhaps that’s another late night project for me. But for now, this should at least get you going down a path that worked for me.

Update:

I thought some of you might find the before and after file sizes interesting:

  • Original VHD: 15 GB
  • WIM of original VHD: 5.58 GB
  • VHD using WAIK: 12.5 GB
  • VHD using VHDMount: 13.3 GB
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: