Shrinking linux .vdi (convincing host fs to claim real size, not more :-) ) in Virtualbox

Maybe you know it – virtual linux machine is used for anything (installing Oracle for example) – and its size says something about 12GB /df -h/ – what a surprise that your host OS is allocating around 25GB and still wants more, more, MORE!!! 🙂

There are two common ways how to zero-ing unused space: use dd utility or specialized one – as zerofree. Inmortal dd is slow – zerofree is intelligent = I have just ONE choice 🙂 Main point = target file system should be mount as read only.

 

1st phase – guest

As I´m lazy and create default layout still the same (one 2TB partition + swap), it looks like a problem to  mount it as read only. SystemRescueCd is a free live distribution where zerofree is located. After booting this distribution from virtual machine (CD mount through menu), you will just need to set your device id:

015

And that´s all 🙂 Just wait for finishing. It can take demanding time according your disk usage and size of disk. In my environment with around 12GB used, 2TB disk it took around 2 hours to complete it.

016

 

2nd phase – host

If you are using vmdk, not vdi, you have to convert this file /compact is functional only for .vdi/. In my case:

VBoxManage clonehd –format VDI U:\vmware\Ora65_Ora1124\Ora65-clean-disk1.vmdk U:\vmware\Ora65_Ora1124\Oracle11204.vdi

Then you really perform compacting virtual machine on host side:

VBoxManage.exe modifyhd U:\vmware\Ora65_Ora1124\Oracle11204.vdi compact

Done.

-a-

This entry was posted in Linux, Virtualbox. Bookmark the permalink.

Napsat komentář