Page 1 of 1

Shrink VM size?

Posted: 14. May 2014, 00:23
by bug-me-not
I have a 30 GB Dynamically sized VM. From within the OS, it says that it's using 2.7GB. However when I exported the appliance, it was over 5GB. There are no snapshots, so I am not sure where all of the extra space is used. Can someone tell me how I can shrink/resize the VM?

Re: Shrink VM size?

Posted: 14. May 2014, 00:32
by Perryg
VirtualBox does not support shrinking a guests hard drive. You would need a third party program like gParted, but be sure you backup the guest before you start.

Re: Shrink VM size?

Posted: 14. May 2014, 11:20
by mpack
"Inside the OS" does not tell you how much disk space is used, it only tells you how much of that space is occupied by undeleted files. Deleted files, swap files, partition maps, boot sectors and boot partitions etc etc will not be included in that tally.

Re: Shrink VM size?

Posted: 14. May 2014, 17:16
by bug-me-not
mpack wrote:"Inside the OS" does not tell you how much disk space is used, it only tells you how much of that space is occupied by undeleted files. Deleted files, swap files, partition maps, boot sectors and boot partitions etc etc will not be included in that tally.
I see. In this case the OS is Windows XP. It sounds like you're saying that anything I need to do would have to happen within the guest & not by Virtualbox.

Thank you both!

Re: Shrink VM size?

Posted: 14. May 2014, 18:14
by mpack
Quite the opposite. SSD disks aside, a guest OS has no ability to delete data from a disk: that's just a misception which non technical users have. Think about what deleting data would mean at a sector level (the level VirtualBox is working at): i.e. if you were a hard disk controller, how would you know that such-and-such data on the drive is considered "deleted" by the user?

The function you want is called disk compaction. Compaction has to be done from outside the VM, using a tool which is aware that the disk is dynamic virtual (it won't work with fixed virtual), and which uses some convention to identify "deleted sectors". In the case of "VBoxManage modifyhd --compact" you first have to run a tool inside the guest (sdelete / zerofree) to zero fill all unused and deleted spaces - though this can't work on unpartitioned spaces. Or you can use CloneVDI, which can compact a drive without requiring any processing, but only supports a limited number of guest filesystems, specifically FATx, NTFS, EXTx and unpartitioned spaces.