Use linked clone instead of full clone to create VMs

TwitterGoogle+LinkedInFacebook

I had many questions, especially on homemade VDI environment, on how to save space without using dedup and compression on the storage backend and how to create a quick clone on a VM.

There is a VMware API call we can use for this purpose which can also be used in a lab environment when you want to test your customization wizard or specific boot up scripts.

The name of this feature is called “linked clone”. Note that it is not the same technology as the “instant clone” way of cloning VMs. This post will cover how it works and how to use this.

OVERVIEW

This way of creating VMs can only be done through APIs. There is no way of doing this using the WebClient. This is the same way Horizon View creates the VMs in a dynamic pool. The clone is not based on the VM but on a snapshot of the VM. Yes, you understood well. This means you do not clone the full VMDK anymore, you just clone the snapshot, which uses only a few KBytes. This is why this is so fast, and this is why it consumes so few space.

As you understood, the linked clone process will just spawn a new snapshot based on the root VMDK of your template. The new created delta disk will refer to the template Read Only disk.

Here is the difference between a full clone and a linked clone

full-clone-vs-linked-clone

As you can see, you save the space of the template and as you just span a delta disk (same way as a VM snapshot), you also save space.

If you are using my Linux deployment script or my Windows deployment script, it will be very easy to use this technology. You will just need to change the way of copying the files.

If you remember, you use the VirtualMachineRelocateSpec object to specify where your virtual machine will be deployed. You need the datastore view as well as the resource pool view. There is a property in this object named diskMoveType which can have several values. The one I specified by default is moveAllDiskBackingsAndAllowSharing. This means that all VM VMDK are copied onto the target datastore and the snapshot mounted on this VMs from other VMs will remained a snapshot. You can find all the options there.

We are going to focus on the createNewChildDiskBacking option. Indeed, this is the only properties of the entire script that will change your VM from a full clone to a linked clone. This property will create a new child disk on the destination datastore. This will be a snapshot of the read only original VMDK.

So your VirtualMachineRelocateSpec will look like this :

my $VirtualMachineRelocateSpec = VirtualMachineRelocateSpec->new(
	'datastore'		=> $DatastoreView,
	'diskMoveType'	=> 'createNewChildDiskBacking',
	'pool'			=> $ClusterView->resourcePool,
);

As I said, you create a clone based on a snapshot. You will need to take a snapshot of your template to make it real. Note that this can be done manually or in a automated way, up to you. Let’s say you do it manually through the WebClient.

You will need to find the snapshot of the VM using APIs and give it to the clone process. Here is how to find the latest snapshot, the snapshot the VM is working on. We already have the VM View, so the best way to get it is to get it through the VM properties. Then we give this snapshot moref to the VirtualMachineCloneSpec to says to the cloning process to start from there. This is the second part of the original Linux or Windows script to custom.

my $currentSnapshot = $VMView->snapshot->currentSnapshot;


my $VirtualMachineCloneSpec = VirtualMachineCloneSpec->new(
    'config'		=> $VirtualMachineConfigSpec,
    'customization' => $CustomizationSpec,
    'location'		=> $VirtualMachineRelocateSpec,
    'powerOn' 		=> 'true',
    'template' 		=> 'false',
    'snapshot' 		=> $currentSnapshot
);

Here you are. If you call the clone process this way, you will create Linked Clone, save a few space on your datastore and you will create VMs in a couple of seconds.

TwitterGoogle+LinkedInFacebook

Author: fluatovh

I'm today Senior Cloud Architect at OVH since 2010 and I manage the teams in charge of deployment and improvement of the OVH Dedicated Cloud product since its creation. I'm a VMware Architect and a VMware specialist since more than 8 years. We run today thousands of vCenter in production in a completely automated way and we host hundreds of thousands VMs on top on these VMware infrastructures for OVH Customers. @fluatovh

Leave a Reply

Your email address will not be published. Required fields are marked *