Skip to content

Instantly share code, notes, and snippets.

@talarczykco
Last active September 14, 2022 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talarczykco/d4cfc9188a061f68880ee5b630a4aeb6 to your computer and use it in GitHub Desktop.
Save talarczykco/d4cfc9188a061f68880ee5b630a4aeb6 to your computer and use it in GitHub Desktop.
Provision a Proxmox VM template from an Ubuntu cloud image
#!/bin/bash
# https://gist.github.com/talarczykco/d4cfc9188a061f68880ee5b630a4aeb6
# https://pve.proxmox.com/wiki/Cloud-Init_Support
set -ex
IMGURL=https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
IMGDIR=etc
IMGFILE=$(basename $IMGURL)
VMID=9001
if ! test -f $IMGDIR/$IMGFILE; then
(cd $IMGDIR && wget --no-clobber $IMGURL)
virt-customize -a $IMGDIR/$IMGFILE --install qemu-guest-agent
fi
qm destroy $VMID
qm create $VMID
qm importdisk $VMID $IMGDIR/$IMGFILE local-lvm
qm set $VMID \
--agent enabled=1 \
--boot c \
--bootdisk scsi0 \
--cores 2 \
--ide2 local-lvm:cloudinit \
--memory 2048 \
--name ${IMGFILE%%.img}.tpl \
--net0 virtio,bridge=vmbr0 \
--scsi0 local-lvm:vm-$VMID-disk-0 \
--scsihw virtio-scsi-pci \
--serial0 socket \
--vga serial0
qm template $VMID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment