Shrinking Virtualbox Hard Drives

Derived from these instructions on HowToGeek

In this tutorial we assume a linux host and a windows guest

  1. Clean up files

  2. delete winsxs:

  3. Clean up system files (search for “cleanup” in start menu)

  4. Turn off hibernate

    powercfg.exe -h off
  5. Turn off page file

  6. Turn off system restore

  7. find and delete shadow copies and backups:

  8. limit size for shadow copies: vssadmin Resize ShadowStorage /For=C: /On=C: /MaxSize=320MB

  9. delete winreaagent folder:

  10. defrag hard drive

    defrag c: /U /V

  11. write zeros to hard drive

    .\sdelete.exe c: -z   
  12. Find the virtual hard drive you want to shrink. In the host OS, type:

    VBoxManage list hdds
  13. Execute the shrink command

    VBoxManage modifymedium disk "/path/to/disk" --compact