Hyper-V Failed to Compact VHD

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
User:  SYSTEM
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.

24 thoughts on “Hyper-V Failed to Compact VHD

  1. digitap

    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.

  2. Steven

    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.

  3. gage

    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

  4. Mark Berry Post author

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

  5. Mike Ash

    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.

  6. Mark Berry Post author

    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 /?

  7. Mike Ash

    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.

  8. Daniel

    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 !

  9. Jure

    Hello,
    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:)

  10. Mark Berry Post author

    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.

  11. Jure

    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!

  12. Mark Berry Post author

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

    http://blogs.msdn.com/b/charles_sterling/archive/2008/08/06/what-are-all-these-avhd-files-hyper-v.aspx

    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!

  13. Jure

    Hello,
    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!

    BR

  14. Mark Berry Post author

    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!

  15. Adam Shaw

    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.

  16. Bruno Guerra

    Awesome. Save me at 2021. Thank you for your post.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.