Creating a Template VM from a qcow2 image
This document outlines the general procedure for adding new Template VMs in vSphere
for .qcow2
images.
The template VM in this guide refers to a regular vSphere VM and not VM
Templates according to the vSphere terminology. The difference is quite subtle,
but VM Templates are not supported yet by machine-controller.
Prerequisites
- vSphere (tested on version 6.7)
- govc (tested on version 0.37.2)
- qemu-img (tested on version 4.2.0)
- curl or wget
Procedure
Download the guest image in qcow2 format end export an environment variable
with the name of the file.
# The URL below is just an example
image_url="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img"
image_name="$(basename -- "${image_url}" | sed 's/.img$//g')"
curl -sL "${image_url}" -O .
Convert it to vmdk e.g.
qemu-img convert -O vmdk -o subformat=streamOptimized "./${image_name}.qcow2" "${image_name}.vmdk"
Upload to vSphere using WebUI or GOVC:
Make sure to replace the parameters on the command below with the correct values specific to
your vSphere environment.
govc import.vmdk -dc=dc-1 -pool=/dc-1/host/cl-1/Resources -ds=ds-1 "./${image_name}.vmdk"
Inflate the created disk (see [VMware documentation][inflate_thin_virtual_disks] for more details)
govc datastore.disk.inflate -dc dc-1 -ds ds-1 "${image_name}/${image_name}.vmdk"
Create a new virtual machine using that image with vSphere WebUI.
During the Customize Hardware
step:
- Remove the disk present by default
- Click on
ADD NEW DEVICE
, select Existing Hard Disk
and select the disk previously created.
The vm is ready to be used by the MachineController
by referencing its name in the field .spec.template.spec.providerSpec.value.cloudProviderSpec.templateVMName
of the MachineDeployment
.