That isn't quite how it works. In VDI a 1MB block is classified in one of three ways: UNALLOCATED, ZERO-BLOCK (a block filled with zeros), and ALLOCATED (a block filled with anything - which may include all zeros). Only the last classification needs actual data storage in the image file. Currently zero blocks are not recognized dynamically, so once a block of disk storage is allocated it remains allocated forever...noteirak wrote:Finally, let's say you need to know what is the state of sector 118. If you actually compacted the diff disk like you expect it to work, it means that you'll remove the 0 from the diff disk, but then, when you try to read the empty sector, they are not defined into the diff disk, so you'll get the value from the base disk..... which actually contains data! So you couldn't compact it either
Except... when you compact (using VBoxManage modifyhd --compact), or clone a disk (VBoxManage clonehd) then VBoxManage at that time checks the allocated blocks to see if they are filled with zeros. If yes then the allocated storage is discarded and the block map entry is changed to ZERO-BLOCK. Hence if you run sdelete and manually fill all unused virtual disk space with zeros then on compaction/cloning these will all be replaced with ZERO-BLOCK markers - they will never be replaced with UNALLOCATED markers. As you say, zeroed is not the same as unallocated.
In snapshot chains, only unallocated blocks cause the parent to be checked for data. Not zero blocks. A zero block in the current state will return a block filled with zeroes, regardless of what the parent had for this block.
So, it is technically quite possible to compact the current state of a snapshot chain - it's just likely to ineffective in a large number of cases because you can only apply it to the current state, which may be a small fraction of the disk space being used by the entire snapshot chain.