From b06b9e80768d66faa8fe25217d7a6493214c3d9e Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Sun, 18 Oct 2026 13:34:32 +0200 Subject: [PATCH] Increase default memory allocation and implement fallback for qemu-guest-agent installation via cloud-init. --- create-template.sh | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/create-template.sh b/create-template.sh index 33f4319..da6aabb 100644 --- a/create-template.sh +++ b/create-template.sh @@ -9,7 +9,7 @@ VMID="${VMID:-9000}" STORAGE="${STORAGE:-local-lvm}" # where the disk + cloud-init drive live BRIDGE="${BRIDGE:-vmbr0}" CORES="${CORES:-2}" -MEMORY="${MEMORY:-1024}" # MiB +MEMORY="${MEMORY:-2048}" # MiB DISK_SIZE="${DISK_SIZE:-20G}" # final root disk size (must be > image size, ~3.5G) ARCH="${ARCH:-amd64}" # amd64 or arm64 CHANNEL="${CHANNEL:-lts}" # lts = newest LTS, latest = newest release incl. interim @@ -17,6 +17,7 @@ CI_USER="${CI_USER:-niklas}" CI_PASSWORD="${CI_PASSWORD:-}" # optional; leave empty to rely on SSH keys only SSH_KEY_FILE="${SSH_KEY_FILE:-$HOME/.ssh/authorized_keys}" INSTALL_QGA="${INSTALL_QGA:-1}" # bake qemu-guest-agent into the image (needs libguestfs-tools) +SNIPPET_STORAGE="${SNIPPET_STORAGE:-local}" # fallback: install QGA via cloud-init vendor snippet stored here BASE_URL="https://cloud-images.ubuntu.com/releases" # ---------- sanity checks ---------- @@ -59,15 +60,25 @@ echo "==> Verifying checksum..." grep " \*\?${IMG_NAME}\$" SHA256SUMS | sed 's/\*//' | sha256sum -c - || die "checksum mismatch, image is cooked" # ---------- optional: bake in qemu-guest-agent ---------- +QGA_VIA_SNIPPET=0 if [[ "$INSTALL_QGA" == "1" ]]; then if ! command -v virt-customize >/dev/null; then echo "==> Installing libguestfs-tools for virt-customize..." apt-get update -qq && apt-get install -y -qq libguestfs-tools fi echo "==> Installing qemu-guest-agent into image..." - virt-customize -a "$IMG_NAME" \ - --install qemu-guest-agent \ - --truncate /etc/machine-id + # Work on a copy so a half-failed customize can't leave the image in a weird state + cp "$IMG_NAME" custom.img + if virt-customize -a custom.img \ + --install qemu-guest-agent \ + --truncate /etc/machine-id; then + mv -f custom.img "$IMG_NAME" + else + rm -f custom.img + echo "WARN: virt-customize couldn't install qemu-guest-agent (usually no network/DNS inside the libguestfs appliance)." + echo " Falling back to installing it via cloud-init on first boot." + QGA_VIA_SNIPPET=1 + fi fi # ---------- create VM ---------- @@ -108,6 +119,30 @@ if [[ ! -f "$SSH_KEY_FILE" && -z "$CI_PASSWORD" ]]; then echo "WARN: no SSH key AND no password set. You won't be able to log in until you set one in the Cloud-Init tab." fi +# ---------- fallback: QGA via cloud-init vendor data ---------- +if [[ "$QGA_VIA_SNIPPET" == "1" ]]; then + if pvesm status --content snippets 2>/dev/null | awk 'NR>1 {print $1}' | grep -qx "$SNIPPET_STORAGE"; then + SNIPPET_REF="${SNIPPET_STORAGE}:snippets/qga-vendor.yaml" + SNIPPET_PATH=$(pvesm path "$SNIPPET_REF") + mkdir -p "$(dirname "$SNIPPET_PATH")" + cat > "$SNIPPET_PATH" <<'EOF' +#cloud-config +packages: + - qemu-guest-agent +runcmd: + - systemctl start qemu-guest-agent +EOF + # vendor data only adds to Proxmox's generated user data, so ciuser/sshkeys still apply + qm set "$VMID" --cicustom "vendor=${SNIPPET_REF}" + echo "==> Clones will install qemu-guest-agent on first boot (needs internet on the clone)." + else + echo "WARN: storage '$SNIPPET_STORAGE' doesn't allow snippets, so no guest agent fallback." + echo " Enable it (add 'snippets' to the existing content list), e.g.:" + echo " pvesm set $SNIPPET_STORAGE --content iso,vztmpl,backup,snippets" + echo " then rerun, or just 'apt install qemu-guest-agent' inside each clone." + fi +fi + # ---------- convert to template ---------- echo "==> Converting to template..." qm template "$VMID"