pve-template-vm/build-proxmox-template

42 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
#
# Build a disk image suitable for use as a Proxmox template in the CCCHH clusters.
# Needs apt install libguestfs-tools
#
VMID=9023
STORAGE=local-zfs
OS=debian-12
NAME=chaos-${OS}-tmpl
BRIDGE=vmbr0,tag=208
set -e
virt-builder debian-12 -o ${NAME}.qcow2 --format qcow2 \
--root-password password:3500mt \
--update \
--run-command 'apt dist-upgrade -y' \
--install cloud-init,qemu-guest-agent \
--run-command 'systemctl enable qemu-guest-agent' \
--run-command 'systemctl enable fstrim.timer' \
--edit '/etc/default/grub:s,GRUB_CMDLINE_LINUX="",GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0",' \
--edit '/etc/default/grub:s,GRUB_TIMEOUT=.*,GRUB_TIMEOUT=1,' \
--run-command 'update-grub'
qm destroy ${VMID} || true
qm create ${VMID} --name ${NAME} --memory 1024 --net0 virtio,bridge=${BRIDGE}
qm importdisk ${VMID} ${NAME}.qcow2 ${STORAGE}
qm set ${VMID} --scsihw virtio-scsi-pci --scsi0 ${STORAGE}:vm-${VMID}-disk-0,ssd=1,discard=on
qm set ${VMID} --ide2 ${STORAGE}:cloudinit
qm set ${VMID} --boot c --bootdisk scsi0
qm set ${VMID} --serial0 socket --vga serial0
qm set ${VMID} --agent 1,fstrim_cloned_disks=1
qm set ${VMID} --ciuser chaos
qm set ${VMID} --sshkeys ./authorized_keys
qm set ${VMID} --ipconfig0 ip=dhcp
qm cloudinit update ${VMID}
qm template ${VMID}
rm -f ${NAME}.qcow2