When you compact a VHD, the process actually removes references to "sectors" that are zeroed. A dynamic VHD contains a "Block Allocation Table" and a series of "Data Blocks". In this context, a block means an extent withing the VHD file; the
size of which in 2008 RTM was 512K and in SP2/R2 is 2M. The block allocation table tells you how many "blocks" make up the dynamic VHD and where they are. Now the term "Data Block" can be a bit misleading. A Data Block starts with a 512 byte
bitmap followed by the actual extent. The purpose of the bitmap is to track the "sectors" inside the extent. A "1" means the sector contains valid data, and a "0" means the sector contains all zeros and has never been written to.
Compact simply reads the Block allocation table to find the data blocks, then for each data block reads the bitmap to determine which "sectors" have and which have not been used. In your case, you wrote a bunch of data to the Dynamic VHD. This
caused the bits in the bitmap to flip from zero to 1. Even though you deleted those files from your linux file system in the partition inside the VHD, the VHD driver has no way to know that. All it knows it that a prticular sector at one time held
data. This is true independed of what the file system is inside the VHD.
If you read
http://social.technet.microsoft.com/wiki/contents/articles/hyper-v-how-to-shrink-a-vhd-file.aspx you'll notice a lot of extra hoops to go through before compacting a dynamic VHD; things like, in the ntfs case running defrag, or in a more general case
running a utility that zeros out unused sectors (as recommended in
http://technet.microsoft.com/en-us/library/cc708394(v=WS.10).aspx ). Within your Ubuntu guest, I would imagine you could you the secure delete utilities.. something like sfill -z to fill all the free space on the volume with zeros before you
take it offline and compact the VHD...
-
Marked as answer by
Vincent HuModerator
Wednesday, March 21, 2012 1:16 PM