Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
Try unmounting the disk before compacting it... –  Graham Wager Oct 29 '12 at 9:14
    
Where is that option to unmount the disk? –  user433531 Oct 29 '12 at 9:16
1  
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 i.imgur.com/OyH1C.png –  user433531 Oct 29 '12 at 9:26
1  
That's the one, Detach VHD, then follow the instructions here: linhost.info/2011/01/windows-how-to-compact-a-dynamic-vhd –  Graham Wager Oct 29 '12 at 9:36

1 Answer 1

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.

(Reference: http://linhost.info/2011/01/windows-how-to-compact-a-dynamic-vhd/)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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