Rapid provisioning with SCVMM 2008 R2

Rapid provisioning with SCVMM 2008 R2

  • Comments 2
  • Likes

A common question we get from hosting providers is around rapid provisioning of virtual machines in Hyper-V.  In the hosting world, when a customer purchases a new VM, the hosting provider wants to make that machine available to the customer as rapidly as possible.   We did a little collaboration on our team and came up with the following approach.  While there are different approaches to solving this this, here is one that is pretty slick.

A little Background on SCVMM and Windows Server 2008

One of the really cool things that came out in SCVMM 2008 R2 was the ability to take advantage of LUN cloning that some SAN vendors support for rapid provisioning.  With LUN cloning, the SAN does the heavy lifting of copying an image to a new LUN then SCVMM 2008 R2 could attach to that VHD when provisioning a new machine, thus avoiding the network file copy. 

Windows Server 2008 R2 introduced another really cool feature known as Clustered Shared Volumes (CSV’s) where cluster nodes can share storage.  You could place multiple VM’s on a CSV and run one VM from one node of the cluster and another VM from a different node of the cluster using that shared network storage.  Now the heartbreaker – LUN cloning and CSV’s don’t really work together.  When using LUN cloning, you are still stuck in a one VM per LUN model as was the case with Windows Server Hyper-V R1.

Before you read any further, a word of caution – before provisioning with this approach, take the time to think through the management implications.  We have listed some Additional Considerations and Questions later in this posting.  Don’t go crazy here.  Take the time to think it through to see if it meets your needs as a business as well as SLA’s and customer expectations.

The solution

Doing some research I saw that Michael Michael had published a PowerShell Module that could be added to SCVMM to provision a VM using differencing disks.  http://blogs.technet.com/m2/archive/2009/05/07/rapid-provisioning-in-vmm-2008-r2.aspx

The thought came up – what if the base sysprepped image was sitting on the CSV?  Could you provision a new highly available VM on the same or even a different CSV using a differencing disk?  If you could, that meant provisioning times could be cut to seconds instead of minutes.

I made some minor modifications of the script MM had produced – I will list the final version at the end of this blog.  I also built a small wrapper around it to make it easy to test and demo.

So here is the step by step:

1) Create a sysprepped image of the base OS you wish to deploy.  In my case I used an eval version of Windows Server 2008 R2 Datacenter.

2) Copy that image onto your CSV so that it can be referenced when provisioning a new VM based on the image.  In this case I placed it on Volume 2.



3)  Next in SCVMM 2008 R2, build a new Template that has the hardware settings that you want your new VM’s to be based on.  In the template you can add product key, admin password, networking configuration and more.  You can even point to an answer file to be used in the mini-setup.


4)  You will need to install the NewDiskDiffVMModule into VMM.  This is pretty easy to do.  Copy the psm1 file on the file system of the SCVMM server and run the following from a SCVMM PowerShell prompt.


5)  Optional - I created a CSV rapid provision script that made this a little bit easier.  Let me go over the call to the New-DiffVM:

param ([String]$VMName)

New-DiffVM -ParentVHDPath "C:\ClusterStorage\Volume2\DCPrep.vhd" -NewChildVHDPath "C:\ClusterStorage\Volume1\$VMName.vhd" -HostComputerName "HvHost2.HyperData.Com" -VirtualMachineName $VMName  -TemplateName "DCBaseTemplate" -VirtualMachineServerName "VMMR2RTM.HyperData.Com"

-ParentVHDPath – this is the path to the parent VHD – in my case on Volume 2 and named DCPrep.vhd

-NewChildVHDPath – this is the path and name of the new VHD that will be the child of the previous entry.

-HostComputerName – where do you want SCVMM to provision this VM.  Yes I know - the next trick will be to use smart placement.

-VirtualMachineName – the new name of the VM as it appears in Hyper-V and SCVMM.

-TemplateName – the name of the template that we created in step #3.

-VirtualMachineServerName – finally the name of the SCVMM server we want to do this provisioning on.


This is the part you have been waiting for right?  Well lets take a look.

Rapid provisioning in action

One more thing to note here is that since these VM’s are sitting on clustered shared volumes, live migration and quick migration work just fine. 

Merging the Virtual Disks

There are at least a couple of issues to be concerned with with this approach.  As you add more and more machines that are using the same base image, there will be more of a demand on the the reading from the base image.  If the demands get too high, you may want to consider merging the new VM and the base image into a new VHD that is used exclusively by the guest VM.  You will loose the disk space you were saving by sharing the parent disk as the parent to multiple VM’s.  Also note that the VM must be down while the merging takes place.

Lets take a look at the merge process.

In Hyper-V manager, go to the properties of the VM and choose Edit


Choose Merge


Be sure you select the option to merge to a NEW VIRTUAL HARD DISK.


When the merging is complete, attach the new dedicated disk to the VM in place of the differencing disk.


Additional Considerations and Questions

Additional things that should be considered include:

1. How do I keep same base image for a single customer? 

Different approaches are out there – one is to consider keeping a copy of the master in the VMM library identified by customer if it is that specific. If the base image needs to change, then its really time to merge VM’S to a single VHD per machine.

2. How do I keep same base image for a single type of workload?

Create different VMM templates – the template really defines how much memory and even additional disk space the VM gets when provisioned

3. How many diff-disks to parent are recommended (ratio)?

This would really depend on workload expect to do some testing

4. How to merge diff disks - and when do you do it.

See the section above for the how to.  When to do it may depend on performance, management, patching and other considerations.

5. How do you move a VM from one cluster to another if the diff disks are used.

The most straightforward approach would be to merge and migrate.  Keeping base disks in sync across clusters may be too much to manage.


Rapid Provisioning in VMM 2008 R2 using the UseLocalVirtualHardDisks and SkipInstallVirtualizationGuestServices flags



#Usage: Import-Module .\NewDiffDiskVMModule.psm1

function New-DiffVM
    Creates a new Virtual Machine using Differencing Disks and Rapid Provisioning.
    This function creates a differencing disk from a base VHD and uses the differencing
    disk to create a new VM without having to copy the VHD file from the VMM library
.Parameter ParentVHDPath
    This is the full path to the base VHD to be used for the differencing disk.
.Parameter NewChildVHDPath
    This is the full path of the child differencing disk VHD that will be created. The
    Virtual Machine will reference this VHD.
.Parameter HostComputerName
    The FQDN of the virtual machine host that is the target for this Virtual Machine.

.Parameter VirtualMachineName
    The name of the Virtual Machine that will be created.

.Parameter TemplateName
    The unique name of the VMM template that contains any Hardware or OS customizations.

.Parameter VirtualMachineServerName
    The FQDN of the Virtual Machine Manager server computer.

    Name     : New-DiffVM
    Author   : michael.michael@microsoft.com
    Lastedit : 05-Apr-2009

param (





    Write-Host -ForeGroundColor DarkGreen “About to get a connection to the VMM server”
    #Add the VMM server PowerShell snap-in
    #Add-PSSnapin "Microsoft.SystemCenter.VirtualMachineManager"
    #get a connection to the VMM server
    $c = get-vmmserver $VirtualMachineServerName
    #check for connectivity
    if ($c.IsConnected -ne $true)
        Write-Host -ForeGroundColor Red “Failed to get a connection to the VMM server”

    #get the VMM host object
    $vmhost = get-vmhost $HostComputerName

    #get the image mgmt service instance for the host computer
    $VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername $HostComputerName
    #create a differencing disk from the base disk
    $Result = $VHDService.CreateDifferencingVirtualHardDisk($NewChildVHDPath, $ParentVHDPath)
    #check for diff disk creation success
    if ($Result.ReturnValue -ne 0 -And $Result.ReturnValue -ne 4096)
        Write-Host -ForeGroundColor Red "Failed in creating the differencing disk"
    #create jobgroup ID for new-vm from template
    $VMGuid = [System.Guid]::NewGuid().ToString()
    #specify the local location for the VHD (use the child vhd that is a diff disk)
    Move-VirtualHardDisk -Bus 0 -LUN 0 -IDE -Path $NewChildVHDPath -JobGroup $VMGuid
    #get the template name
    $template = Get-Template | where {$_.Name -eq $TemplateName}
    #Get the current username to be passed as the VM owner
    $callerUsername = whoami

    #create the new-vm from template and specify the Rapid Provisioning flag (-uselocalvirtualharddisks)
    New-VM -Template $template -Name $VirtualMachineName -Description "Created using Rapid Provisioning PowerShell script" -Owner $callerUsername  -SkipInstallVirtualizationGuestServices -VMHost $vmhost -UseLocalVirtualHardDisks -Path $vmhost.VMPaths[0] -RunAsynchronously -JobGroup $VMGuid | Out-Null
    Write-Host -ForeGroundColor DarkGreen "Creating the new Virtual Machine. Go to the VMM Administrator Console to monitor the progress of the job"


Export-ModuleMember -Function New-DiffVM

  • Thank you very much !

    Take care


  • Antique thread but was does the Move-VirtualHardDisk attach the VHD to the newly created VM in the JobGroup?

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