The Real Guide To Prepare To Shrink A Virtual Machine Linux Disk

My inexperience in Linux makes me spent one day on this point: how to zeroing free space in order to call a compact on disk file.

— Solution 1 —

You can create a file big as all free space filled with zeros and delete it, wow, yeah! great idea! but I have a virtual dinamic disk bigger than real phisical space available.

So no way.

— Solution 2 —

Other way is to use “zerofree”, so let’s open a terminal and let’s go ready with super user:

su root

install zerofree (thanks Ron Yorston):

apt-get install zerofree

reinit system:

init 1

remount disks in readonly mode because zerofree works only on readonly disks, my disk is /dev/hda1 (check it with “mount” command) and you have to declare filesystem type:

mount -n -o remount,ro -t ext3 /dev/hda1 /

zero free space:

zerofree /dev/hda1

…after hours and hours…   … and hours …

… and, but are you working or what? …    … and done! Yeahhhhhhh

Last simple step, reboot:

reboot

Done!

From linux host launch:

VBoxManage modifyvdi /mypath/mydisk.vdi compact

From win host launch:

VBoxManage.exe modifyvdi c:\mypath\mydisk.vdi compact

VN:F [1.9.15_1155]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.15_1155]
Rating: 0 (from 0 votes)

Leave a Reply