none
Compress Hyper V Disk

    Question

  • Hi

    I did find this thresd: https://social.technet.microsoft.com/Forums/en-US/b0861584-ea87-4cf8-91de-323edf19f5ee/how-to-compress-hyperv-virtual-harddisk8217s-?forum=winserverhyperv

    but it seems not longer a proper workflow as this might result in the virtual machine Hard Drive no longer available. Certainly when the vm was suspended. 

    What is the best practice to manage vdisks in hyper-v these days. A link to the definitiv documentation would be appreciated.

    Thursday, October 11, 2018 7:20 AM

Answers

  • Hi!

    As far as I know there's no "Best Practice" for this, you can manage virtual disks either in the GUI (compacting a VHD/VHDX can be done as in the link you mentioned, here's also a blog post about it.) or with PowerShell, personally I prefer to perform these operations in PowerShell.

    Compact a VHD/VHDX in PowerShell

    Mount-VHD -Path "D:\Hyper-V\Windows10\Virtual Hard Disks\Windows10_C.vhdx" -ReadOnly
    Optimize-VHD -Path "D:\Hyper-V\Windows10\Virtual Hard Disks\Windows10_C.vhdx" -Mode Full
    Dismount-VHD -Path "D:\Hyper-V\Windows10\Virtual Hard Disks\Windows10_C.vhdx"

    Note the following:

    • It is not possible to compact a VHD/VHDX that is connected to a running virtual machine.
    • The computer system where you run the Optimize-VHD must have the complete Hyper-V role installed.
      The PowerShell module alone does not contain the necessary system services.
    • You can also run the compact operation on a system that doesn't have Hyper-V installed by using Diskpart.

    Before performing any kind of maintenance on a VHD/VHDX disk, I would recommend to always create a backup/copy of the VHD/VHDX before.

    Best regards,
    Leon


    Blog: https://thesystemcenterblog.com LinkedIn:

    Thursday, October 11, 2018 9:00 AM