Monday, July 13, 2009

How to Compact Virtualbox vdi

Abstract: a memo on how to compact virtualbox vdi files.

VirtualBox comes with a utility to compact vdi files which drops zero block. So the problem is how to write zero to unused blocks. If you have a windows guest, run the following command in cmd:

sdelete -c

If you have a linux guest, run this:

cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

And in the host run:

VBoxManage modifyvdi harddisk.vdi compact

These may reduce the size of vdi files considerably if it has been used for a long time.

2 comments:

  1. Where do I run "VBoxManage modifyvdi harddisk.vdi compact"? Please answer =)

    ReplyDelete
  2. Where you have harddisk.vdi but you got to put the directory that holds "VBoxManage.ext"(win) iin your PATH environmment variable.
    On windows platform with the latest vbox, you would want to run "C:\Windows\Program Files\Oracle\VirtualBox\VBoxManage modifyvdi harddisk.vdi compact"; while on *nix, I think the binary is already in your PATH, so you can just run the command without any problem.

    ReplyDelete