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                  : 
  • This has nothing really to do about compression though? It's more about how to reduce the size of the VHD ;) – user238343 Oct 2 '14 at 16:50
  • What do you think a shrink is other than 'compressing' all the sectors on a disk that are empty? BTW did you actually read the question and answers, and not just the title? It basically describes the same thing you want, even if the OP choose an incorrect term for their subject. – Zoredache Oct 2 '14 at 16:55
  • Are you using the VHDX format on the virtual disk? There are ways to do it with VHD but it is a total kludge. – Rex Oct 2 '14 at 16:57
  • @Zoredache - actually, that is not what he is trying to do. He is trying to shrink the size of the actual vhd/vhdx file used by hyper-v. All the solutions in the post you linked to would require him to zip/gzip/compress the file using some other utility to produce an archive and not reduce the size of the actual VHD/VHDX file in use by Hyper-V – Rex Oct 2 '14 at 17:00
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.

  • Is copying the VHD to a NAS considered a backup option or do I need to do something more advanced to backup the VHD? -- I've tried to run the SHRINK option when doing a edit on the VHD but never seemed to shrink the drive. I guess maybe I will try VHDX – user238343 Oct 7 '14 at 12:28
  • Yes, it doesn't have to be a complicated backup solution. Just as long as you feel comfortable that you will be able to revert back to a known good state if you run into trouble. In this case a straight copy of the VHD would probably suffice (taken whilst the VM is offline). – Steve365 Oct 7 '14 at 13:09
  • @Steve365 It isn't clear to me from the documentation what exactly Resize-VHD is doing. Can you elaborate. Does it handle resizing the filesystem and partitions contained within the VHDX? What does it do if the filesystem isn't NTFS? – Zoredache Oct 8 '14 at 17:50
  • @Zoredache Yes it handles resizing the partitions, only if they're NTFS. If not, it will only expand the disk and leaves non-NTFS partitions alone... So exactly what you would expect. – Chris S Oct 13 '14 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy