Creating Proxmox Cloud-Init VM Ubuntu 20.04

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

Preparing Template

Download cloud image Ubuntu 20.04:

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

Create VM:

qm create 9020 --memory 2048 --net0 virtio,bridge=vmbr0,tag=18 --agent enabled=1 --cores 2 --ostype l26 --name ubuntu20-template

Import downloaded image as disk in local-lvm:

qm importdisk 9020 focal-server-cloudimg-amd64.img local-lvm

adding imported disk to vm:

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

extending disk size:

qm resize 9020 scsi0 +8G

setting limits to virtual disk:

qm set 9020 --scsi0 local-lvm:base-9120-disk-0,mbps_rd=100,mbps_wr=100,iops_rd=100,iops_wr=100

Adding to VM cloud init disk:

qm set 9020 --scsi2 local-lvm:cloudinit

setting up boot disk:

qm set 9020 --boot c --bootdisk scsi0

setting up console output via xterm.js:

qm set 9020 --serial0 socket --vga serial0

setting up cloudinit VM options:

qm set 9020 --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

Leave a Reply