How to prepare a Cloud-Init Templates with Proxmox

This is an article about the preparation of Cloud-Init images for a Proxmox server to ease the deployment and setup of Virtual Machines. It covers a few common operating system environments such as Ubuntu, Debian, and CentOS.

The article is updated a few times a year or so.

Normally Cloud-Init is installed like so:

apt-get install cloud-init

However, many distributions offers ready-to-use Cloud-Init images as .qcow2 files. For Ubuntu, go here:
https://cloud-images.ubuntu.com/

The one we’re after is animal-server-cloudimg-amd64.img

I’ve included scripts for Ubuntu, CentOS 7, and Debian. There are a number of steps per image. All that changes is the VM ID 9xxx and the download file. Carefully check your syntax if you’re copy these configurations. Typically you don’t want these Image IDs to overlap because it will making things hard to find.

Install Cloud-Init If No Guest Tools

If you can’t find the virt-customize command on your system, you’ll have to install the tools first:

apt install libguestfs-tools

The size of the guest tools on Proxmox VE is about 189 MB.

Instructions for Ubuntu Noble Numbat 24.04 (9401)

In the example below, bold indicates extra customization. Our customizations are:

  • Install the QEMU Guest Agent
  • Install Mutt
  • Allow SSH PasswordAuthentication by using SED find and replace. Please note, this is a security risk. If you are going to forget to disable it after you have added keys, then rather just work with keys.
wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
virt-customize -a noble-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a noble-server-cloudimg-amd64.img --install mutt
virt-customize -a noble-server-cloudimg-amd64.img --run-command "sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes\nChallengeResponseAuthentication yes/' /etc/ssh/sshd_config"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "sed -i '/#PasswordAuthentication yes/ { s//#PasswordAuthentication yes/; a ChallengeResponseAuthentication yes' } /etc/ssh/sshd_config"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "sed -i 's/#PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
virt-customize -a noble-server-cloudimg-amd64.img --run-command "sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
qm create 9401 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9401 noble-server-cloudimg-amd64.img nas02
qm set 9401 --scsihw virtio-scsi-pci --scsi0 nas02:vm-9401-disk-0
qm set 9401 --ide2 nas02:cloudinit
qm set 9401 --boot c --bootdisk scsi0
qm set 9401 --serial0 socket --vga serial0
qm template 9401

Follow up steps

On Proxmox, you’ll also want to turn on protection and enable the QEMU Guest Agent with fstrim_cloned_disks: Enabled

Instructions for Ubuntu Focal 20.04 (9000)

wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
virt-customize -a focal-server-cloudimg-amd64.img --install qemu-guest-agent
[optional for Virtualmin quotas] virt-customize -a focal-server-cloudimg-amd64.img --install linux-image-generic
qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9000 focal-server-cloudimg-amd64.img local-lvm
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --serial0 socket --vga serial0
qm template 9000

virt-customize

See: https://registry.terraform.io/modules/sdhibit/cloud-init-vm/proxmox/latest/examples/ubuntu_single_vm

Instructions for CentOS 7 (9103)

wget https://cloud.centos.org/altarch/7/images/CentOS-7-x86_64-GenericCloud-2111.qcow2c
virt-customize -a CentOS-7-x86_64-GenericCloud-2111.qcow2c --install qemu-guest-agent
virt-customize -a CentOS-7-x86_64-GenericCloud-2111.qcow2c --run-command "sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
qm create 9103 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9103 CentOS-7-x86_64-GenericCloud-2111.qcow2c local-lvm
qm set 9103 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9103-disk-0
qm set 9103 --ide2 local-lvm:cloudinit
qm set 9103 --boot c --bootdisk scsi0
qm set 9103 --serial0 socket --vga serial0
qm template 9103

Updates

11 Nov 2022

  • Added version 2111 instead of version 2009
  • Added both install qemu-guest-agent and PasswordAuthentication customizations
  • Changed identifier from 9001 to 9103

Instructions for Debian 10 – Buster (9104)

Change Log

04 Mar 2023

  • First version, merged from Debian 11 and CentOS 7 configurations and cloud image obtain from web
wget http://cloud.debian.org/images/cloud/buster/20230222-1299/debian-10-generic-amd64-20230222-1299.qcow2
virt-customize -a debian-10-generic-amd64-20230222-1299.qcow2 --install qemu-guest-agent 
virt-customize -a debian-10-generic-amd64-20230222-1299.qcow2 --run-command "sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
qm create 9104 --memory 2048 --net0 virtio,bridge=vmbr0 
qm importdisk 9104 debian-10-generic-amd64-20230222-1299.qcow2 local-lvm 
qm set 9104 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9104-disk-0 
qm set 9104 --ide2 local-lvm:cloudinit 
qm set 9104 --boot c --bootdisk scsi0 
qm set 9104 --serial0 socket --vga serial0 
qm template 9104

Instructions for Debian 11 – Bullseye (9002) – Released 14 August 2021

Source: http://cloud.debian.org/images/cloud/

wget http://cloud.debian.org/images/cloud/bullseye/20210814-734/debian-11-generic-amd64-20210814-734.qcow2
qm create 9002 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9002 debian-11-generic-amd64-20210814-734.qcow2 local-lvm
qm set 9002 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9002-disk-0
qm set 9002 --ide2 local-lvm:cloudinit
qm set 9002 --boot c --bootdisk scsi0
qm set 9002 --serial0 socket --vga serial0
qm template 9002

Instructions for Ubuntu 21.04

wget https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-amd64.img
qm create 9003 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9003 hirsute-server-cloudimg-amd64.img local-lvm
qm set 9003 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9003-disk-0
qm set 9003 --ide2 local-lvm:cloudinit
qm set 9003 --boot c --bootdisk scsi0
qm set 9003 --serial0 socket --vga serial0
qm template 9003

Instructions for Ubuntu 22.04 (9101)

In the example below, bold indicates extra customization. The customizations are:

  • Install the QEMU Guest Agent
  • Allow SSH PasswordAuthentication by using SED find and replace. Please note, this is a security risk so be careful.
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
virt-customize -a jammy-server-cloudimg-amd64.img --run-command "sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
qm create 9101 --memory 2048 --net0 virtio,bridge=vmbr0
qm importdisk 9101 jammy-server-cloudimg-amd64.img local-lvm
qm set 9101 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9101-disk-0
qm set 9101 --ide2 local-lvm:cloudinit
qm set 9101 --boot c --bootdisk scsi0
qm set 9101 --serial0 socket --vga serial0 
qm template 9101

Updates

17 Apr 2024

  • Added Ubuntu 24.04 Noble Numbat

11 Nov 2022

  • Fixed typo for sed command was pointing to a Bionic image

Reference

Share this article

2 thoughts on “How to prepare a Cloud-Init Templates with Proxmox”

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top