As many of you know XenServer before version 5.6 has no online leaf node coalescing integrated and so you have to shut down or halt a virtual machine when you want to manually coalesce the leaf node of a virtual machine.

For those of you first time reading about coalescing and snapshots here is a short summary:
When you snapshot a virtual machine the virtual disk of this VM is set to read only (parent disk) and a additional virtual disk is chained to the read only disk (leaf node) where the VM can place additional write operations. If you create a second snapshot the first chained disk also gets read only and again a second disk is created and chained to the first snapshot disk to take the read operations of the vm after the second snapshot was taken. The last disk in this chain is called the leaf node.
When you now delete a snapshot the chain disk for this snapshot is merged into its parent disk to reduce the length of the disk chain. This can be done when the virtual machine is running excepting the last existing snapshot. For the last snapshot this is very complicated because the vdisks are online and in use of the virtual machine.

This problem is solved in XenServer 5.6 FP1 but for 5.6 and earlier read this cool workaround

How to reclaim the disk space is described in CTX123400 and how snapshots in XenServer are working in detail is described in CTX122978.

But over the time if you are working a lot with snapshots and have not the possibility to reclaim the space because of availability of the virtual machine there is an additional amount of space wasted on the storage repository which cannot be reclaimed but can be minimized to nearly zero by a simple trick:

Create a snapshot before installing the operating system into the virtual machine and delete it afterwards.



Here is an example:

I create virtual machine with a 12 GB attached vDisk. At the end of the creation wizard select not to start the virtual machine when finished. On the storage I can see the following:



 
vhd=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4 capacity=12884901888 size=12918456320 hidden=0 parent=none
 




The total usage of storage is ~12 GB. Before starting the virtual machine and installing the operating system into our VM I will create a snapshot. The main disk will be inflated as expected and the additional (leaf node) disk will have a size of 12GB. The total usage of the storage is now ~12 GB for the leaf node, ~8 MB for the read only parent disk and ~8 MB for the snapshot representing disk.

 
vhd=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4 capacity=12884901888 size=8388608 hidden=1 parent=none
    vhd=VHD-7f64c04c-f8c1-4975-befa-05f0f126a226 capacity=12884901888 size=12918456320 hidden=0 parent=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4
    vhd=VHD-9789c140-5900-458d-880a-cbe43000dde1 capacity=12884901888 size=8388608 hidden=0 parent=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4
.




So the usage of storage is approxemately 16 MB more than without a snapshot. Now I install the operating system into the virtual machine. Because of the 8 MB parent disk is read only all data will be written into the 12GB leaf node.
When I now delete the snapshot there will only be the parent node and the leaf node:

 
vhd=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4 capacity=12884901888 size=8388608 hidden=1 parent=none
    vhd=VHD-7f64c04c-f8c1-4975-befa-05f0f126a226 capacity=12884901888 size=12918456320 hidden=0 parent=VHD-930e7df0-a642-4bb7-acf4-efb572d927b4
.




In the XenCenter management console you will not see any snapshots for the virtual machine. Just on the storage with a more of use of the 8MB.
By this usage from now you can work with snapshots in XenServer versions earlier 5.6 feature pack 1 with a minimized consumption of storage because we reduce the storage overhead to ~8 MB per virtual machine.



Also there will be no performance impact because all data is located into the leaf node and so the virtual machine will get its data with the first disk access.

Have fun…

          Jens