Unable to Compact a VHD Due to a File System Limitation Explained

Thursday, June 24, 2010

You may get the following error when attempting to compact a Hyper-V virtual hard disk (VHD):
The system failed to compact disk.vhd. Error Code: The requested operation could not be completed due to a file system limitation
This can be happen for several of reasons. 
  1. Windows Server 2008 R2 does not support hosting VHDs on compressed NTFS volumes. See the article, Virtual Hard Disk (VHD) Architecture Explained.
  2. The NTFS volume where the VHD resides is very heavily fragmented.  See Microsoft KB967351.
Both of these scenarios are fairly well explained, but I also came across another reason this can happen.  You cannot compact a VHD where the VHD contains a VSS backup.

The VHD in question was an Exchange 2010 data volume where I had run an Exchange-aware VSS backup using the native Windows Server Backup utility.  See my article, How to Backup Exchange 2010 RTM at Release Timeframe.

In order to compact the VHD, all VSS shadows must be deleted from the VHD volume within the VM.  This can be done by running the vssadmin utility, as such:
vssadmin delete shadows /all
Now you can compact the VHD to reduce the physical size of the VHD file and regain space on the Hyper-V host.

21 comments:

  1. That's it! Thanks for solving my problem.

    ReplyDelete
  2. I removed my shadow copies and it worked! Excellent solution - thank you!

    ReplyDelete
  3. It works perfect for me!!
    Thank you, thank you, thank you!!!

    ReplyDelete
  4. Thanks! Deleting shadow copies saved me too.

    Blogged: Hyper-V Failed to Compact VHD.

    ReplyDelete
  5. If the VM is Vista - disable the "System Restore" feature to delete the VSS backups since vssadmin can't do it in this scenario.

    Thanks for this article - VSS backup in the guest (as a system restore point) was my issue as well!

    ReplyDelete
  6. great thanks. that just worked for me. I'm using Windows 2003 VHD.

    ReplyDelete
  7. That did the trick for me too, thanks!

    ReplyDelete
  8. Worked for me too. And I can see the logic behind it is that way. Thanks

    ReplyDelete
  9. Thanks for the hint that this was caused by VSS backups. Mine couldn't even be removed using vssadmin, and I had to resort to the diskshadow tool, but I got there in the end.

    ReplyDelete
  10. Thanks Jeff. In my case it was VSS shadow copies on the partiton, a SBS 2008 box. Following your instructions did the trick. Great blog BTW.

    ReplyDelete
  11. Thanks for posting this, solved my problem as well!

    R.

    ReplyDelete
  12. Thanks! That worked!

    ReplyDelete
  13. This saved my day! Winows 7 x64 / Windows Server 2008 R2 x64!

    ReplyDelete
  14. Excellent post!

    The following is added to lure Google users here for a good answer:

    Compacting a VHD of Windows 7 can fail "due to a file system limitation" because of System Restore.

    Boot back into your VHD - turn off System Restore - and try again.

    ReplyDelete
  15. Fantastic!!!
    Works fine!!!

    ReplyDelete
  16. Disabled shadow copy - and it worked!
    OS is Windows 2008 R2 + SP1.
    Big thanks from Canada.

    ReplyDelete
  17. worked - thank you!

    ReplyDelete
  18. Thanks, it worked
    Ravi Luchmun

    ReplyDelete
  19. Saved me a ton of time, thank you.

    ReplyDelete
  20. Just thought I'd say that if you have a problem removing the shadows using vssadmin, try using the diskshadow command instead. It seems to remove problem shadows that vssadmin won't remove.

    ReplyDelete
  21. Things just don't work straigthforward anymore these days :-(
    Thx.

    ReplyDelete

Thank you for your comment! It is my hope that you find the information here useful. Let others know if this post helped you out, or if you have a comment or further information.