none
After Deleted some files in Disk driver , the free space increased in drive inside of the VM . but its not replicating or increase the free space while inspect the VHD

    Question

  • Hi All,

    After Deleted some files in Disk driver , the free space increased in drive inside of the VM . but its not replicating or increase the free space while inspect the VHD. So VMs are went to pause state. Kindly help to resolve the issue 

    OS and role : Windows server 2012 R2 with Hyper-v 

    Cluster :- 20 node fail over cluster  

    Regards

    V.P.Neelakandan

    Wednesday, December 5, 2018 11:04 AM

All replies

  • It sounds like you are using a dynamically expanding virtual disk.  In that case, new files are always created at the 'end' of the disk, causing the disk to continually grow until it reaches its maximum size.  A delete operation, just like on a physical disk, is not a 'delete and purge' operation.  In other words, when you delete a file, the file is not actually physically removed from the disk, but is simply marked as available for future use.  Since the default action of adding new files is to place them at the end of the disk, the freed space is not automatically used.  This causes the dynamically expanding VHD to continue to expand until it reaches its maximum size.  Then it will start using the previously deleted file space.

    If you want the dynamically expanding disk to shrink in size after deleting files, you can use the Edit VHD command from the GUI.  Select the disk and select the compress option to remove the deleted file space.

    A better option is to define the disk as a fixed disk.  That disk will not expand.  It will always use the same amount of host disk space.  And deleted file space will be reused, just like on a physical disk.


    tim

    Wednesday, December 5, 2018 2:38 PM
  • I disagree with Tim on several points, but the important part is correct: the VHD/X driver does not automatically reclaim freed blocks. The I/O overhead would be extreme. The operation to use is "compact", not "compress", though. The VM needs to be taken offline, then the compact operation initiated:

    $VHDPath = 'full-path-to-your-vhdx.vhdx'
    Mount-VHD -Path $VHDPath -ReadOnly
    Optimize-VHD -Path $VHDPath -Mode Full
    Dismount-VHD -Path $VHDPath

    Or:

    If you have available space on another LUN or SMB share, you can alternatively perform a Storage Migration of one or more VMs.

    You definitely need to set up some monitoring on your storage location so that you get advanced warning.

     new files are always created at the 'end' of the disk

    Since the default action of adding new files is to place them at the end of the disk, the freed space is not automatically used.

    Then it will start using the previously deleted file space.

    Select the disk and select the compress option to remove the deleted file space.

    The quoted parts are not true. The VHD/X driver is block-based, so it does not, and cannot, dictate where files are created. It only adds space to the end of the VHD/X if the VHD/X driver receives a request to write to a valid but unallocated block. The guest OS decides which blocks to use, and it will default to writing into the next empty one. Up until files start getting deleted, those blocks are in sequence. But, if a file is deleted in-guest, then the in-guest file system will direct future writes to those freed blocks first (that's how fragmentation happens). As long as the guest is re-using blocks, the VHD/X driver will also reuse blocks. It will not perform an expansion event and it will not redirect them to the end.


    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    • Proposed as answer by Tim CerlingMVP Friday, December 7, 2018 3:34 PM
    Wednesday, December 5, 2018 9:26 PM
  • Hi Eric,

        i agree your point , but its a manual process before that we need to monitor always whether disks having a free space or not . 

     Actually i am expecting automation process that once deleted some files from driver , automatically the same space need to decrease in VHD. Is there any possibility 

    V.P.Neelakandan

    Thursday, December 6, 2018 4:55 AM
  • No, there is no process that will automatically shutdown a VM and compact its disks. You could wrap the script that I gave you in a larger one that shuts down and starts up the VM and put that in a task scheduler someplace, I suppose. There is certainly no way to compact online. As I said, the I/O would be extreme.

    Thin provisioning is only intended to allow you to exploit the natural slack space present in almost every virtual disk. It's not a magical thing that allows you to yo-yo at the edge of space exhaustion. It sounds like you need to add capacity.


    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    Thursday, December 6, 2018 5:25 AM
  • Hi

    Thanks for posting in our forum!

    Realistically, the biggest problems with this system appear when you need to copy or move the VHD. The VHD itself doesn’t know which of its blocks are empty, so 100% of them have to be copied. Even if your backup or copy software employs compression, empty blocks aren’t necessary devoid of data. In the guest’s file system, “deleting” a file just removes its reference in the file allocation table. The blocks themselves and the data within them remain unchanged until another file’s data is saved over them.

    We should  turn off the vm and then “compact” the VHD in VM settings

    You can refer to the following link:

    https://www.altaro.com/hyper-v/hyper-v-guest-design-fixed-vs-dynamic-vhd/

    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    Hope this information can help you, if you have any question, please feel free to let me know.

    Thanks for your time and have a nice day!

    Best Regards,

    Daniel


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, December 6, 2018 6:03 AM
  • Hi,

    This is Daniel and wish you all the best!

    May I know whether your problem is solved? If you have any question, please let me know.

    Thanks for your time and have a nice day!

    Best Regards,

    Daniel


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, December 10, 2018 2:17 AM
  • Hi,
    Hope you are doing well!
    I haven't received your reply for a while, how is the problem now, if your problem is solved, would you please share your experience with us? if there is anything need to help, please let me know.
    In addition, if anyone’s reply is helpful to your problem, please mark it as an answer at your convenience so that other people who have similar problem can refer to. I appreciate your cooperation!
    Thanks for your time and have a nice day!
    Best Regards,
    Daniel


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, December 12, 2018 1:35 AM