Wednesday, March 2, 2011

Compacting/Shrinking virtual disk image...

Working on virtual machine with dynamic virtual disk gives an advantage to those with limited disk space. But after using it for a while (install/uninstall/copy/paste/delete), the actual size of your virtual disk image may have grown to nearly defined size, guest system reported that the disk usage was less than the size reported on host system. It should be fine provided if you have larger disk space. However, if that's not the case, than the best option would be to compact (known as shrink in VMWare) the virtual disk image.

In general, 3 steps are required to achieve this task
1) Disk cleanup / Defrag the hard drive on guest system

2) Execute "sdelete -c" to zero the free disk space before compressing the virtual disk image (sdelete tool was provided by Microsoft) on guest system
> sdelete -c [drive letter]
3) Compact the virtual disk image

VirtualBox user
Execute VBoxManage command on host system
$ VBoxManage modifyhd [filename] --compact
VMWare user
Shrinking needs to be done on guest system. Complete the first two steps above then:
1) Open VMWare tools by right click VM icon in system tray

2) Go to Shrink tab, under supported partitions, check the mount point checkbox

VMWare Tools Properties


3) Click "Prepare to shrink" and once ready, click "Yes" to proceed

Preparing shrink process


Ready to go


Shrinking in progress


If everything working as expected, virtual disk usage on both guest and host should be ~same

Note:
Test environment
Host: Linux Mint 10 64-bit
VirtualBox guest: Windows Server 2003 32-bit
VMWare guest: Windows 7 Profesional 64-bit

No comments:

Post a Comment