Skip to main content

Templates

Templates are the blueprint VMs are created from: they define the virtual hardware (firmware type, devices, memory defaults…) and, optionally, pre-installed disk content.

πŸŽ“ Two kinds of templates​

  • Built-in templates: shipped with XCP-ng, one per supported guest OS family. They contain no disk content: they only carry the right virtual hardware settings and optimizations for that OS (device model, boot mode, memory defaults…). You install the OS yourself from an ISO or network. Always create a VM from the template matching its OS: this is what guarantees the best defaults.
  • Custom templates: created by you from an existing VM or snapshot. They include the disks' content, so new VMs start as exact copies. This is the classic "golden image" workflow.

List available templates:

root@xcp-ng-host β€” Two kinds of templates
# xe template-list params=name-label
tip

If built-in templates are missing (e.g. after an incomplete upgrade), see this troubleshooting entry.

πŸ“Έ Create a custom template​

From a VM​

Halt the VM, then in Xen Orchestra use Convert to template (VM advanced tab). With xe, converting is a one-way flag flip:

root@xcp-ng-host β€” From a VM
# xe vm-param-set uuid=<vm-uuid> is-a-template=true

If you want to keep the original VM, clone it first and convert the clone.

From a snapshot​

A snapshot of a running VM can become a template without ever stopping the source VM: in Xen Orchestra, snapshot list β†’ create template from snapshot, or:

root@xcp-ng-host β€” From a snapshot
# xe snapshot-export-to-template snapshot-uuid=<snapshot-uuid> filename=my-template.xva
# xe vm-import filename=my-template.xva preserve=true

🧼 Prepare the source before templating​

New VMs created from a custom template are clones: anything unique to the source machine gets duplicated. Before converting a source VM into a template:

  • Linux: clear /etc/machine-id, remove SSH host keys (they'll regenerate at boot with most distros), remove static network configuration, clean logs and package caches. Even better, install cloud-init so each new VM configures its hostname, users and network at first boot. Xen Orchestra has first-class cloud-init support (see cloud features).
  • Windows: run sysprep /generalize so each clone gets its own machine identity.

A full worked example (cloud image β†’ prepared VM β†’ template β†’ new VMs) is in the Ubuntu custom templates guide.

πŸš€ Create VMs from a template​

From Xen Orchestra: New β†’ VM and pick your template: custom templates appear alongside built-in ones. With xe:

root@xcp-ng-host β€” Create VMs from a template
# xe vm-install template="my-golden-image" new-name-label="new-vm" sr-uuid=<sr-uuid>

For repeated or automated deployments, drive this with Terraform/OpenTofu, Packer or Ansible.

πŸ“¦ Move templates around​

Templates export and import like VMs, in XVA format, which is handy to copy a golden image to another pool:

root@xcp-ng-host β€” Move templates around
# xe template-export template-uuid=<template-uuid> filename=my-template.xva
# xe vm-import filename=my-template.xva preserve=true

Or from Xen Orchestra, export/import from the template's view (see import and export).

πŸ—‘οΈ Delete a custom template​

In Xen Orchestra, from the templates list (Home β†’ VMs β†’ templates filter). With xe:

root@xcp-ng-host β€” Delete a custom template
# xe template-uninstall template-uuid=<template-uuid>

This also removes the template's disks (after confirmation).