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 was updated 8 November 2021 to provide a link to updating the Cloud-Init images with ‘qemu-guest-agent’ which is an essential tool when you’re running these services for your clients.

Normally Cloud-Init is installed like so:

apt-get install cloud-init

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

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

We’ve included scripts for Ubuntu, CentOS 7, and Debian. There are 8 steps per distribution. All that changes is the VM ID 9xxx and the download file.

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

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