Goal – shrink my VDI using VirtualBox-provided tools
Important note (this will come into play later): I have VERY fast home-grown ZFS-based NAS/SAN that stores my VDI (and most other) files that I use on a regular basis. In most cases, this proves to be faster than running virtual machines off of my local disk.
I wanted to compact my Sun (now Oracle) VirtualBox vdi file. The vdi file was created with version 3.2.12r68302 of VirtualBox, and was a clean, patched base install of Windows 7 that I wanted to compact as much as possible. After reviewing the user’s manual that comes with the product (C:Program FilesOracleVirtualBoxdocUserManual.pdf), page 99 gave me the command line to use (vboxmanage.exe modifyhd –compact file.vdi), and page 116 references the sdelete tool from Microsoft required to zero out blank space. After deleting unnecessary files, deleting system restore points, emptying recycle bin, etc., I ran the sdelete tool (which took about 2 hours), then shut the machine down. So far, so good. Now it was time to run the “vboxmanage.exe modifyhd –compact” command, which presented a problem that most people probably won’t run into.
Symptom
C:Program FilesOracleVirtualBox>VBoxManage.exe modifyhd –compact y:Base_OS_Installswin7base.vdi
Oracle VM VirtualBox Command Line Management Interface Version 3.2.12
(C) 2005-2010 Oracle Corporation
All rights reserved.
ERROR: Could not find a hard disk with location ‘y:Base_OS_Installswin
7base.vdi’ in the media registry (‘C:Userspalermo/.VirtualBoxVirtualBox.xml’)
Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
Context: “FindHardDisk(Bstr(FilenameOrUuid), hardDisk.asOutParam())” at line 430
of file VBoxManageDisk.cpp
Resolution
Apparently when you add a vdi file to the media registry, it expands mapped drives to the UNC name. Using the UNC name instead of the mapped drive letter fixed the problem:
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
This took my VDI file from 12.4GB to 8.4GB. Still big, but almost 33% less than its original size.