Hyper-V cannot keep VHDX compact

Fabio Cavallero 1 Reputation point
2022-10-02T09:18:36.747+00:00

Hi. we have a server with a dynamic expansion VHDX. 300GB of data, 1TB of vhdx. It's 2 days than I turned off the VM and I'm working to shrink it (defrag, defraggler, defragging free space, 0 fill free space and so on. But some clusters cannot be moved and I don't have enough free space to move data on other VHD. But I also think that this is a stupid thing to do.

Ok... We sovrastimated the server use (the crisis didn't help). anc whe moved 2 other VM from another deading server, so we reached less than 10gb of free space on phisical server

But, why don't you insert an option, a flag, something on VHDX that can manage it, something like "keep VHDX compact" to force the file writing at he beginning of the virtual disk and keep the VHDX as small as possible? I'ts stupid loosing hours switching off servers for compacting VHDX

Windows for business | Windows Client for IT Pros | Storage high availability | Virtualization and Hyper-V
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,926 Reputation points
    2022-10-06T08:13:01.903+00:00

    Hi

    Thank you for posting your query.

    Kindly the details provided below to answer your query.

    1. NTFS puts a secondary copy of the MFT at the exact center of a partition. This means you won't be able to compact more than 50%. All compaction does is truncates any zero filled disk clusters it can find starting at the end of the disk.
    2. This is plausibly because Hyper-V will only compress the first partition, which is that "System Reserved" one. You just need to shut-down the VM, mount the .VHD(X) file as drives, then compact them individually.

    Turn off the VM

    run "DiskPart"

    C#
    DISKPART> select vdisk file="J:\Virtual Hard Drives\<filename>.vhdx"
    DiskPart successfully selected the virtual disk file.
    DISKPART> attach vdisk readonly
    100 percent completed
    DiskPart successfully attached the virtual disk file.
    DISKPART> compact vdisk
    100 percent completed
    DiskPart successfully compacted the virtual disk file.
    DISKPART> detach vdisk
    DiskPart successfully detached the virtual disk file.
    Oddly enough, you then go into the Hyper-V manager and use THAT compress feature, and it seems to work properly.

    Go to this link for your reference https://community.spiceworks.com/topic/2077033-compacting-vhd-not-working-in-hyper-v

    Note: This is a non-Microsoft website kindly take precautions before downloading anything.


    If the answer is helpful kindly click "Accept as Answer" and upvote it. Thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.