
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.
On the Configure Disk window check the Copy the contents of the specified virtual hard disk, and select the path to the source VHD.
Click next and finish and this will create the new VHD with the content from the source VHD.
The second and my preferred way of doing it, is of course with Windows PowerShell.
# Mount the Source VHD Mount-VHD "C:\VMs\WS2012\Virtual Hard Disks\WS2012.vhdx" # List the Disks Get-Disk # Create the new VHD (SourceDisk = Disknumber) New-VHD -Dynamic -Path "C:\VMs\NewDefragVHD2.vhdx" -SourceDisk 1








