Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defrag a virtual hard disk (.vhd)? [closed]

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!

like image 764
user4531 Avatar asked Nov 11 '08 17:11

user4531


3 Answers

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.

like image 168
John Baughman Avatar answered Sep 30 '22 05:09

John Baughman


Defrag the guest, then the host. You can defrag just the vhd file on the host by using a utility like CONTIG.

I don't believe you can defrag both at once, since the vhd file likely can't be in use in order to defrag it, requiring the VM to be off.

like image 34
J c Avatar answered Sep 30 '22 05:09

J c


Yes, your assumption is correct. The correct way to defrag is to defrag within the guest first, then the guest hdd file, and then the host hdd. Depending on the VM you're using, it should give you the option. VMWare gives you the option to defrag the guest hdd.

like image 45
JamShady Avatar answered Sep 30 '22 06:09

JamShady