Use this when new Linux VMs must get hostname, users, SSH keys and network on first boot, or when cloud-init did not apply.
Cloud-init · Automation
Cloud-init is the first-boot agent in most Linux cloud images: it reads user-data and meta-data from a datasource (NoCloud ISO, config drive, metadata service) to set hostname, users, SSH keys, network, packages and run commands.
1. cloud-init customises VMs at first boot.
2. Use with cloud images and templates.
3. Check logs in guest.
4. Keep secrets out of user-data where possible.
5. Validate schema.
user-data → cloud-init → configured VM
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 Checks Verify boundary
cloud-init status --long→status: done.- Hostname, users and keys applied.
- No errors in
/var/log/cloud-init.log.
Step 2 Common mistakes Narrow the fault
- Image captured without
cloud-init clean, so it does not run again. - YAML errors (validate with
cloud-init schema --config-file user-data). - No datasource attached (cloud-init drive missing).
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.
- cloud-init runs per instance ID; clones may not rerun.
- Wrong datasource = nothing applied.
- YAML errors silently skip modules.
cloud-init status --long— guest resultqm cloudinit dump <vmid> user— Proxmox user-datacloud-init schema --config-file user-data— validate YAML
ReferenceWhy it matters1 section · depth on demand
Datasources
| Platform | Datasource |
|---|---|
| Proxmox | NoCloud (cloud-init drive) |
| vSphere | VMware (guestinfo) or OVF |
| OpenStack | ConfigDrive/metadata service |
| Public clouds | Provider metadata service |
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
cloud-init configures a VM on first boot from metadata: hostname, users and SSH keys, network, packages, files and commands. Hypervisors provide the data through a config drive (NoCloud ISO in Proxmox, OVF/vApp properties or guestinfo in VMware, VHD with NoCloud in Hyper-V).
#cloud-config
hostname: web01
users:
- name: ops
groups: sudo
shell: /bin/bash
ssh_authorized_keys: ["ssh-ed25519 AAAA… ops@admin"]
package_update: true
packages: [qemu-guest-agent]
runcmd: [systemctl enable --now qemu-guest-agent]
Debug: cloud-init status --long, /var/log/cloud-init.log, cloud-init query --all.
Example user-data
#cloud-config
hostname: web01
users:
- name: patrick
ssh_authorized_keys: [ "ssh-ed25519 AAAA..." ]
sudo: ALL=(ALL) NOPASSWD:ALL
package_update: true
packages: [ qemu-guest-agent ]
Documented example, not captured output. Check results in the guest with cloud-init status --long and /var/log/cloud-init.log.
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 Automation → Cloud-init. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/html/index.html · confidence 94%