I was looking to back up some VHD containers that I use to store files in Windows, and needed to trim one of them down before it would fit under the OneDrive 10 GB upload limit. Since it was a dynamically expanding VHD, just removing files from the container wasn’t sufficient to reduce the actual size of the VHD file. Once I was done, I needed to unmount the drive, and then compact it using the diskpart utility. Here are the steps I followed:
- Run the
diskpartcommand from a command prompt.
select vdisk file="path to VHD file".
attach vdisk readonly.
compact vdisk. This will compact the VHD file, and might take a little while.
- Finally, enter
detach vdiskand then
exit. This will detach the VHD file and exit diskpart.
Once this is done, your VHD size should be reduced to the minimum necessary to store the files within!