Creating Proxmox Cloud-Init VM Ubuntu 22.04

All in one step
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img \
  && qm create 9022 --memory 2048 --net0 virtio,bridge=vmbr0,tag=8 --agent enabled=1 --cores 2 --ostype l26 --name ubuntu22-template \
  && qm importdisk 9022 jammy-server-cloudimg-amd64.img local-lvm \
  && qm set 9022 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9022-disk-0 \
  && qm resize 9022 scsi0 16G \
  && qm set 9022 --scsi0 local-lvm:vm-9022-disk-0,mbps_rd=200,mbps_wr=200,iops_rd=400,iops_wr=400 \
  && qm set 9022 --scsi2 local-lvm:cloudinit \
  && qm set 9022 --boot c --bootdisk scsi0 \
  && qm set 9022 --serial0 socket --vga serial0 \
  && echo Finished

Preparing Template

Download cloud image Ubuntu 22.04:

wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img

Create VM:

qm create 9022 --memory 2048 --net0 virtio,bridge=vmbr0,tag=8 --agent enabled=1 --cores 2 --ostype l26 --name ubuntu22-template

Import downloaded image as disk in local-lvm:

qm importdisk 9022 jammy-server-cloudimg-amd64.img local-lvm

adding imported disk to vm:

qm set 9022 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9022-disk-0

extending disk size:

qm resize 9022 scsi0 16G

setting limits to virtual disk:

qm set 9022 --scsi0 local-lvm:vm-9022-disk-0,mbps_rd=200,mbps_wr=200,iops_rd=400,iops_wr=400

Adding to VM cloud init disk:

qm set 9022 --scsi2 local-lvm:cloudinit

setting up boot disk:

qm set 9022 --boot c --bootdisk scsi0

setting up console output via xterm.js:

qm set 9022 --serial0 socket --vga serial0

setting up cloudinit VM options:

qm set 9022 --ciuser user_example --cipassword password_example --searchdomain corp.example.com --nameserver 10.0.1.11,10.0.1.12 --ipconfig0 ip=10.0.8.251/24,gw=10.0.8.1 --sshkeys /path/to/id_rsa.pub

Preparing system

Updating system

sudo apt update && sudo apt dist-upgrade -y

Enabling bash autocompletion of root user, by uncommenting these lines in file /root/.bashrc:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Setting up the correct time zone, in my case Asia/Almaty

sudo dpkg-reconfigure tzdata