Software - Shrink virtualbox dynamic drive
ShakaZ - 16.04.2012, 15:43
Post subject: Shrink virtualbox dynamic drive
Yesterday I needed to find a way to shrink a virtualbox dynamic hard drive image. Indeed the vdi (virtual drive image) grows when you use up more disk space but doesn't reduce it's size when you delete files.
In this case it was a virtual Windows XP, the same kind of procedure exists for Linux virtual machines. (more info
here , replace modifyvdi by modifyhd)
The two procedures described (using VboxManage modifyhd Image.vdi --compact or VboxManage clonehd Image.vdi NewImage.vdi) actually made things worse as the vdi grew from 9GB to 20GB which was almost the full capacity of the virtual drive.
The solution was to use Clonezilla as it supports smart copying for ntfs when cloning a drive, writing only the sectors that contain data.
1) Create a virtual machine booting on a Parted Magic iso with the vdi you want to shrink and a new dynamic virtual drive attached to it. The new drive's size should be equal or bigger in capacity than the current one or clonezilla will refuse to clone onto it.
If you have several hard drives available, preferably create the new virtual disk on another drive than the current one as this will speed up the cloning onsiderably.
2) Launch the machine and then clonezilla once booting is done. Select disk to disk cloning and check the option to resize the target partition in case the 2nd drive is bigger.
Shutdown the machine once it's done.
3) Reconfigure your original VM to use the new vdi instead, or create a new VM connected to the new drive. 2nd method might be better as else virtualbox might complain about UUID of the drive changing once you restart virtualbox.
Using this method the 20GB image was reduced to 5.7GB which is slightly more than the reported disk space usage .
DeepDayze - 16.04.2012, 16:43
Post subject: RE: Shrink virtualbox dynamic drive
you should detach both drives from the VM first after the cloning is complete and the VM is shutdown, then attach only the newly cloned VDI to the primary master then restart the VM. This way you don't get any errors from VBox. Once you are happy with the new virtual disk you can delete the old vdi.
All times are GMT - 12 Hours
Powered by PNphpBB2
© 2003-2010 The Zafenio GroupCredits