Increase default memory allocation and implement fallback for qemu-guest-agent installation via cloud-init.
This commit is contained in:
+39
-4
@@ -9,7 +9,7 @@ VMID="${VMID:-9000}"
|
|||||||
STORAGE="${STORAGE:-local-lvm}" # where the disk + cloud-init drive live
|
STORAGE="${STORAGE:-local-lvm}" # where the disk + cloud-init drive live
|
||||||
BRIDGE="${BRIDGE:-vmbr0}"
|
BRIDGE="${BRIDGE:-vmbr0}"
|
||||||
CORES="${CORES:-2}"
|
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)
|
DISK_SIZE="${DISK_SIZE:-20G}" # final root disk size (must be > image size, ~3.5G)
|
||||||
ARCH="${ARCH:-amd64}" # amd64 or arm64
|
ARCH="${ARCH:-amd64}" # amd64 or arm64
|
||||||
CHANNEL="${CHANNEL:-lts}" # lts = newest LTS, latest = newest release incl. interim
|
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
|
CI_PASSWORD="${CI_PASSWORD:-}" # optional; leave empty to rely on SSH keys only
|
||||||
SSH_KEY_FILE="${SSH_KEY_FILE:-$HOME/.ssh/authorized_keys}"
|
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)
|
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"
|
BASE_URL="https://cloud-images.ubuntu.com/releases"
|
||||||
|
|
||||||
# ---------- sanity checks ----------
|
# ---------- sanity checks ----------
|
||||||
@@ -59,15 +60,25 @@ echo "==> Verifying checksum..."
|
|||||||
grep " \*\?${IMG_NAME}\$" SHA256SUMS | sed 's/\*//' | sha256sum -c - || die "checksum mismatch, image is cooked"
|
grep " \*\?${IMG_NAME}\$" SHA256SUMS | sed 's/\*//' | sha256sum -c - || die "checksum mismatch, image is cooked"
|
||||||
|
|
||||||
# ---------- optional: bake in qemu-guest-agent ----------
|
# ---------- optional: bake in qemu-guest-agent ----------
|
||||||
|
QGA_VIA_SNIPPET=0
|
||||||
if [[ "$INSTALL_QGA" == "1" ]]; then
|
if [[ "$INSTALL_QGA" == "1" ]]; then
|
||||||
if ! command -v virt-customize >/dev/null; then
|
if ! command -v virt-customize >/dev/null; then
|
||||||
echo "==> Installing libguestfs-tools for virt-customize..."
|
echo "==> Installing libguestfs-tools for virt-customize..."
|
||||||
apt-get update -qq && apt-get install -y -qq libguestfs-tools
|
apt-get update -qq && apt-get install -y -qq libguestfs-tools
|
||||||
fi
|
fi
|
||||||
echo "==> Installing qemu-guest-agent into image..."
|
echo "==> Installing qemu-guest-agent into image..."
|
||||||
virt-customize -a "$IMG_NAME" \
|
# Work on a copy so a half-failed customize can't leave the image in a weird state
|
||||||
--install qemu-guest-agent \
|
cp "$IMG_NAME" custom.img
|
||||||
--truncate /etc/machine-id
|
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
|
fi
|
||||||
|
|
||||||
# ---------- create VM ----------
|
# ---------- 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."
|
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
|
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 ----------
|
# ---------- convert to template ----------
|
||||||
echo "==> Converting to template..."
|
echo "==> Converting to template..."
|
||||||
qm template "$VMID"
|
qm template "$VMID"
|
||||||
|
|||||||
Reference in New Issue
Block a user