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 Unused programs

  3. delete winsxs: https://helpdeskgeek.com/windows-11/what-is-the-winsxs-folder-why-is-it-huge-and-how-to-cleanup/

    DISM.exe /Online /Cleanup-Image /AnalyzeComponentStore
    DISM.exe /Online /Cleanup-Image /StartComponentCleanup
    Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
    
  4. Clean up system files (search for “disk cleanup” in start menu)

  5. Turn off hibernate

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

  7. Turn off system restore

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

    control panel –> recovery –> config disable system protection

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

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

    vssadmin Resize ShadowStorage /For=C: /On=C: /MaxSize=20% vssadmin list shadowstorage /for=c: vssadmin list shadows /for=c: vssadmin delete shadows /for=c:

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

  11. Delete / shrink serviceprofiles directory

    https://superuser.com/questions/1635577/can-i-delete-files-from-c-windows-serviceprofiles-networkservice-appdata-local

    netsh branchcache flush
    
  12. Remove edge: https://www.lifewire.com/uninstall-microsoft-edge-4156669

  13. defrag hard drive

    defrag c: /U /V
    

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

  14. write zeros to hard drive

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

    VBoxManage list hdds
    
  16. Execute the shrink command

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