Pages

Subscribe:

Ads 468x60px

Labels

Sunday, June 9, 2013

Shrinking a VirtualBox VDI image

Mac is starting to complain about the lack of disk space. Searching around and i noticed that a very huge VDI image takes up 35G of space. And this VDI image is from a guest Windows XP operating system which is used for development work. The amount of disk space in the guest system reports only the usage of 15G. But the VDI image size is over 35G, a wastes of 20G! It should be reduced, but how!?
Google does it work well. And i quickly find the commandline tool VBoxManage that comes with VirtualBox, but it is not as trivial to use. From the man page, it says something like this

VBoxManage modifyvm /path/to/image.vdi --compact

But of course, this does not work, complaining:

VBoxManage: error: Cannot register the hard disk '/path/to/image.vdi' {0bb60115-3e8c-4a52-b825-229166ec0c84} because a hard disk '/path/to/image.vdi' with UUID {0bb60115-3e8c-4a52-b825-229166ec0c84} already exists

VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 210 of file VBoxManageDisk.cpp

What? line 210 of a c++ program has problem? That takes me google more and more pages to find the solution.

Here is it finally my steps to shrink.
  1. Defrag the Guest OS. In windows, one can use the built-in defragmentation tool to do the task. I do it a few times to move all files to the front.
  2. Set all the empty space to null. I use this tool http://www.feyrer.de/g4u/nullfile-1.02.exe. Put it in c:\ and run it. Some pages suggest to use sdelete from sysinternals. But it doesn't work for me.
  3. Run the command VBoxManage to compact it.  VBoxManage modifyhd {0bb60115-3e8c-4a52-b825-229166ec0c84} --compact
  4. Done!
Note that I use the uuid instead of the path, i don't know why but only using uuid works. 








0 comments:

Post a Comment