Hyper-V Failed to Compact VHD

Mark Berry October 8, 2010

On Windows Server 2008 R2 running Hyper-V, I’m trying to compact a (dynamically expanding) VHD on an external hard drive (USB drive, NTFS format). The drive is 59GB and there is 103GB free on the drive. I keep getting the message, "The system failed to compact <MyDrive>.VHD. Error code:  The requested operation could not be completed due to a file system limitation." Why can’t I compress the VHD?

In the Hyper-V-Image-Management-Service Admin log, we have Event ID 15054:

Log Name:  Microsoft-Windows-Hyper-V-Image-Management-Service-Admin
Source:  Microsoft-Windows-Hyper-V-Image-Management-Service
Event ID:  15054
Level:  Error
Description:  ‘The system failed to compact ‘F:\<MyDrive>.VHD’. Error Code: 2424869

I thought maybe the physical drive was too fragmented, but a defrag ran quickly and made no difference.

This blog post provides the answer:  the VHD contains VSS shadow copies. (It’s a Server 2003 with Volume Shadow Copies enabled.)

Start up the virtual machine and log on to the guest. Run vssadmin list shadows to check for shadow copies. Run vssadmin delete shadows /all to delete the shadow copies. Then shut down the virtual machine guest and try compacting again.


  1. James Summerton   |  November 07, 2010 at 9:03 pm

    Thanks for blogging this!

    Stopped me from going mad trying to compact a VHD in Hyper-V.

    Worked perfectly

  2. Nick Lloyd   |  January 26, 2011 at 10:46 am

    Thanks for blogging this Mark, had the same problem and your post solved it!

  3. Oliver Geist   |  February 23, 2011 at 12:32 am

    Yeah, special thanks for this great Information!
    I searched a long time for this solution.

  4. digitap   |  March 16, 2011 at 9:14 pm

    thanks for the post. i’d run into this before and chased down a lengthy defrag before i realized that wasn’t the solution in the past. your post jogged my memory.

  5. Steven   |  October 31, 2011 at 10:56 pm

    Worked – thanks very much; saved my bacon tonight.

    I had to go in and actually enable shadow copies (Computer Management -> Right click on Shared Folders -> All Tasks -> Configure Shadow Copies). Once I enabled, then I was able to delete.

  6. gage   |  January 10, 2012 at 12:27 am

    in the hyper-v guest machine, it is windows 2008 r2 sp1
    1. I run defragmented
    2. I do vssadmin delete shadows /all

    but this is doesn’t work for one of my guest machine. but other guest machines are work.

    what can I do more

  7. Mark Berry   |  January 10, 2012 at 8:16 am

    Gage, see the comment by Steven just above yours. Maybe you have to enable shadow copies before deleting them?

  8. Mike Ash   |  February 21, 2012 at 12:03 pm

    Hi Mark,
    I’m attempting to compact a dynamically expanding) VHD with host= Windows Server 2008 R2 (x64)running Hyper-V.
    The guest is Vista Ultra (x32) residing on an internal SAS drive.
    Getting the same error when attempting to compact.
    When I attempt to run ‘”vssadmin delete shadows /all” at administrative privilege on the Vista guest, I receive the “Error: invalid command” response.
    There is definitely a shadow copy, because the vssadmin List command works.
    I went into Computer Management, followed what Steven indicated, but there is no “Configure Shadow Copies” option available.
    I also gave myself temporary access to the System Volume Information directory, but could find nothing that corresponded to the shadow copy listed in the vssadmin List results.
    Any guidance would be appreciated.

  9. Mark Berry   |  February 21, 2012 at 1:17 pm

    Sorry Mike, I don’t have a Vista install to test against. Maybe poke around in the vssadmin help:

    vssadmin /? (on Win7, this lists “delete shadows” as an option)
    vssadmin delete shadows /?

  10. Mike Ash   |  February 21, 2012 at 4:21 pm

    This is finally what worked on the Vista .vhd:
    If the guest’s Volume Shadow Copy service is running, stop it.
    Then (on the guest):
    1) Open an elevated command prompt
    2) Type “wmic”, after some time “wmic:rootcli>” will appear
    3) Type “shadowcopy” ( it will displays a list of existing shadow copies)
    4) Type “shadowcopy delete”
    5) one by one, it will give a “Y/N” style prompt, confirming the deletion of each individual shadow copy.
    6) Type “exit” to get back to normal command prompt

    The Hyper-V Compact Disk function ran successfully after that eliminating 20GB of real space from the VHD.

  11. Mark Berry   |  February 21, 2012 at 4:24 pm

    Great info, Mike, thanks for posting back.

  12. Daniel   |  February 08, 2013 at 1:10 pm

    Yep, deleting the one shadow copy I had on the VHD did the trick for me too. Wow ! I spent hours and hours getting this to work, unti I found this post. Many many thanks !

  13. Jure   |  March 01, 2014 at 9:24 am

    im am having Windows Server 2008 R2 with Hyper-V for a guest sistem then i have Windows SMall Bussines Server 2011 instaled, i had shadow copyes i have deleted it with DISKSHADOW, ther ist any VSS shadow copy files anymore, i dergamentend disks, i diabled shadow copy but i still cannot compact VHD, my CHD is now 760GB big and its stil growing, im out of ideas…. my drive is 830Gb and now i cannot run all server anymore….

    Does anyone hat any idea? Im i real problems right now:)

  14. Mark Berry   |  March 01, 2014 at 9:48 am

    Jure – compacting a disk will copy the old .VHD to a new and hopefully smaller .VHD. While it is compacting, BOTH the old and new .VHD files will be on disk. To compact a 760GB VHD, you will need more than 760GB free. You could try it on a 2TB hard drive.

  15. Jure   |  March 01, 2014 at 12:23 pm

    Hello Mark, thanks for reply this seems very logicaly, but i havent managet to test it yet, no enoug space! Il let you know. I have one more questin if i do conversion from a dinamic to static, what Will be the size of the nev VHD, same as is dinamic VHD 780Gb or just the size of actual disk that are in the host OS i have C thats 160Gb and D its 250GB?

    And also about AVHD, my VHD is named SBS, the i have two *.avhd files with different prefixes.

    Thanks for qiuck reply!

  16. Jure   |  March 01, 2014 at 12:24 pm

    I meant why are two AVHD files?

  17. Mark Berry   |  March 01, 2014 at 12:56 pm

    Apparently the AVHD files have something to do with snapshots, which I never use:


    I think if you convert dynamic to fixed, it will use the _maximum_ size of the dynamic.

    It seems strange that your dynamic is bigger than 160 + 250 = 410. But I never put multiple volumes on a dynamic disk, and I always set a maximum size for the dynamic disk.

    What you might be able to do:

    1. Create a fixed 165GB VHD.
    2. Mount the VHD from Disk Management under the Hyper-V server. Create an empty NTFS partition.
    3. With your SBS client OS shut down (and after merging all snapshots), mount the 760GB VHD.
    4. Copy the copy entire C: drive from the dynamic VHD to the fixed VHD. (You might need ROBOCOPY or a cloning tool.)
    5. Repeat for the D: drive but its fixed VHD must be over 250GB.

    You might have some disk signature errors after that and/or boot errors and/or need to re-activate the client OS.

    Another approach would be to restore from SBS backup (you do have a separate external backup, right?) but I would do that to a new drive / VHD in case there is a failure.

    Use these suggestions at your own risk!

  18. Jure   |  March 01, 2014 at 10:03 pm

    sorry i didnt explained properly my situation, i have one virtual machine that has two VHDs, firs is C: disk that is named SBS and is 160GB size, then it has two AVHD files tht are 126 and 95GB site, thed i have second disk that is 260GB and tvo AVHDs with 60GB and 90 GB. When i do a compact i have to. When i did defrag the files expandet for at least 10%. I tried to do a compact on bigger host HDD and the issue stays the same!(FIlesystem limitation)

    I will try to do as you suggested, but still i would like to found a solution to compact VHDs.

    Thanks fro help!


  19. Mark Berry   |  March 01, 2014 at 10:39 pm

    Okay… from reading that article I linked, I get the idea that if you can get the snapshots to merge back into the main disk, the AVHD files will go away. But I have not worked enough with snapshots to remember for sure how to merge them. Good luck!

  20. Adam Shaw   |  July 13, 2015 at 5:30 pm

    Snapshots can be deleted in the console ‘on-the-fly’, though the Hyper-V Image Management service won’t actually ‘merge’ the snapshots until the respective VM is shut down. This can be very time consuming.

  21. Gonzalo Carrasco   |  January 12, 2016 at 11:29 am

    It’s work fine for me!! Thanks!

  22. Jules   |  February 04, 2016 at 6:29 pm

    Thank you sir, that did the trick. Great information.

Leave a Reply