Skip to main content

Create and manage VMs

Creating, cloning and deleting virtual machines on XCP-ng.

tip

The most comfortable way to create and manage VMs is Xen Orchestra (or XO Lite directly from your host, for simple cases). The xe commands below are useful for scripting and automation. See also infrastructure as code for Terraform/OpenTofu, Packer and Ansible.

🏗️ Create a VM

From a template + ISO

The usual workflow: pick the template matching the guest OS, give the VM resources, attach an installation ISO, install the OS, then install the guest tools.

From Xen Orchestra: NewVM, pick the pool, template, name, CPU/RAM, disks and network, select the ISO, and create. ISOs come from an ISO SR.

With xe:

root@xcp-ng-host — From a template + ISO
# Find the right template
# xe template-list params=name-label | grep -i debian

# Create the VM from it
# xe vm-install template="Debian Bookworm 12" new-name-label="my-vm"

# Attach the install ISO and a network interface
# xe vm-cd-add vm="my-vm" cd-name="debian-12.iso" device=3
# xe vif-create vm-uuid=<vm-uuid> network-uuid=<network-uuid> device=0

# Start it and install the OS through the console
# xe vm-start vm="my-vm"

vm-install creates the disks defined by the template on the default SR; add sr-uuid= to choose another one.

From a cloud image

For cloud-ready images (Ubuntu cloud images, Debian genericcloud…), import the image as a disk and configure it at first boot with cloud-init: see the custom templates guide and Xen Orchestra's cloud-init support in the cloud features page.

By cloning

See clone or copy below: cloning an installed and prepared VM (or a template made from it) is the fastest way to mass-produce VMs.

By importing

Import an existing VM (XVA, OVA, or disks from another hypervisor): see import and export and migrate to XCP-ng.

🐑 Clone or copy a VM

Two different operations:

  • Clone (xe vm-clone): near-instant on SRs supporting copy-on-write: the clone shares its base disk with the original ("fast clone" in Xen Orchestra). Ideal to spin up many VMs from one source on the same SR.
  • Copy (xe vm-copy): full independent copy of the disks, optionally to a different SR. Slower, but the result doesn't share anything with the source ("full copy" in Xen Orchestra).
root@xcp-ng-host — Clone or copy a VM
# xe vm-clone vm="my-vm" new-name-label="my-vm-clone"
# xe vm-copy vm="my-vm" new-name-label="my-vm-copy" sr-uuid=<destination-sr-uuid>

The source VM must be halted (or use a snapshot of a running VM as the source).

warning

Clones inherit everything from the source, including hostname, SSH host keys, and machine IDs. For anything you plan to clone repeatedly, prepare the source first (for Linux: reset /etc/machine-id, SSH host keys, static IPs; for Windows: use sysprep). Details in the templates page.

⚡ Start, stop, reboot

From Xen Orchestra or XO Lite, use the VM's action buttons. With xe:

root@xcp-ng-host — Start, stop, reboot
# xe vm-start vm="my-vm"
# xe vm-shutdown vm="my-vm"            # clean shutdown, needs guest tools
# xe vm-reboot vm="my-vm"
# xe vm-shutdown vm="my-vm" force=true # hard power-off, last resort

A clean shutdown/reboot requires working guest tools in the VM. You can also suspend a VM to disk (xe vm-suspend / xe vm-resume): its memory is written to the default SR and the VM stops consuming RAM.

To start VMs automatically when the host boots, see the autostart guide. To choose which host a VM should preferably run on, set its affinity host (xe vm-param-set uuid=<vm-uuid> affinity=<host-uuid>). See VM load balancing for dynamic placement.

🛡️ Protect a VM against accidental deletion

You can block specific operations on any VM, including deletion:

root@xcp-ng-host — Protect a VM against accidental…
# xe vm-param-set uuid=<vm-uuid> blocked-operations:destroy=true

Anyone (or any script) trying to delete the VM will get an error until the block is removed:

root@xcp-ng-host — Protect a VM against accidental…
# xe vm-param-remove uuid=<vm-uuid> param-name=blocked-operations param-key=destroy

🧺 VM groups with a start order (vApps)

XAPI can group VMs into an appliance (also called vApp): a set of VMs started together, in a defined order, with delays between them. Typical use: bring a database up before the application servers. The group is also what HA and DR tooling can recover as a unit.

root@xcp-ng-host — VM groups with a start order…
# xe appliance-create name-label="my-app"
# xe vm-param-set uuid=<vm-uuid> appliance=<appliance-uuid> start-order=1 start-delay=30
# xe appliance-start uuid=<appliance-uuid>

See the appliance commands in the CLI reference.

🗑️ Delete a VM

From Xen Orchestra, deleting a VM lets you choose whether to also remove its disks and snapshots. With xe:

root@xcp-ng-host — Delete a VM
# xe vm-uninstall vm="my-vm"           # deletes the VM and the disks marked for destruction
# xe vm-destroy uuid=<vm-uuid>         # deletes the VM record only, leaves the disks

A VM must be halted before deletion. Remember that its snapshots are separate objects: list them with xe snapshot-list snapshot-of=<vm-uuid> and clean them up too, or the space won't be freed (see snapshots).