How to shrink VHDX

sglee
sglee used Ask the Experts™
on
Hi,

 I have a Hyper-V virtual machine "TS3" running Windows Server 2008 with 278GB space allocated, but only using 100GB of space.

So I wanted to shrink the VHDX size. When I ran "Shrink" option in Disk Mgmt.msc, I got an error "Access denied".

I tried different suggestions on Google, but to no avail. So I ran Disk2VHD in TS3 and it created 72GB VHDX file.
Then I created a new VM "TS3 - VHDX" using existing 72GB VHDX file. But when I fired up the new VM, it still shows that hard drive size is 278GB in "My Computer".

Furthermore, when I tried to shrink it using DiskMgmt.msc, I still get "Access denied"error.
I don't mind seeing 278GB in "My Computer" of the VM as long as real size of VHDX is till 72GB.

My objective is to reduce the VHDX file and free up overall hard drive space on HyperV server.
But I am curious why the VM would not display current HD size based on VHDX file size?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
It is thinly provisioned so although the VHDX is 72GB it can expand to the size you see in disk manager. Can you run shrink using diskpart.exe?

Author

Commented:
C Drive Usage TS3 VHDX created thru Disk2VHD@Andy,
Can you run shrink using diskpart.exe? --> can  you post some actual commands?
 As seen in the screenshots, TS3.VHDX file size matches the size of Used space in C drive within VM. Maybe it is the way it shows. As long as this VM does not take up 278GB, i am good.
Top Expert 2014
Commented:
That's exactly what you expect with thin provisioning, the storage (in this case Hyper-V) tells the OS the disk is full size but does not actually allocate physical space until data is written. If you were to copy a load of data to it or run defrag it will expand the VHDX file as needed.

Diskpart command to shrink is at https://docs.microsoft.com/en-us/windows-server/storage/disk-management/shrink-a-basic-volume
Philip ElderTechnical Architect - HA/Compute/Storage

Commented:
In the virtual machine open Disk Manager and right click on the last partition on that VHDX and Shrink. If possible, options will be given for the maximum and minimum amount the partition can be reduced.

Once done, on the host open Hyper-V Manager and click EDIT DISK in the right hand column, find the VHDX, and Shrink should be available.

Once the process is done, there should be space freed up on the host's partition the VHDX is sitting on.

Author

Commented:
@andyalder
Diskpart command did actually shrunk the disk size. Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial