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. empty all recycle bins

    Clear-Recycle-Bin -Force
    
  4. 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
    
  5. Clean up system files (search for “disk cleanup” in start menu)

  6. Turn off hibernate

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

  8. 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

  9. find and delete shadow copies and backups:

  10. limit size for shadow copies:

    #vssadmin Resize ShadowStorage /For=C: /On=C: /MaxSize=320MB
    vssadmin list shadowstorage /for=c:
    vssadmin list shadows /for=c:
    vssadmin delete shadows /for=c:
    vssadmin Resize ShadowStorage /For=C: /On=C: /MaxSize=1%
    
  11. delete winreaagent folder: https://www.majorgeeks.com/content/page/what_is_the_winreagent_folder_and_can_i_delete_it.html

  12. Delete / shrink serviceprofiles directory

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

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

  14. defrag hard drive

    defrag c: /U /V
    

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

  15. write zeros to hard drive

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

    VBoxManage list hdds
    
  17. Execute the shrink command

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