If you’re one if these people looking under the cover of XenClient or probably have read an earlier blog regarding how XenClient leverages VHD chaining, you may wonder if there’s any way how you can manage some of your vhd chains.

The answer is (Choose one): Kind of – Depends – Sure!

From the technical point of view, you can modify all aspects of the VHD files and chains. However, there are a few things you need to be aware of: You can easily brake your VHD, so the VM wont boot anymore – There’s no undo button – Tech support may not help you – Don’t blame me 🙂

The pain with the chain

While VHD chaining is a fantastic technology, there’s a good chance the you loose track about which files belong to which chain. Additionally the chains may got longer and longer during the lifetime of a VM.

As a first step I wanted to share a few CLI’s, how to get more insights about your chains.

In the second step I’ll show how you can control the vhd coalesce proces within XenClient

Show me the chain please

The first thing you probably want to know is how can I read these chains.

There are multiple way to do, obviously the first thing is to find out which vhd belongs to my vm here is an example how you can find this out:

  1. Open Terminal
  2. Enter: xec-vm -> this will show you the VM’s / UUID mapping
    <a rel="attachment wp-att-174180042" href="/blogs/2012/01/27/xenclient-best-practices-series-%e2%80%93-keep-on-top-of-your-vhd-chain/term1/"><img class="alignnone size-full wp-image-174180042" src="/blogs/wp-content/uploads/2012/01/term1.jpg" alt="" width="479" height="138" /></a>
  3. Read the respective config file using the UUID e.g.

  4. Look for the section “disk”
  5. The vhd file listed on “disk 1” is the one the VM runs from – the leaf of the chain typically
  6. Now we’re going to read the header of that vhd file using the vhd-util tool
  7. You can see that this VHD file is in fact a Differencing hard disk and further down the Parent name can be read
  8. Now you could repeat the steps with the parent VHD file and “walk the chain”
  9. TIP: use the following command to display the VHD chains in your storage directory:
  10. The output will give you a tabbed list of the VHD files sorting the VHD’s against the chain.
    Note: Our VM harddisk chain consists of 3 VHD files

What makes chains growing?

Typically a chain is being created when ever thy system makes a snapshot. Creating snapshot will make the current CHD file readonly, therefore an empty VHD file is being created which holds all the changes since the snapshot – This is often referred to the leaf.

In a XenClient world, there are several situations when a snapshots is being created.  By default when ever you download an Image from the Synrhonizer, the first thing XenClient is doing after installing the image is to create a snapshot.

If you use dynamic image mode, you can layer the image, which creates a golden image and referenced differential files (compressed block level diff VHD’s), which are perfect for:

  • Saving bandwidth and storage
  • Maintaining multiple versions – You, can switch between them by just selecting a different version of a image

When ever a backup is being made, XenClient will snapshot the current leaf, create an empty one and upload the old (readonly) leaf to the synchronizer. After the the backup has been completed the VHD chain will be “merged” during a housekeeping task. This is called coalesce and will run with low priority in the background.

No worries, if the user is shuting down XenClient the houskeeping will be continued on the next run until the processing has been completed. However if it doesn’t complete until the next backup schedule is hit, the chain grows again…

I want to control the VHD coalesce process

Sometimes, you might wish to get control over these processes. Guess what, with many things in XenClient this is possible you jus need to get to the terminal.

In order to have something to show, I’ll create a manual backup of m VM.

As you can see on the following scan, the same VHD chain we looked before know has four VHD0s opposed to three.

The command to user for controlling the coalesce process is bed-coalasce – You can check which chains are being queued for coalescing  using the parameter targets, you can stop using the parameter cancel, or activate a cancelled job using the parameter activate or just monitor the status with the parameter monitor.

You can safely the ruby erro message and monitoring might not be accurate, but you’ll get the message coalesce completed after the job has finished.

What else can I do with these chains

To be frankly honest in a managed environment (using Synchronizer) not much without breaking the system.

If you consider the Dynamic Image Mode each version will add a vhd to the chain and we only can switch between versions if these layers are untouched. Using the “raw” vhd-util would allow you to to coalesce any chain on vhd level, but the backend wouldn’t be aware of the chances and the VM would brake.

I’v planned to add a share some  stuff around manipulating vhd’s in a unmanaged environment in a future blog of the XenClient Best Practices Series.

Enjoy working with XenClient! Cheers, walter.hofstetter[at]

Connect with the XenClient team online!