Monthly Archives: June 2017

Hyper-V Compact VHD(X) Disk Task Taking Hours to Complete in GUI

The Scenario

I have a VM on my Windows Server 2012 R2 Standard with Hyper-V role. It has a dynamically expanding disk which I need to compact to reclaim disk space on the host.

The Problem

I used the Hyper-V Management console to compact the disk, but after several hours it’s still running. And because you can only compact a disk on a powered-off VM my business critical VM remains offline.

The Solution

In my case the compact process actually completed successfully within 30 minutes, it’s just the GUI had crashed even though it looked like it was still running normally (the green progress bar hadn’t quite reached the end). I found this out by look in the Event Logs:

Event Viewer > Applications and Services Logs > Microsoft > Windows > Hyper-V-VMMS > Operational log

Search for event ID 27301

“The system successfully compacted ‘:\Virtual Hard Disks\.vhdx’.”

Once I saw this I pressed cancel on the GUI compact window and restarted the Hyper-V management console. I was then able to successfully power-on my VM and the space had been successfully reclaimed.

I also noticed that the high disk activity that had been seen during the early stages of the disk compaction had completely stopped, however the above event log gave me the confidence to cancel the GUI.

NB To enable disk performance counter in Server 2012 R2 open an elevated command prompt and enter the following command “diskperf -y” then close/reopen the task manager window.

Disclaimer: provided “AS IS” with no warranties and confer no rights