what is cloud init

Cloud-init is an open-source initialization tool that automates the configuration of cloud instances, virtual machines (VMs), and bare-metal machines during their first boot. It acts as the industry standard for cross-platform cloud instance initialization and is supported by all major public cloud providers.

Its key functions include:

  • Automated Configuration: Streamlines deployment by applying settings automatically, reducing manual effort.
  • Task Execution: Handles tasks like setting hostname, configuring network, creating user accounts, installing software, and running scripts.
  • User Data and Metadata: Uses “user data” (YAML configuration instructions) and “metadata” (cloud platform data) to configure instances.
  • Consistency and Reusability: Allows consistent and reliable deployments across multiple instances.
  • Integration: Provides the “glue” between launching a cloud instance and connecting to it.

How to enable cloud init for Proxmox VE (PVE)‘s Virtual Machine (vm)

  1. Use a cloud image (recommended) and ensure the guest has cloud-init installed (most cloud images already do). For example, Ubuntu Cloud Images.
  2. In Proxmox VE, attach a Cloud-Init drive to the VM (Hardware → Add → CloudInit), and make sure the main disk is on VirtIO/SCSI and is first in boot order.
  3. Configure Cloud-Init settings in the VM (Cloud-Init tab): user/password or SSH key, DNS, and ipconfig0 (DHCP or static).
  4. Regenerate/apply Cloud-Init and boot the VM (GUI: “Regenerate Image”, then start; CLI: qm cloudinit update <vmid>).

Step by step guide

Here’s a step-by-step “Ubuntu 24.04 LTS (Noble) cloud image → Proxmox VE VM with Cloud-Init” recipe (CLI-first, with GUI equivalents).

Pick the amd64 KVM/QEMU cloud image

  • Pick the amd64 KVM/QEMU cloud image from https://cloud-images.ubuntu.com/noble/current/ (commonly named like noble-server-cloudimg-amd64.img).
  • On the PVE host (example):
    cd /var/lib/vz/template/iso
    wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img

Create an empty VM

Choose a VMID (example: 9000), storage (example: local-lvm), and bridge (example: vmbr0):

  • VMID=122
  • STORAGE=local-lvm
  • BRIDGE=vmbr0
qm create $VMID --name ubuntu-2404-cloud --memory 2048 --cores 2 --net0 virtio,bridge=$BRIDGE
qm create 122 --name ubuntu-2404-cloud --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0

Import the downloaded disk into Proxmox storage

qm importdisk $VMID /var/lib/vz/template/iso/noble-server-cloudimg-amd64.img $STORAGE
qm importdisk 122 /var/lib/vz/template/iso/noble-server-cloudimg-amd64.img vmstripe

Attach the imported disk as the main VM disk (VirtIO-SCSI)

qm set $VMID --scsihw virtio-scsi-single --scsi0 $STORAGE:vm-$VMID-disk-0
qm set 122 --scsihw virtio-scsi-single --scsi0 vmstripe:vm-122-disk-0
 
qm set $VMID --boot order=scsi0
qm set 122 --boot order=scsi0

Add the Cloud-Init drive

qm set $VMID --ide2 $STORAGE:cloudinit
qm set 122 --ide2 vmstripe:cloudinit
qm set $VMID --serial0 socket --vga serial0
qm set 122 --serial0 socket --vga serial0
 
qm set $VMID --agent enabled=1
qm set 122 --agent enabled=1

Configure Cloud-Init: user + SSH key + networking

  • DHCP example

    qm set $VMID --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub --ipconfig0 ip=dhcp
    qm set $VMID --ciuser ubuntu --cipassword "your-new-password" --ipconfig0 ip=dhcp
     
    qm set 122 --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub --ipconfig0 ip=dhcp
    qm set 122 --ciuser ubuntu --cipassword "ubuntu" --ipconfig0 ip=dhcp
  • Static IP example

    qm set $VMID --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub --ipconfig0 ip=192.168.1.50/24,gw=192.168.1.1 --nameserver 1.1.1.1
    qm set $VMID --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub --ipconfig0 ip=192.168.1.50/24,gw=192.168.1.1 --nameserver 1.1.1.1

Resize the disk (cloud images are small by default)

  • Example: add 20G:

    qm resize $VMID scsi0 +20G
    qm resize 122 scsi0 +20G

Regenerate/apply Cloud-Init and boot

qm cloudinit update $VMID
qm cloudinit update 122
 
qm start $VMID
qm start 122

Connect and verify inside the VM

  • From PVE console (serial): qm terminal $VMID
  • Inside Ubuntu:
    • cloud-init status —wait
    • ip a
    • sudo growpart /dev/sda 1 && sudo resize2fs /dev/sda1 (only if the root FS didn’t auto-grow; device names can differ)

GUI equivalent (high level)

  • Create VM (don’t add an ISO).
  • Import the .img as a disk (or upload it somewhere accessible), then attach it as SCSI (VirtIO-SCSI).
  • Hardware → Add → CloudInit.
  • Cloud-Init tab → set user, SSH key, DNS, IP config.
  • Options → Boot order: main disk first.
  • Start VM.