Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My computer is running on Windows 7 64-bit. I used Disk Management to create a new VHD file and made it into a new virtual drive. The size of the disk is 8GB. After using about 3GB, I decided to format it. However after formatting the size of the disk is still 3GB.

I tried diskpart to compact this VHD file and I got this error message

Virtual Disk Service error: The requested operation requires that the virtual disk be attached read only.

So, is there any way to compact this VHD file?

share|improve this question
Try unmounting the disk before compacting it... – Graham Wager Oct 29 '12 at 9:14
Where is that option to unmount the disk? – Teiv Oct 29 '12 at 9:16
Inside Disk Management, right-click the Disk (not the volume) and there should be an Unmount or Eject option in the menu – Graham Wager Oct 29 '12 at 9:18
I don't see that option, only "Detach VHD", here is the screenshot – Teiv Oct 29 '12 at 9:26
That's the one, Detach VHD, then follow the instructions here: – Graham Wager Oct 29 '12 at 9:36
up vote 7 down vote accepted

Compacting can't be completed on a VHD that is attached unless it is read-only.

To detach the disk, you need to right-click the VHD disk in Disk Management and select Detach VHD:

Detach VHD

You can then complete the compacting using diskpart from a Command Prompt:

  1. Run diskpart
  2. Select the disk via its path: select vdisk file="<path>"
  3. Attach it as read-only: attach vdisk readonly
  4. Compact it: compact vdisk
  5. Upon completion of the compact, detach it again: detach vdisk

You can then re-attach it via Disk Management in its normal and newly compacted state.


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .