From 7ebf94cc2316dc34be31cbe1064b75ff9b4a15b7 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Tue, 31 Mar 2026 19:55:02 +0200 Subject: [PATCH] Install a one-shot service to initialize hostid --- build-proxmox-template | 9 +++++++-- initialize-host-id | 8 ++++++++ initialize-host-id.service | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 initialize-host-id create mode 100644 initialize-host-id.service diff --git a/build-proxmox-template b/build-proxmox-template index e97a758..d3bb232 100755 --- a/build-proxmox-template +++ b/build-proxmox-template @@ -9,12 +9,13 @@ : "${STORAGE:=local-zfs}" : "${OS:=debian-13}" : "${NAME:=chaos-${OS}-tmpl-$(date -u +%Y-%m-%d)}" -: "${BRIDGE:=vmbr0,tag=208}" +: "${BRIDGE:=vmbr0,tag=2}" : "${AUTHORIZED_KEYS_URL:=https://git.hamburg.ccc.de/CCCHH/infrastructure-authorized-keys/raw/branch/trunk/authorized_keys}" set -eE export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH +here="$(pwd)" tempfolder=$(mktemp -d /tmp/cloudinit-XXXXX) pushd $tempfolder @@ -44,7 +45,11 @@ virt-customize -a disk.raw \ --uninstall openipmi \ --run-command 'systemctl enable qemu-guest-agent' \ --run-command 'systemctl enable fstrim.timer' \ - --run-command 'echo -n >/etc/machine-id' + --run-command 'echo -n >/etc/machine-id' \ + --copy-in ${here}/initialize-host-id:/usr/local/sbin \ + --run-command 'chmod +x /usr/local/sbin/initialize-host-id' \ + --copy-in ${here}/initialize-host-id.service:/etc/systemd/system \ + --run-command 'systemctl enable initialize-host-id.service' qm destroy ${VMID} || true qm create ${VMID} --name "creating-vm" --memory 2048 --net0 virtio,bridge=${BRIDGE} diff --git a/initialize-host-id b/initialize-host-id new file mode 100644 index 0000000..c45255d --- /dev/null +++ b/initialize-host-id @@ -0,0 +1,8 @@ +#!/bin/sh + +# +# Initialize /etc/hostid if it doesn't exist or is empty +# +if [ ! -f /etc/hostid -o "$(cat /etc/hostid 2>/dev/null)" = "" ]; then + hexdump -n 4 -e '"%02x"' /dev/urandom >/etc/hostid +fi diff --git a/initialize-host-id.service b/initialize-host-id.service new file mode 100644 index 0000000..e7cdfa3 --- /dev/null +++ b/initialize-host-id.service @@ -0,0 +1,13 @@ +[Unit] +Description=Initialize /etc/hostid +Documentation=https://git.hamburg.ccc.de/CCCHH/pve-template-vm +After=sysinit.target + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/initialize-host-id +User=root +Restart=never + +[Install] +WantedBy=sysinit.target