pve-template-vm/build-proxmox-template

44 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-07-30 11:51:42 +02:00
#!/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
2023-07-30 23:52:22 +02:00
virt-builder ${OS} -o ${NAME}.qcow2 --format qcow2 \
2023-07-30 12:12:37 +02:00
--root-password disabled \
2023-07-30 11:51:42 +02:00
--update \
--run-command 'apt dist-upgrade -y' \
--install cloud-init,qemu-guest-agent \
--run-command 'systemctl enable qemu-guest-agent' \
2023-07-30 12:02:09 +02:00
--run-command 'systemctl enable fstrim.timer' \
2023-07-30 11:51:42 +02:00
--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,' \
2023-07-30 13:52:53 +02:00
--run-command 'update-grub' \
--edit '/etc/ssh/sshd_config:s,#?Port.*,Port 42666,' \
2023-07-30 11:51:42 +02:00
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
2023-08-06 01:40:41 +02:00
qm resize ${VMID} scsi0 16G
2023-07-30 11:51:42 +02:00
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