2

I have a Windows Server 2008 R2 with Hyper V installed.

One of the virtual machines is a 150GB dynamically expanding virtual hard disk (Windows). I would like to shrink this to 100GB, however I can't seem to achieve this.

What I have tried so far;

  • opened disk management on guest machine and shrunk the HDD by 50GB, this is now displaying as 'unallocated' in the guest.
  • ensured there are no snapshots of the guest OS
  • defragmented the guest machine
  • selected the guest machine in Hyper V and ran 'compact'

However whenever I inspect the disk in Hyper V it's still showing as 150GB, there's no change.

I have also tried the diskpart tool, using the following commands on the guest OS however same result;

select vdisk File=”I:\path\to\your.vhd”
attach vdisk readonly
compact vdisk
detach vdisk

Am I missing something?

Few questions;

I've read that it's not possible to shrink dynamically expanding virtual hard disks- is this true? If I simply delete the VM in Hyper V, where will the 150GB be reallocated to?

I'm unable to export the VM and create a new one as my host machine is very low on space.

1

According to this article;

The VHD virtual disk format doesn’t support shrinking..

I tried the exact same steps for a long time and never had any success. Best to recreate the virtual disk if possible, save some time.

0

You can shrink Dynamically expanding virtual hard disks. you've shrunk the volume in the guest already so from PowerShell try:

Resize-VHD –Path c:\BaseVHDX.vhdx –SizeBytes 1TB (1TB is just an example)

or

Resize-VHD –Path c:\BaseVHDX.vhdx –ToMinimumSize

if it is a .VHD then use .VHD instead of .VHDX

  • This Cmdlet should be part of the Hyper-v Powershell tools, are you running it on a hyper-V machine? – Michael Brown Jul 3 '17 at 13:19
  • I have hyper-v installed on a win server 2008 R2 machine. I ran the command in powershell (v2) as administrator. – TheOrdinaryGeek Jul 3 '17 at 13:28
  • in that case id recommend installing the latest WMF version in order to upgrade PowerShell. you can find it here powershellgallery.com ill keep looking to see if there is an alternative to the Resize-VHD command for PowerShell V2 – Michael Brown Jul 3 '17 at 13:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.