Cloud Init Templates in Proxmox VE - Quickstart

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

The simplest and most efficient way to deploy Linux VMs in Proxmox VE is to use so-called Cloud-Init images. These images are custom-made installation media that are offered by mostly every well-known Linux distribution like, for example, Debian, Ubuntu or CentOS. Proxmox VE has already been supporting Cloud-Init deployments since some versions.

Hint: We have presented Cloudinit in a beginner webinar: https://www.youtube.com/watch?v=EKn7lTJrOW8&t

Advantages over .ISO

Advantages compared to ISO images:

  • The operating system does not have to be installed manually, but starts automatically after deploying.
  • Various parameters can be specified for each template clone via the Proxmox VE interface.
  • Before deployment, you can use various tools such as libguestfs-tools to make adjustments to the images:
    • Integration of software packages via package manager
    • Modify of files as desired before deployment
    • Setting a root password or creating a new user

Cloud Init parameter within PVE

The following parameters can be viewed within the created Cloud-Init drives in the Proxmox VE surface:

  • User (a user is created)
  • Password (a password is set)
  • DNS domain (DNS Domain Override to PVE-Host Default)
  • DNS servers (DNS Server Override toPVE-Host Default)
  • SSH public key (a personal SSH public key)
  • Upgrade packages yes (the image is completely updated during initial start-up)
  • IP Config (net0) (IP configuration for the first network device, static or DHCP)

Preparation of Cloud-Init images

Below is a template with the ID 9500, which contains our recommended best practices for a VM installation in PVE. Some parameters still need to be adapted to your infrastructure, for example, the path where the image is to be downloaded.

Ubuntu 22.04 Cloud image

apt update -y && apt install libguestfs-tools -y
cd /mnt/pve/cephfs/template/iso/

wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img &&
virt-customize -a /mnt/pve/cephfs/template/iso/jammy-server-cloudimg-amd64.img --install qemu-guest-agent &&
virt-customize -a /mnt/pve/cephfs/template/iso/jammy-server-cloudimg-amd64.img --root-password password:Relation123! &&
virt-customize -a /mnt/pve/cephfs/template/iso/jammy-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"

A current Ubuntu 22.04 Cloud-Init image is downloaded, libguestfs-tools are installed and are used for injecting the Qemu guest agent afterwards. Furthermore, a default root password is set and the /etc/maschine-id is reset.

Ubuntu 24.04. Cloud image

apt update -y && apt install libguestfs-tools -y
cd /mnt/pve/cephfs/template/iso/

wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img &&
virt-customize -a /mnt/pve/cephfs/template/iso/noble-server-cloudimg-amd64.img --install qemu-guest-agent &&
virt-customize -a /mnt/pve/cephfs/template/iso/noble-server-cloudimg-amd64.img --root-password password:Relation123!&&
virt-customize -a /mnt/pve/cephfs/template/iso/noble-server-cloudimg-amd64.img --run-command "echo -n > /etc/machine-id"

Debian 12 (Bookworm) Cloud image

apt update -y && apt install libguestfs-tools -y &&
cd /mnt/pve/cephfs/template/iso/ &&

wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 &&
virt-customize -a /mnt/pve/cephfs/template/iso/debian-12-generic-amd64.qcow2 --install qemu-guest-agent &&
virt-customize -a /mnt/pve/cephfs/template/iso/debian-12-generic-amd64.qcow2 --root-password password:Relation123!&&
virt-customize -a /mnt/pve/cephfs/template/iso/debian-12-generic-amd64.qcow2 --run-command "echo -n > /etc/machine-id"

Generate Cloud-Init template

Important:The snippet assumes, for example, that the folder configs exists under /mnt/pve/cephfs and that there is a file authorized_keys there. If necessary, you may need to comment this out beforehand or create the folder and file.

### Cloudinit Template VM erstellen (Ubuntu 24.04)

qm create 9501 --name "ubuntu-2404-ci" --memory 8192 --cores 4 --net0 virtio,bridge=vmbr0 &&
qm importdisk 9501 /mnt/pve/cephfs/template/iso/noble-server-cloudimg-amd64.img vm_nvme &&
qm set 9501 --scsihw virtio-scsi-single --scsi0 vm_nvme:vm-9501-disk-0,cache=writeback,discard=on,ssd=1 &&
qm set 9501 --scsi1 vm_nvme:60,cache=writeback,discard=on,ssd=1 &&
qm set 9501 --boot c --bootdisk scsi0 &&
qm set 9501 --scsi2 vm_nvme:cloudinit &&
qm set 9501 --agent enabled=1 &&
qm resize 9501 scsi0 +27748M &&
qm set 9501 --serial0 socket &&
qm set 9501 --vga serial0 &&
qm set 9501 --cpu cputype=host &&
qm set 9501 --ostype l26 &&
qm set 9501 --balloon 4096 &&
qm set 9501 --ciupgrade 1 &&
qm set 9501 --ciuser ansible &&
qm set 9501 --ipconfig0 ip=dhcp &&
qm set 9501 --nameserver 192.168.110.61 &&
qm set 9501 --searchdomain pmx.local &&
qm set 9501 --sshkeys /mnt/pve/cephfs/configs/authorized_keys &&
qm template 9501

These commands create a template, which you can use via Proxmox VE surface or via command line afterwards. To do this, right-click on the template within the PVE web UI to create a clone, and then enjoy the newly created virtual machine with all your customizations.


Author: Jonas Sterr

Jonas Sterr has been working for Thomas-Krenn for several years. Originally employed as a trainee in technical support and then in hosting (formerly Filoo), Mr. Sterr now mainly deals with the topics of storage (SDS / Huawei / Netapp), virtualization (VMware, Proxmox, HyperV) and network (switches, firewalls) in product management at Thomas-Krenn.AG in Freyung.


Translator: Alina Ranzinger

Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.


Related articles

Creation of Proxmox Ubuntu 24.04 server VM
ESXi VM importer - Proxmox VE Storage Plugin
Proxmox Remote Migration