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: https://helpdeskgeek.com/windows-11/what-is-the-winsxs-folder-why-is-it-huge-and-how-to-cleanup/

  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

    https://www.howtogeek.com/5482/make-system-restore-use-less-space-in-windows-7/

  7. find and delete shadow copies and backups: https://superuser.com/questions/1746099/system-volume-information-folder-huge

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

  9. delete winreaagent folder: https://www.majorgeeks.com/content/page/what_is_the_winreagent_folder_and_can_i_delete_it.html

  10. defrag hard drive

    defrag c: /U /V
    

    https://www.partitionwizard.com/clone-disk/optimization-not-available.html

  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