Terry : VirtualBox Tips

VirtualBox Tips

Compact (Shrink) the VDI

To reduce VDI side, zero out free space for all partitions/virtual HD (VirtualBox does NOT automatically reclaim the disk space after deleting files within the VM)

cat /dev/zero > z;sync;sleep 3;sync;rm -f z

Compact the VDI file

VBoxManage modifyhd /path/to/vm.vdi --compact

Ubuntu 10.04 LTS.vdi 2.56GB => 2.2GB.

In addition, the modifyhd --compact command can be used to compact disk images, i.e. remove blocks that only contains zeroes. For this operation to be effective, it is required to zero out free space in the guest system using a suitable software tool. Microsoft provides the sdelete tool for Windows guests. Execute sdelete -z (-c does NOT seem to work any more in sdelete v1.6 and above, -z is for virtual disk optimization) in the guest to zero the free disk space before compressing the virtual disk image. Compaction works both for base images and for diff images created as part of a snapshot.

Reference => VBoxManage modifyhd

Clone VM

Clone is required when copying VM from 1 machine to the other, clonehd will generate new UUID for the vdi file.

VBoxManage clonehd source.vdi destination.vdi

Internal Commands

terry@tux:~$ VBoxManage internalcommands
Oracle VM VirtualBox Command Line Management Interface Version 4.2.14
(C) 2005-2013 Oracle Corporation
All rights reserved.
Usage: VBoxManage internalcommands <command> [command arguments]
  loadmap <vmname>|<uuid> <symfile> <address> [module] [subtrahend] [segment]
      This will instruct DBGF to load the given map file
      during initialization.  (See also loadmap in the debugger.)
  loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]
      This will instruct DBGF to load the given symbol file
      during initialization.
  sethduuid <filepath> [<uuid>]
       Assigns a new UUID to the given image file. This way, multiple copies
       of a container can be registered.
  sethdparentuuid <filepath> <uuid>
       Assigns a new parent UUID to the given image file.
  dumphdinfo <filepath>
       Prints information about the image at the given location.
  listpartitions -rawdisk <diskname>
       Lists all partitions on <diskname>.
  createrawvmdk -filename <filename> -rawdisk <diskname>
                [-partitions <list of partition numbers> [-mbr <filename>] ]
       Creates a new VMDK image which gives access to an entite host disk (if
       the parameter -partitions is not specified) or some partitions of a
       host disk. If access to individual partitions is granted, then the
       parameter -mbr can be used to specify an alternative MBR to be used
       (the partitioning information in the MBR file is ignored).
       The diskname is on Linux e.g. /dev/sda, and on Windows e.g.
       On Linux or FreeBSD host the parameter -relative causes a VMDK file to
       be created which refers to individual partitions instead to the entire
       The necessary partition numbers can be queried with
         VBoxManage internalcommands listpartitions
  renamevmdk -from <filename> -to <filename>
       Renames an existing VMDK image, including the base file and all its extents.
  converttoraw [-format <fileformat>] <filename> <outputfile>
       Convert image to raw, writing to file.
  converthd [-srcformat VDI|VMDK|VHD|RAW]
            [-dstformat VDI|VMDK|VHD|RAW]
            <inputfile> <outputfile>
       converts hard disk images between formats
  repairhd [-dry-run]
           [-format VDI|VMDK|VHD|...]
       Tries to repair corrupted disk images
  debuglog <vmname>|<uuid> [--enable|--disable] [--flags todo]
           [--groups todo] [--destinations todo]
       Controls debug logging.
  passwordhash <passsword>
       Generates a password hash.
WARNING: This is a development tool and shall only be used to analyse
         problems. It is completely unsupported and will change in
         incompatible ways without warning.
Syntax error: Command missing


VirtualBox User Manual