Last active
September 14, 2022 00:57
-
-
Save talarczykco/d4cfc9188a061f68880ee5b630a4aeb6 to your computer and use it in GitHub Desktop.
Provision a Proxmox VM template from an Ubuntu cloud image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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