Thursday, February 14, 2013

Fast way to shrink VMWARE image

I am sure everyone noticed that when using a repository inside the VM the size of the VM on disk
keeps growing even when you delete branches or get rid of old Android repo like 2.3 and focus on the good
stuff Android 4.2 and work against the fragmentation of Google Android Platform where migration is key :)
To get more disk space, the key is to compact the VM once in a while.

The slow way

Normal commands for Linux VM are

1. Inside of VM-- $ sudo vmware-tools
a. Select “shrink” tab
b. Select “/” folder
c. Hit “shrink” button and enjoy the process
d. Repeat the same for “/boot” folder and for any other folders you might have there
2. Shutdown VM completely
3. From VMware menu find “Settings->Hardware->Hard Disk->Utilities->Defragment”
4. From VMware menu find “Settings->Hardware->Hard Disk->Utilities->Compact”

Now the fast way :

For Linux VM

In the VM, in a Terminal make sure you become root (sudo bash) and then copy and paste the following command, as is,
and then press Enter:

dd if=/dev/zero of=wipefile bs=1024x1024; rm wipefile

Wait for the command prompt to return and then shutdown the VM and then from the Virtual Machine Settings for the
Hard Disk select the Compact command from the Utilities button.

You’ll be able to spare a couple of Gigabyte !!

We are talking at least of a 2X gain easy.. I didn't benchmark yet because I am impatient to use the fast way only!
On Windows

Assuming the VMware virtual disk is not pre-allocated and the Filesystem is ext4 you will have to
manually prepare it to be shrunk. When Windows deletes a file, it doesn’t actually delete the data on the disk,
it just deletes the references/pointers in the file allocation tables. So when “shrink” is processing a vmdk and
is looking at the raw disk, it is seeing values that aren’t empty (non-zero) and export them as such.
So before doing a Shrink, use a really cool command line tool developed by Mark Russinovich SDelete.
Simply execute SDelete with parameter –c inside running Virtual Machine, then shut down the Guest
and do a Shrink

No comments: