#!/bin/bash #Create template #args: # vm_id # vm_name # file name in the current directory function create_template() { #Print all of the configuration echo "Creating template $2 ($1)" # Always create new templates. Never use linked clones. qm stop "$1" qm destroy "$1" #Create new VM #Feel free to change any of these to your liking qm create "$1" --name "$2" --memory 1024 --cores 2 --ostype l26 --net0 virtio,bridge=vmbr0 # Set storage qm importdisk "$1" "$3" "$storage" qm set "$1" --scsihw virtio-scsi-pci --scsi0 vmpool:vm-"$1"-disk-0 #Set scsi hardware as default boot disk using virtio scsi single qm set $1 --boot c --bootdisk scsi0 #Add cloud-init device qm set "$1" --ide2 ${storage}:cloudinit #Set display to serial qm set "$1" --serial0 socket --vga serial0 #Enable Qemu guest agent in case the guest has it available qm set "$1" --agent enabled=1 #Make it a template qm template "$1" #Set CI ip config #IP6 = auto means SLAAC (a reliable default with no bad effects on non-IPv6 networks) #IP = DHCP means what it says, so leave that out entirely on non-IPv4 networks to avoid DHCP delays qm set "$1" --ipconfig0 "ip=dhcp" #Add the user qm set "$1" --ciuser ${username} #Import the ssh keyfile (only one). Add others in gui. qm set "$1" --sshkeys ${ssh_keyfile1} #If you want to do password-based auth instaed #Then use this option and comment out the line above qm set "$1" --cipassword "Merlin69" qm set "$1" --nameserver "172.20.10.54,172.20.10.53" qm set "$1" --searchdomain "thedacus.lan" } iso_path="/bkuppool/other/template/iso" #Path to your ssh authorized_keys file #Alternatively, use /etc/pve/priv/authorized_keys if you are already authorized #on the Proxmox system export ssh_keyfile1="/root/.ssh/2023nasa01_id_rsa.pub" #Username to create on VM template export username=bdacus01 #Name of your storage export storage=vmpool #The images that I've found premade #Feel free to add your own cd $iso_path || return ## Debian #Bullseye (11) wget -O "debian-11-cloud-amd64.qcow2" "https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2" create_template 901 "temp-debian-11" "debian-11-cloud-amd64.qcow2" #Bookworm (12) wget -O "debian-12-cloud-amd64.qcow2" "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2" create_template 902 "temp-debian-12" "debian-12-cloud-amd64.qcow2" ## Ubuntu #20.04 (Focal Fossa) wget -O "ubuntu-20.04-server-cloud-amd64.img" "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img" create_template 910 "temp-ubuntu-20-04" "ubuntu-20.04-server-cloud-amd64.img" #22.04 (Jammy Jellyfish) wget -O "ubuntu-22.04-server-cloud-amd64.img" "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" create_template 911 "temp-ubuntu-22-04" "ubuntu-22.04-server-cloud-amd64.img" ## Rocky Linux # Rocky 8 wget -O "Rocky-8-Cloud-x86_64.qcow2" https://dl.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2 create_template 920 "temp-rocky-8" "Rocky-8-Cloud-x86_64.qcow2" #Rocky 9 wget -O "Rocky-9-Cloud-x86_64.qcow2" https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 create_template 921 "temp-rocky-9" "Rocky-8-Cloud-x86_64.qcow2"