Written by 8:42 pm Microsoft, PowerShell, Virtualization, Windows Server • 4 Comments

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

# Mount the Source VHD
Mount-VHD "C:\VMs\WS2012\Virtual Hard Disks\WS2012.vhdx"
# List the Disks
# Create the new VHD (SourceDisk = Disknumber)
New-VHD -Dynamic -Path "C:\VMs\NewDefragVHD2.vhdx" -SourceDisk 1


Create the new virtual hard disk via PowerShell



Tags: , , , , , , , , Last modified: August 9, 2012
Close Search Window