Defrag a virtual hard disk (.vhd)?

user4531 picture user4531 · Nov 11, 2008 · Viewed 23.7k times · Source

Like any other hard disk, virtual hard discs (*.vhd) will suffer from fragmentation.

So to keep good performance i guess i have to defrag first the virtual hard disc from within the virtual machine and also the (physical) hard disc the .vhd is stored on.

First, are these assumption correct? And second, is there a way to defrag both (virtual and physical hard disc) at once?

Thanks in advance!

Answer

John Baughman picture John Baughman · Nov 12, 2008

Another option that I have been using is to use JkDefrag which is free. There is also a whole process on defragging a virtual PC, but since I can't find the "official" link in the JkDefrag forum, it goes something like this for command line parameters:

  1. Defrag the guest drive from within the virtual machine.
  2. Exit the virtual machine.
  3. On the host machine, run JkDefrag with these command lines

(you can also put them in a batch file):

jkDefrag -q -a2
jkDefrag -q -a6 C:\PathToVirtualDisks\VDiskToDefrag.vhd
jkDefrag -q -a3 -e C:\PathToVirtualDisks\VDiskToDefrag.vhd

Here's what the parameters do:

  • -q = Quit the program when finished.
  • -a2 = Defragment, don't optimize.
  • -a6 = Move to end of disk
  • -a3 = Defragment, fast optimize.

The process can take a long time depending on the size of your virtual disk. As an example, on my PC with a 56GB vdisk it takes about 16-18 hours to complete this process on really badly fragmented days. As a matter of fact, as I write this I have 150+ fragments of that file being defragmented and it's been running for about 30 minutes and it's only about 10% done with just that file.