Skip to content

Instantly share code, notes, and snippets.

@ironwolphern
Last active June 6, 2025 19:46
Show Gist options
  • Save ironwolphern/9c2c5841a1382a3fc28fdc57408dd4a0 to your computer and use it in GitHub Desktop.
Save ironwolphern/9c2c5841a1382a3fc28fdc57408dd4a0 to your computer and use it in GitHub Desktop.
This script will download a cloud image and deploy it as a template in Proxmox VE
#!/bin/bash
# This script will download a cloud image and deploy it as a template in Proxmox VE
# Tested on Proxmox VE 8.4.1
clear
# Default values for cloud template
MEMORY="512"
DISK_SIZE="5G"
STORAGE="local-lvm"
NET_IFACE="vmbr0"
# Menu to select cloud template to deploy
printf "Select an image linux to deploy how a cloud template in Proxmox:\n"
PS3="Select an option [1-11]: "
OPTIONS=("Ubuntu Server Minimal 24.04 LTS" "Ubuntu Server Minimal 25.04" "Debian 12" "CentOS Stream 9" "CentOS Stream 10" "Fedora Server 42" "Arch Linux 2025.06.01" "OpenSUSE Leap Micro 6.1" "Alpine Linux 3.22.0" "Flatcar 4152.2.3" "Quit")
select opt in "${OPTIONS[@]}"; do
case "${opt}" in
"Ubuntu Server Minimal 24.04 LTS")
printf "\nYou selected Ubuntu Server Minimal 24.04 LTS\n"
printf "Downloading cloud image...\n"
# https://cloud-images.ubuntu.com/minimal/releases/noble/release/SHA256SUMS
IMAGE="https://cloud-images.ubuntu.com/minimal/releases/noble/release/ubuntu-24.04-minimal-cloudimg-amd64.img"
DST="ubuntu-24.04-minimal-cloudimg-amd64.img"
ID_VM=9000
VM_NAME="ubuntu-server-24.04"
break
;;
"Ubuntu Server Minimal 25.04")
printf "\nYou selected Ubuntu Server Minimal 25.04\n"
printf "Downloading cloud image...\n"
# https://cloud-images.ubuntu.com/minimal/releases/plucky/release/SHA256SUMS
IMAGE="https://cloud-images.ubuntu.com/minimal/releases/plucky/release/ubuntu-25.04-minimal-cloudimg-amd64.img"
DST="ubuntu-25.04-minimal-cloudimg-amd64.img"
ID_VM=9001
VM_NAME="ubuntu-server-25.04"
break
;;
"Debian 12")
printf "\nYou selected Debian 12\n"
printf "Downloading cloud image...\n"
# https://cloud.debian.org/images/cloud/bookworm/latest/SHA512SUMS
IMAGE="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2"
DST="debian-12-nocloud-amd64.qcow2"
ID_VM=9002
VM_NAME="debian-12"
break
;;
"CentOS Stream 9")
printf "\nYou selected CentOS Stream 9\n"
printf "Downloading cloud image...\n"
# https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2.SHA256SUM
IMAGE="https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2"
DST="CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2"
ID_VM=9003
VM_NAME="centos-Stream-9"
break
;;
"CentOS Stream 10")
printf "\nYou selected CentOS Stream 10\n"
printf "Downloading cloud image...\n"
# https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2.SHA256SUM
IMAGE="https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2"
DST="CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2"
ID_VM=9004
VM_NAME="centos-Stream-10"
break
;;
"Fedora Server 42")
printf "\nYou selected Fedora Server 42\n"
printf "Downloading cloud image...\n"
# https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-42-1.1-x86_64-CHECKSUM
IMAGE="https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
DST="Fedora-Cloud-Base-Generic.x86_64-42-1.1.qcow2"
ID_VM=9005
VM_NAME="fedora-server-42"
break
;;
"Arch Linux 2025.06.01")
printf "\nYou selected Arch Linux 2025.06.01\n"
printf "Downloading cloud image...\n"
# https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2.SHA256
IMAGE="https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2"
DST="Arch-Linux-x86_64-cloudimg.qcow2"
ID_VM=9006
VM_NAME="arch-linux-2025.06.01"
break
;;
"OpenSUSE Leap Micro 6.1")
printf "\nYou selected OpenSUSE Leap Micro 6.1\n"
printf "Downloading cloud image...\n"
# https://download.opensuse.org/distribution/leap-micro/6.1/appliances/openSUSE-Leap-Micro.x86_64-Default-qcow.qcow2.sha256
IMAGE="https://download.opensuse.org/distribution/leap-micro/6.1/appliances/openSUSE-Leap-Micro.x86_64-Default-qcow.qcow2"
DST="openSUSE-Leap-Micro.x86_64-Default-qcow.qcow2"
ID_VM=9007
VM_NAME="opensuse-leap-micro-6.1"
break
;;
"Alpine Linux 3.22.0")
printf "\nYou selected Alpine Linux 3.22.0\n"
printf "Downloading cloud image...\n"
# https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/nocloud_alpine-3.22.0-x86_64-bios-cloudinit-r0.asc
IMAGE="https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/nocloud_alpine-3.22.0-x86_64-bios-cloudinit-r0.qcow2"
DST="nocloud_alpine-3.22.0-x86_64-bios-cloudinit-r0.qcow2"
ID_VM=9008
VM_NAME="alpine-linux-3.22.0"
break
;;
"Flatcar 4152.2.3")
printf "\nYou selected Flatcar 4152.2.3\n"
printf "Downloading cloud image...\n"
# https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_qemu_image.img.DIGESTS
IMAGE="https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_qemu_image.img"
DST="flatcar_production_qemu_image.img"
ID_VM=9009
VM_NAME="flatcar-4152.2.3"
break
;;
"Quit")
exit 0
;;
*)
printf "\nInvalid option, try again.\n"
;;
esac
done
# Download image
wget -O "${DST}" "${IMAGE}"
printf "Uploading cloud image to Proxmox...\n"
# Create a VM with the cloud image and convert to template
qm create "${ID_VM}" --name "${VM_NAME}" --memory "${MEMORY}" --net0 virtio,bridge="${NET_IFACE}" --scsihw virtio-scsi-pci
# Set agent and cpu parameters
qm set "${ID_VM}" --agent enabled=1,fstrim_cloned_disks=1 --cpu cputype=host
# Import cloud image to VM
qm set "${ID_VM}" --scsi0 "${STORAGE}":0,import-from="${PWD}"/"${DST}"
# Set cloud-init parameters
qm set "${ID_VM}" --ide2 "${STORAGE}":cloudinit
qm set "${ID_VM}" --boot order=scsi0
qm set "${ID_VM}" --serial0 socket --vga serial0
# Set network parameters
qm set "${ID_VM}" --ipconfig0 ip=dhcp
# Set disk size
qm disk resize "${ID_VM}" scsi0 "${DISK_SIZE}"
printf "Creating cloud template in Proxmox...\n"
# Convert VM to template
qm template "${ID_VM}"
printf "Cleaning up...\n"
# Remove downloaded image
rm -Rf "${DST}"
printf "Done!\n"
# Then you can create a VM from this templates with terraform and cloud-init
############
# Reference:
# https://pve.proxmox.com/wiki/Cloud-Init_Support
# https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_cloud_init
# https://cloud-images.ubuntu.com/minimal/releases/
# https://cloud.debian.org/images/cloud/
# https://cloud.centos.org/centos/
# https://download.fedoraproject.org/pub/fedora/linux/releases/
# https://geo.mirror.pkgbuild.com/images/latest/
# https://download.opensuse.org/distribution/
# https://dl-cdn.alpinelinux.org/alpine/
# https://stable.release.flatcar-linux.net/amd64-usr/current/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment