├── README.md ├── build-image.sh ├── build-info ├── build-vars └── keyfile /README.md: -------------------------------------------------------------------------------- 1 | # Proxmox-VM-Template 2 | 3 | 4 |
This repo contains the files that I use to deploy a VM template onto Proxmox VE 7.2
5 | 6 |Clone this repo into a directory directly into the Promox node that you are going to work with. Modify the build-vars file to match your environment. You can either chmod the script to execute with sh build-image.sh
7 | 8 | 9 |Please see my blog at https://gtgb.io for more information. 10 | Geek The Grey Beard
11 | -------------------------------------------------------------------------------- /build-image.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This script will download and modify the desired image to prep for template build. 4 | # Script is inspired by 2 separate authors work. 5 | # Austins Nerdy Things: https://austinsnerdythings.com/2021/08/30/how-to-create-a-proxmox-ubuntu-cloud-init-image/ 6 | # What the Server: https://whattheserver.com/proxmox-cloud-init-os-template-creation/ 7 | # requires libguestfs-tools to be installed. 8 | # This script is designed to be run inside the ProxMox VE host environment. 9 | # Modify the install_dir variable to reflect where you have placed the script and associated files. 10 | 11 | . ./build-vars 12 | 13 | # Clean up any previous build 14 | rm ${install_dir}${image_name} 15 | rm ${install_dir}build-info 16 | 17 | # Grab latest cloud-init image for your selected image 18 | wget ${cloud_img_url} 19 | 20 | # insert commands to populate the currently empty build-info file 21 | touch ${install_dir}build-info 22 | echo "Base Image: "${image_name} > ${install_dir}build-info 23 | echo "Packages added at build time: "${package_list} >> ${install_dir}build-info 24 | echo "Build date: "$(date) >> ${install_dir}build-info 25 | echo "Build creator: "${creator} >> ${install_dir}build-info 26 | 27 | virt-customize --update -a ${image_name} 28 | virt-customize --install ${package_list} -a ${image_name} 29 | virt-customize --mkdir ${build_info_file_location} --copy-in ${install_dir}build-info:${build_info_file_location} -a ${image_name} 30 | qm destroy ${build_vm_id} 31 | qm create ${build_vm_id} --memory ${vm_mem} --cores ${vm_cores} --net0 virtio,bridge=vmbr0 --name ${template_name} 32 | qm importdisk ${build_vm_id} ${image_name} ${storage_location} 33 | qm set ${build_vm_id} --scsihw ${scsihw} --scsi0 ${storage_location}:vm-${build_vm_id}-disk-0 34 | qm set ${build_vm_id} --ide0 ${storage_location}:cloudinit 35 | qm set ${build_vm_id} --nameserver ${nameserver} --ostype l26 --searchdomain ${searchdomain} --sshkeys ${keyfile} --ciuser ${cloud_init_user} 36 | qm set ${build_vm_id} --boot c --bootdisk scsi0 37 | #qm set ${build_vm_id} --serial0 socket --vga serial0 38 | qm set ${build_vm_id} --agent enabled=1 39 | qm template ${build_vm_id} 40 | -------------------------------------------------------------------------------- /build-info: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geektx/Proxmox-VM-Template/fb62a12f80d33f76f220c56d1376ff83b7979470/build-info -------------------------------------------------------------------------------- /build-vars: -------------------------------------------------------------------------------- 1 | 2 | # Change this line to reflect the VMID you would like to use for the template. 3 | # Select an ID such as 9999 that will be unique to the node. 4 | build_vm_id='ENTER-VMID-FOR-TEMPLATE' 5 | 6 | # What directory do you have all of the files in? Use a trailing / 7 | install_dir='/WHAT-DIRECTORY-ARE-WE-IN/' 8 | 9 | # Who are you? 10 | creator='YOURNAMEHERE' 11 | 12 | # Create this file and add your SSH keys 1 per line 13 | keyfile=${install_dir}keyfile 14 | 15 | # Enter the URL for the cloud-init image you would like to you. Below are Ubuntu Focal 16 | # and Ubuntu Kinetic. For Focal I like to refresh weekly and Kinetic daily. Uncomment 17 | # the distro you would like to use. 18 | cloud_img_url='https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img' 19 | #cloud_img_url='https://cloud-images.ubuntu.com/kinetic/current/kinetic-server-cloudimg-amd64.img' 20 | 21 | # Leave this variable alone 22 | image_name=${cloud_img_url##*/} 23 | 24 | # Enter the additional packages you would like in your template. 25 | package_list='cloud-init,qemu-guest-agent,curl,wget' 26 | 27 | # What storage location on your PVE node do you want to use for the template? (zfs-mirror, local-lvm, local, etc.) 28 | storage_location='zfs-mirror' 29 | 30 | # VM options 31 | 32 | # Your preferred DNS 33 | nameserver='ENTER-NS-IP-HERE' 34 | # Your domain (ie, domain.com, domain.local, domain) 35 | searchdomain='ENTER-SEARCH-DOMAIN-HERE' 36 | 37 | # Username for accessing the image 38 | cloud_init_user='CLOUD-INIT-USERNAME-HERE' 39 | 40 | # Default setting is the most common 41 | scsihw='virtio-scsi-pci' 42 | 43 | # What to name your template. This is free form with no spaces and will be used for automation/deployments. 44 | template_name='YOUR-TEMPLATE-NAME' 45 | 46 | # Memory and CPU cores. These are overridden with image deployments or through the PVE interface. 47 | vm_mem='2048' 48 | vm_cores='2' 49 | 50 | # Where to store the build-info file in the template for easy identification. 51 | build_info_file_location='/etc/DIRNAME-HERE' 52 | -------------------------------------------------------------------------------- /keyfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geektx/Proxmox-VM-Template/fb62a12f80d33f76f220c56d1376ff83b7979470/keyfile --------------------------------------------------------------------------------