Windows Server 2012 Hyper-V – How to create a new VHD from a source VHD

Windows Server 2012 RC Logo

Microsoft MVP Aidan Finn posted a interesting blog post about Virtual Hard Disk (VHD) Block Fragmentation. He was reviewing the document about Performance Tuning Guidelines for Windows Server 2012 and found a very important note about VHD performance.

Just as the allocations on a physical disk can be fragmented, the allocation of the blocks on a virtual disk can be fragmented when two virtually adjacent blocks are not allocated together on a virtual disk file.

The fragmentation percentage is reported for disks. If a performance issue noticed on a virtual disk, you should check the fragmentation percentage. When applicable, defragment the virtual disk by creating a new virtual disk with the data from the fragmented disk by using the Create from Source option.

Now first thanks to Aidan Finn for finding this one. But how do I create a new VHD or VHDX from a source? Simple there are two ways of doing that, the first one is over the Hyper-V Manager GUI.

Create a new VHD and give it a new name.

New Defrag VHD

On the Configure Disk window check the Copy the contents of the specified virtual hard disk, and select the path to the source VHD.

Copy the contents of the specified virtual hard disk

Click next and finish and this will create the new VHD with the content from the source VHD.

Creating the new virtual hard disk

The second and my preferred way of doing it, is of course with Windows PowerShell.

Create the new virtual hard disk from Source via PowerShell

 

Create the new virtual hard disk via PowerShell