Best Way to Compact a Virtual Disk

Phone (907) 727-1489

I was frustrated when I tried to compact virtual hard disks from within Hyper V using the Edit Disk options so I resolved to find a better way to do so without using third party tools.  It took me a bit of research to learn how to do this but after reviewing lots of options, I settled on the method below.  I like the fact that you don't need to shrink partitions from within the guest operating system and you don't even need to zero out unused disk space as a lot of other guides recommended.

Make sure that your vhd or vhdx is not mounted by any other operating system or virtual machine, and then, from an elevated command prompt type:

diskpart
select vdisk file="C:\Hyper-V\sampledisk.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

If you didn't get any warnings, your output should look something like this:

Compact Vdisk commands

 

This process reduced the size of my Master Image from 24GB to 15GB and takes seconds.  It may sound too good to be true but I would be very happy to hear back from you if it worked for you.

comments