Skip to content

Instantly share code, notes, and snippets.

@omidkrad
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omidkrad/ca686af1fe43209395d6 to your computer and use it in GitHub Desktop.
Save omidkrad/ca686af1fe43209395d6 to your computer and use it in GitHub Desktop.
Steps to compact a Virtual Hard Disk

Steps to compact a Virtual Hard Disk

From inside VM (guest):

  1. Disk Cleanup -> Cleanup system files
  2. Turn off VM

From outside VM (host):

  1. Attach VHD as a drive (for example V:)
  2. Delete pagefile.sys and swapfile.sys if you don't want them to be in the parent VHD. They will be created again in the child VHD when Windows starts.
  3. defrag V: /h /u /v /x
  4. sdelete -s -z V:
  5. Detach VHD
  6. Optimize-VHD $vhdx_file -Mode full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment