Use this when templates use cloud-init to customize each clone.
Cloud-init · VM Templates
Cloud-init in templates customizes each new clone from the same image: pass user-data with hostname, users, SSH keys, network and packages through a NoCloud drive or the hypervisor's cloud-init settings.
1. cloud-init configures a VM on first boot: hostname, users, SSH keys, network, packages.
2. Datasource: NoCloud ISO, ConfigDrive, cloud metadata.
3. Logs: /var/log/cloud-init.log.
4. Runs once per instance-id.
5. Validate YAML: cloud-init schema --config-file.
datasource → cloud-init stages → configured guest
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Template captured with cloud-init state left (it will not run again).
- Network config in user-data conflicting with the platform's network config.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Validate user-data before using it.
cloud-init status --long— cloud-init result in guestqm cloudinit dump <vmid> user— generated user-data (Proxmox)cloud-init query -a | head— datasource info
ReferenceWhy it matters1 section · depth on demand
How it works
Cloud-init runs at first boot, reads metadata/user-data from a datasource (config drive, NoCloud ISO, cloud metadata service) and configures hostname, users, SSH keys, network and packages.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
NoCloud seed for KVM/libvirt
The cloud-init NoCloud documentation describes a seed with meta-data (must contain instance-id) and user-data (required, may be empty), plus optional vendor-data and network-config, typically delivered on a volume labelled CIDATA (vfat or iso9660).
$ cat meta-data
instance-id: web01-20261127
local-hostname: web01
$ cat user-data
#cloud-config
users:
- name: admin
groups: sudo
shell: /bin/bash
ssh_authorized_keys:
- ssh-ed25519 AAAA... admin@laptop
package_update: true
packages: [qemu-guest-agent]
runcmd:
- systemctl enable --now qemu-guest-agent
$ cloud-localds seed.iso user-data meta-data # or: genisoimage -volid CIDATA -joliet -rock ...
Attach seed.iso as a CD-ROM. If you change user-data later, change the instance-id too — the documentation notes that cloud-init uses it to decide whether this is a first boot.
Proxmox VE built-in cloud-init
qm set 9000 --ide2 local-lvm:cloudinit
qm set 123 --ciuser admin --sshkeys ~/.ssh/id_ed25519.pub --ipconfig0 ip=10.0.20.51/24,gw=10.0.20.1 --nameserver 10.0.0.53
qm cloudinit dump 123 user # show generated user-data
qm cloudinit update 123 # regenerate the drive after changes
Troubleshooting inside the guest
| Check | Command |
|---|---|
| Overall status | cloud-init status --long |
| What happened | /var/log/cloud-init.log, /var/log/cloud-init-output.log |
| Which datasource was found | cloud-init query ds / cloud-id |
| Re-run for testing (lab only) | cloud-init clean --logs && reboot |
Common faults: YAML indentation errors (validate with cloud-init schema --config-file user-data), the seed attached without the CIDATA label, or a template image where cloud-init already ran and was not cleaned.
*The NoCloud seed configuration and Proxmox cloud-init commands above are illustrative examples, not captured from a lab or production host.*
Reference
cloud-init status --long
cloud-init query -a | head
cat /var/log/cloud-init-output.log
Re-run on a clone after cloud-init clean --logs (for template preparation only).
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in VM Templates → Cloud-init. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/docs.html · confidence 94%