Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reduce vagrant box storage (vmdk) size

I created initialized vagrant from ubuntu/trusty64 on Windows host. I realized newly created virtualbox's disk size is set to 40GB. I want to reduce this to at least 10GB. Is there any way to do this?

although right now actual size is 1.19GB i don't want it's virtual size to be this big.

thank you!

like image 628
ganni Avatar asked Sep 11 '14 05:09

ganni


2 Answers

You can try to do it by

  1. zero-out disk space within the vm by running

cat /dev/zero > /path/to/fill/z; sync; sleep 3; sync; rm -rf z

NOTE: Delete unwanted files within the VM before running the command above. If you have multiple partitions, logical volumes, do it on each of them.

  1. compact / shrink the virtual disk (this works fine with VDI format, but not sure about VMDK, you can try)

VBoxManage modifyhd --compact /path/to/vdisk.vmdk

You'll see the progress, once finished, check its size.

Update: If you want to resize the virtual disk, you should use VBoxManage modifyhd --resize <megabytes> /path/to/vdisk.vmdk.

NOTE: The size of the virtual disk doesn't matter too much, it is just like a cap (max size) of the virtual disk image it can grow up to. By default the VMDK should be dynamically allocated, which mean the vmdk size will be close to the amount of data within the VM. The above method will help to reclaim spaces that has been freed up within the guest.

IMPORTANT: Growing the size of the vdisk is OK, but when reducing/shrinking you should be very careful, there is risk of losing data the new size < the actual data size within the vdisk.

like image 196
Terry Wang Avatar answered Oct 22 '22 23:10

Terry Wang


On linux you can try using qemu-img resize filename [+|-]size

like image 36
Maxym Avatar answered Oct 22 '22 23:10

Maxym