#!/bin/sh
# PVE IMPORT-ONLY helper for devuan-6-excalibur-ECS01_6-0.2.2_amd64 — run ON A PVE 9.1 HOST after transferring
# the qcow2. Creates a STOPPED, NON-template VM and stops. Generated by
# build-cloud-image.sh (STAGE 1). Adjust VMID/storage.
set -eu
VMID=${1:-9001}; STORAGE=${2:-local-zfs}; BRIDGE=${3:-vmbr0}
QCOW="devuan-6-excalibur-ECS01_6-0.2.2_amd64_20260708.qcow2"
qm create "$VMID" --name devuan-6-excalibur-ECS01_6-0.2.2_amd64 --memory 2048 --cores 2 --cpu host \
  --machine q35 --net0 virtio,bridge=$BRIDGE --ostype l26 \
  --serial0 socket --vga serial0 --scsihw virtio-scsi-single --agent enabled=1
qm importdisk "$VMID" "$QCOW" "$STORAGE"
qm set "$VMID" --scsi0 $STORAGE:vm-$VMID-disk-0,discard=on,ssd=1 --boot order=scsi0
# VM is now CREATED and STOPPED — NOT a template. In the PVE GUI: add a
# Cloud-Init drive + set user / SSH keys / IP on the Cloud-Init tab, then Start.
# Convert to a template ONLY after this image is confirmed working.
# HOST PREREQ for chrony/ptp_kvm: modprobe ptp_kvm on the PVE host so the guest
# sees /dev/ptp0 (the image has NO external NTP fallback by design).
echo "Created STOPPED VM $VMID (devuan-6-excalibur-ECS01_6-0.2.2_amd64). Configure Cloud-Init + Start in the GUI."
