Hyper-V compacting not working as expected

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

beekerc

New Member
Oct 25, 2017
1
0
1
123
I am running Hyper-V in Windows Server 2012 Standard Edition on a Dell 1950 (2 quad core XEON and 64GB RAM). I have one VM that i'm having a lot of issues with trying to recover space in it.

the VM OS is Windows Server 2008 and it's running Oracle 11g database (in case that matters).

the VHD is originally configured as a 350GB dynamically expanding drive. it runs fine but after a while i realized that 160GB is more than enough for this drive and wanted to free up the space for other VMs to use. to prep the re-partitioning i did the following....



turned off the paging file
ran disk cleanup
ran chkdsk /f
ran sfc /scannow
vssadmin delete shadows /all
ran windows defrag
ran Raxco Perfect Disk Defrag (defrag, consolidate free space, prep for shrink)

Then in Computer Management / Disk Management, i did a Shrink Volume and reduced the size to 160GB. this worked fine. so now i have 100MB for System Reserved / 160GB for the VM / 190 of Unallocated. Of that 160GB VM partition there's 88GB of actual data and the PerfectDisk picture shows that there is no data in at least the last 40% of the drive. after compaction, i expect the VHD to be no larger than 100GB.

When execute the Compact Disk in Hyper-V, it completes but the hard VHD is 333GB.

I to do it via the command line

Diskpart
select vdisk file=<vm.vhd>
compact vdisk

at this point, it reduces the VHD size to 250GB, which is better, but not good enough. When I look in Computer Manager it still shows a 350GB disk with a 160GB partition and a 190GB Unallocated partition.

what am i missing? at the very least, i'd expect the 190GB of unallocated space to go away and the resulting VHD to be no bigger than 160GB, but i can't even get that far.

thanks in advance

BeekerC
 

Marsh

Moderator
May 12, 2013
2,645
1,496
113
sdelete.exe been around forever.

I used it at least once a month.
Each patch Tuesday, I patch all my windows image ( Windows 8.1 , Windows server 2012r2 , Windows 10 , Window server 2016). Then I run sdelete.exe to zero out the unused space, then compact the vhd file.
After all done, I capture all 4 Windows image into my WDS/MDT server for PXE booot auto-deployment.

I been using selete.exe since Windows 7.
 

Evan

Well-Known Member
Jan 6, 2016
3,346
598
113
I use it to clean up my windows VM’s on my MacBook as the space is somewhat limited there. The fact you do it each patch Tuesday is dedication :)
 
  • Like
Reactions: Marsh