4

I have Ubuntu Server 10.04 TLS installed on a Virtual Machine in a VirtualBox. The size of the Hard Drive is dynamic growing hard drive and the maximum is 32GB. At the beginning i had 4GB on the Hard Drive and the size of the .vdi was 4GB. Lately the size of data on the disk is 15GB but the size of the .vdi is almost 32GB.

Why is that?

How can i pack / optimize / defrag the HD so it will be the same size of the data on the disk?

Thanks.

2 Answers 2

4

The reason is that the dynamic disk stores all data, even data that was just temporary and now unlinked. The VBoxManage executable has a command, modifyvhd, which can perform compaction of hard disk images:

VBoxManage modifyhd Ubuntu.vhd --compact

This should get you back down close to the 15GB file size, and might even give you a small performance boost (less data to read / search through). If you really want to optimize the disk you can start by writing zero to the free space, then compacting. This will force the filesystem to free up any blocks that might still be held.

cat /dev/zero > zero ; sync ; rm zero

Additional reference: http://www.virtualbox.org/manual/ch08.html - see the modifyvhd section, specifically the --compact option.

0

You could use Clonezilla to clone the disk to an new VDI. I've used it successfully recently for Linux & WIndows volumes. I can't say for certain that it will recoup the space but there is no garm in trying.

  • Use VBox to create a new volume
  • Attach volume to vm
  • Boot to Clonezilla Live CD
  • Clone current disk to new
  • after verifying results, remove original, and new disk to same attachpoint
  • Boot vm and test

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .