2

Trying to recover ~450GB unallocated space from a VHDx total filesize. Thanks for taking a look at this issue:

  • Hyper-V Server 2012.
  • Dynamic VHDx (we'll call it disk2.vhdx) with a file size of 1.5TB out of a maximum 2TB, does not contain Operating System, no Shadow Copies enabled.
  • On the VM with disk2.vhdx attached, I've shrunk the previously 1.5TB partition to be 1.05TB, freeing up about ~450GB of space now listed as unallocated in the VM.
  • The filesize for the VHDx still lists 1.5TB, we need to recover that 450GB on the Hyper-V host as it's nearing capacity.

Steps I've Taken:

  • Defragged every drive on the VM.
  • Turned VM off, used GUI compact, no results on any of the disks.
  • Used Powershell Optimize-VHD -mode full & quick, full resulted in a longer compact time but end result was no free'd space.
  • Using the Hyper-V Disk Management Wizard, there is no Shrink option even after shrinking the partition from within the VM.
  • We can simply mount the drive sucessfully with the following command (the disk is also working fine in the VM):

    mount-vhd F:\disk2.vhdx

  • Attempting to Mount the VHD to pull info & manually resize it returns an error stating unable to 'get-disk' as there's no partition table or it's corrupt:

    mount-vhd F:\disk2.vhdx -passthru | get-disk | get-partition | get-volume

  • Manual resize returns the same thing for both MinSize and SetBytes:

    resize-vhd F:\disk2.vhdx -ToMinimumSize

Here's what get-vhd returns:

ComputerName            : XXXX
Path                    : F:\Disk2.vhdx
VhdFormat               : VHDX
VhdType                 : Dynamic
FileSize                : 1572935303168
Size                    : 2147483648000
MinimumSize             : 
LogicalSectorSize       : 512
PhysicalSectorSize      : 4096
BlockSize               : 33554432
ParentPath              : 
FragmentationPercentage : 1
Alignment               : 1
Attached                : False
DiskNumber              : 
IsDeleted               : False
Number                  : 

As you can see there is no Minimum Size.

I would attempt to create a new fixed VHDx with the proper size and migrate the data over, but unfortunately we're very low on space so 1.5TB is an issue. Any ideas on how to recover the 450GB of unallocated space back from the VHDx file size to make it a 1TB drive?

I've also attempted to convert disk2.VHDx to a VHD and use the third party tool VHDResizer, but it eats up the remaining disk space before it can complete the transition to vhd. Could this work if it were a VHD? I could look into transferring the VHDx off of the server onto one with more space to complete the conversion and test VHDResizer, I have no experience with the tool so I'm unsure if it's worth the attempt.

Thanks, appreciate any and all ideas.

TSga
  • 21
  • 3
  • Have a look at; https://serverfault.com/questions/962203/hyper-v-vhdx-file-is-much-larger-than-the-contents – Dennis Apr 11 '19 at 15:40

1 Answers1

1

Maybe you can shrink the VHDx file directly from inside your virtual machine, by using TRIN/UNMAP from your guest.

Simply try recreating a new partition inside your guest's free space, and format it. If all stars align correctly, it will free a significant amount of space, returning it to the host OS.

Please note that the file will appear to have the same size as before, but total free disk space should nevertheless increase.

shodanshok
  • 44,038
  • 6
  • 98
  • 162