Quantcast
Channel: Hyper-V forum
Viewing all articles
Browse latest Browse all 8743

Compact differencing VHD or VHDX

$
0
0

Hi,

Is it possible to compact a differencing disk similar to how a dynamically expanding VHD can be compacted?

There's this technet article for virtual server, which says it doesn't work for differencing disks: "If you want to compact a differencing virtual hard disk or an undo disk, you must merge the changes to the parent disk and then compact the parent disk, if it is a dynamically expanding virtual hard disk"

However, this article about a C++ API clearly says it's possible: "Compaction can be run only on a virtual disk that is dynamically expandable or differencing."

I've tried to do it with the powershell cmdlet Optimize-VHD. It (kind of) implies that differencing VHDs work too: "Optimizes the allocation of space usedby virtual hard disk files, except for fixed virtual hard disks."

The results from my tests are strange. It works somehow, but definitely not how I expected it to work. I did the following:

First, create a new dynamic VHD:

NEW-VHD -Dynamic C:\VHD\BaseDrive.vhd -SizeBytes 3GB

Mount it:

Mount-VHD -path .\BaseDrive.vhd

Open Disk Management. It prompts for initializing the mounted drive.
Confirm (MBR). Format as NTFS and Assign Drive Letter E.

Write a file to the disk: test.zip: 296 MB

Calls SDelete to overwrite empty blocks with zeros.
sdelete.exe -z E:

Dismount-VHD -path .\BaseDrive.vhd

Create a differencing VHD and mount it:

New-VHD -Differencing -Path .\DiffDisk.VHD -ParentPath .\BAseDrive.VHD
Mount-VHD -path .\DiffDisk.VHD

Copy some files to E:. The file size of DiffDisk.VHD increases to 567 MB. Now delete all files you just added and call sdelete again with the same parameters. The file size did not change (still 567 MB).

Now unmount and call Optimize-VHD

Dismount-VHD -path .\DiffDisk.vhd
Optimize-VHD -path .\DiffDisk.VHD -Mode Full

The expected result would be a file size close to 0 for DiffDisk.VHD. However, it's now 22 MB. Mounting it still works correctly, but I don't understand why it's still 22 MB. In this case, the improvement is still quite good, but it's just a test case and in the real world case, there's no improvement, unfortunately (more like the opposite). Somehow sdelete even increases the size from about 1.5 GB to 6 GB for a 80 GB VHD and then Optimize-VHD reduces it by several hundred MB again to 5.8... or something like that.

My understanding is that sdelete should overwrite all empty blocks on the disk with zero, including those where the deleted files were stored. Optimize-VHD should be able to completely remove all these blocks. I have no idea where these 22 MB come from.

Inputs, explanations or solutions are very welcome!




Viewing all articles
Browse latest Browse all 8743

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>