2

I have a Hyper-V server running on WS2012. I have a Windows 7 running as a dynamic disk. I delete files and more from within to attempt to save disk space and reduce the size. However, the size does not shrink even after I turn it off and run a shrink on the VHD.

Do I need to do something else that will allow me to shrink the VHD so that I can keep the VM from crashing due to a lack of disk space?

EDIT: I also mounted the disk and ran DEFRAG: E: /V /X to defrag the disk in hopes that I could compact the .VHD but the size still remains over 30GBs over the actual used space inside the drive.

Do I need to 0 out the empty space for a VHD before running the shrink option from Hyper-V?

Running out of disk space: enter image description here

VHD: enter image description here

Disk inside the VHD:

enter image description here

PS C:\Users\Administrator> get-vhd

cmdlet Get-VHD at command pipeline position 1
Supply values for the following parameters:
Path[0]: X:\NAME.VHD
Path[1]:


ComputerName            : NAME
Path                    : X:\NAME.VHD
VhdFormat               : VHD
VhdType                 : Dynamic
FileSize                : 86707423744
Size                    : 256060514304
MinimumSize             : 256059113472
LogicalSectorSize       : 512
PhysicalSectorSize      : 512
BlockSize               : 2097152
ParentPath              :
FragmentationPercentage : 16
Alignment               : 0
Attached                : False
DiskNumber              :
IsDeleted               : False
Number                  : 

1 Answers1

2

Native support for shrinking Hyper-V virtual disk files was introduced with Windows Server 2012 and the new VHDX file format. If you are using the legacy VHD format then you will need to convert the file to VHDX first.

Before you begin, if possible ensure you have a good backup. You shouldn't need it, but it's always sensible.

Both of these operations can be carried out using the Hyper-V manager UI. The virtual machine must be shutdown first; these operations can't be carried out online. Select the VHD and choose 'edit'. The resulting wizard has both a convert option and a shrink option. Run the wizard once to convert and then again a second time to shrink the new VHDX.

You can also perform the same using Powershell using cmdlets Convert-VHD and Resize-VHD.

You can find a good step by step on this page;

http://www.techrepublic.com/blog/data-center/working-with-and-resizing-windows-server-2012-vhds/

I should add that there is generally no downside to converting to VHDX; it is a more modern, scalable file format with a host of benefits (brief summary on Technet here: http://technet.microsoft.com/en-gb/library/hh831446.aspx). However, if you wish to convert back to a VHD after performing the shrink process then you can do so; it is a fully reversible operation.

I hope that helps.

Steve365
  • 1,273