question

JohnLenz-5880 avatar image
0 Votes"
JohnLenz-5880 asked DSPatrick commented

Did VHDX really shrink?

Server 2012R2 running Hyper-V
Hyper-V server 2012R2 (SQLserver2012)

OK, I followed the process to shrink the VHDX to free up space.

Here is VM disk Partition:

93415-longsql2012-volume-shrink.jpg

This is the Get-VHD that shows the before & after of the shrink command and the file explore winnow Did it shrink physically or not?

93385-longsql2012-get-vhd.jpg


windows-server-hyper-v
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
I would like to check if the issue has been fixed. If yes, please help accept answer. If you need any additional assistance, please feel free to feedback.
Best Regards,
Danny

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered

Yes, that should be correct.
https://www.sikich.com/insight/how-to-compact-dynamic-vhd-and-vhdx-files-in-hyper-v-2012-and-newer/

--please don't forget to Accept as answer if the reply is helpful--





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnLenz-5880 avatar image
0 Votes"
JohnLenz-5880 answered DSPatrick commented

Success! first resize, then optimize

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad to hear of success!




0 Votes 0 ·
JohnLenz-5880 avatar image
0 Votes"
JohnLenz-5880 answered

I still have a question

I believe my command line should be

Optimize-VHD -Path c:....vhsx -Mode Full

I have read the doc for Full. It states it scans for zero blocks and unused blocks. Does that mean it will Shrink the vhdx to "FileSize" that is the "MinimumSize" as noted above?

I need to shrink the VM data space to free up space on my C drive.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

Any progress or updates?

--please don't forget to Accept as answer if the reply is helpful--


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YuhanDeng-MSFT avatar image
0 Votes"
YuhanDeng-MSFT answered

Hi,
The Optimize-VHD cmdlet optimizes the allocation of space in one or more virtual hard disk files, except for fixed virtual hard disks. The Compact operation is used to optimize the files. This operation reclaims unused blocks as well as rearranges the blocks to be more efficiently packed, which reduces the size of a virtual hard disk file.
To use Optimize-VHD, the virtual hard disk must not be attached or must be attached in read-only mode.
The compact operation can succeed without reducing the file size, if no optimization is possible.

The Resize-VHD cmdlet changes the maximum physical size of a virtual hard disk. It can expand both VHD and VHDX files but can shrink only VHDX files. The shrink operation fails if it would shrink the virtual disk to less than its minimum size (available through the VHDX object's MinimumSize property).
If the virtual disk file connects to a virtual machine's IDE chain, you cannot resize the virtual disk while the virtual machine is online. If the virtual disk file connects to a virtual machine's SCSI chain, you can resize the virtual disk while the virtual machine is online.

For your reference:
https://docs.microsoft.com/en-us/powershell/module/hyper-v/optimize-vhd?view=windowsserver2019-ps
https://docs.microsoft.com/en-us/powershell/module/hyper-v/resize-vhd?view=windowsserver2019-ps

Thanks for your understanding.
Best regards,
Danny


If the Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

Please describe the command line Resize-Vhd

Resize-VHD does not remove empty blocks from a dynamically-expanding virtual hard disk file. Use Optimize-VHD instead.

https://docs.microsoft.com/en-us/powershell/module/hyper-v/resize-vhd?view=windowsserver2019-ps

--please don't forget to Accept as answer if the reply is helpful--






5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnLenz-5880 avatar image
0 Votes"
JohnLenz-5880 answered

Please describe the command line Resize-Vhd ...
I cannot do it wrong
Thanks, I am out of office today returning tomorrow afternoon. I'll try then and report

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cheong00 avatar image
0 Votes"
cheong00 answered

What you need is Optimize-VHD, not Resize-VHD, as you're not resizing your partition, but merely try to reclaim unused space on the VHD file.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered

Might take a run through this one.
https://www.altaro.com/hyper-v/shrink-hyper-v-virtual-disk-vhd-vhdx/

--please don't forget to Accept as answer if the reply is helpful--



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnLenz-5880 avatar image
0 Votes"
JohnLenz-5880 answered

OK,

Please look at the attachments

  1. I successfuly shrunk the partition on the VM machine SQL2012. If I took a screen shot before the Resize-VHD command, it would have show unallocated space at the end of the partition

  2. I executed the Resize-VHD command and it executed successfully, as shown

  3. the post Resize-VHD shows Size shrinking to 166GB


Why did the Get-VHD file size not shrink as well. The file explorer still shows the file as 300+ GB. I need to recover space on the drive ASAP.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.