Checking and Correcting Virtual Hard Disk Fragmentation

With both dynamically expanding and differencing virtual hard disks – the following pattern is used when writing data:

Check to see if data has already been written to this area of the disk

If yes – write new data to the same location as the old data

If no – create new blocks on the disk, and record the new block location in the block allocation table for the virtual hard disk

Depending on the write patterns experience by a virtual hard disk – these blocks can end up being poorly aligned, or “fragmented”. You can check the fragmentation level of a virtual machines virtual hard disks by running the following command in PowerShell:

If you believe this is causing a performance problem in your situation – there are a number of ways to defragment a virtual hard disk. But the easiest way is to perform a storage migration – which will re-layout the blocks in a linear fashion.

Hi Ben, can you list out the steps to do this kind of de-fragmentation? I have tried to move the VHD to another folder using Hyper-V manager (Windows 10 Build 1511) but the fragmentation percentage did not change after the time consuming move?