Using Differencing disks for VM deployment in Hyper-V

Hui W. Wu
Tech Jobs Academy
Published in
5 min readMar 9, 2016

The differencing disk feature in Hyper-V for Windows Server 2012 is a wonderful tool that can be extremely useful when you are in a situation where you need to deploy a bunch of Virtual Machines(VM) for your company or if you simply just want multiple VM for a test environment. Not only does differencing disks help you save deployment time, it actually helps you conserve disk space as well. For this blog post, I will give a walk-through of how to utilize differencing disks for VM deployment. But first, let’s talk about what differencing disk are.

What are Differencing Disks?

Differencing disks, also referred to as the child disk in this situation, are virtual hard disks(VHD) that have a parent-child relationship with another VHD. It only saves changes made to the parent VHD. This parent-child relationship allows the child disks to reference the parent disk for similar files instead of storing another copy of the same exact files.

Below is a picture to help you visualize that relationship:

Differencing disks can reduce the storage and time requirements for VM deployments, but it can also be a performance hit when many differencing disk is trying to read from the parent disk at the same time. So if performance is an issue for your project, then differencing disks might not be the best choice.

Step. 1: Creating the Parent Disk

Before we can create any differencing disks, we have to create a parent disk and prepare it. So first, let’s create a new VM with the “New Virtual Machine Wizard” in Hyper-V and set it up according to the specs of the Windows OS that you plan to deploy. For our example, we’ll be deploying Windows Server 2012 R2 on our VMs, so we’ll set up our VM with the following options:

  • Name: Parent Disk
  • Specify Generation: Generation 1
  • Assign Memory: 1024 and dynamic
  • Configure Networking: Not Connected
  • Connect Virtual Hard Disk: Create a virtual hard disk with a size of 60gig and name it parentdisk.vhdx and select the path where you want to save your parent VHD.
  • Installation Options: Install OS from a bootable CD/DVD-ROM or from an Image file

Once our VM is created and we’ve installed our Windows OS, we must run sysprep within the VM we have created to remove the system-specific data from Windows and prepare it for imaging. The sysprep executable can usually be found in the following path “C:\Windows\System32\Sysprep.exe”.

We’ll select the option as shown in the dialog below to put our system into an “Out-of-Box Experience” and generalize our Windows settings.

Sysprep is usually found in the following path: C:\Windows\System32\Sysprep.exe

Once that is complete, we have to shutdown the VM. Then we can use the VHD that was created with this VM as our parentdisk, in this case, it is named parentdisk.vhdx.

We should also set parentdisk.vhdx to be read-only because we don’t want any changes to be made to the parent disk at this point forward. We can do that by right-clicking on the parentdisk.vhdx file and going to properties and under the general tab, we should check “Read-Only”.

Step 2: Creating differencing Disks

Now that we have created our parent disk, we can create as many differencing disks as we want based on that parent disk. To create our differencing disk, we will use the “New Virtual Hard Disk Wizard” in Hyper-V with the following options:

  • Choose Disk Format: VHDX
  • Choose Disk Type: Differencing
  • Specify Name and Location: Name it VM1 and store it where ever you want to store this differencing disk.
  • Configure Disk: specify where the parent disk is located

Finish the wizard, and now we have created our first differencing disk that is ready for deployment.

8.5 gigs compared to 4kbs

As you can see with the screenshot above, the space savings can be quite significant when you multiply that with many VMs.

Step 3: Creating a VM with the Differencing Disk

We can now create a VM with the differencing disk we just made by going through the “New Virtual Machine Wizard” in Hyper-V. Using the same options that we used to create the parent disk earlier except this time, we’ll pick the “Use an existing virtual hard disk” option and select the differencing disk that we made. We can repeat the process to deploy as many VMs as we want.

Things to note

An important thing to keep in mind is that we should never make any changes to the parent disk once a differencing disk is created from it. Any changes made to the parent disk will corrupt any subsequent differencing disk made from it and render it inoperable. Also, as you create more and more differencing disk and they are all trying to read from the Parent disk, performance will suffer because of I/O limitation. To optimize disk I/O performance, it’s a good idea to keep your parent disk on a separate physical hard disk than your differencing disks.

Once we have set up a parent disk, we can use differencing disks to quickly deploy VM’s on demand without having to go through the lengthy installation process. This will make your VM deployment less tedious and repetitive.

--

--