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.
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
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 :
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.
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.