Install a one-shot service to initialize hostid
This commit is contained in:
parent
346c3cb5eb
commit
7ebf94cc23
3 changed files with 28 additions and 2 deletions
|
|
@ -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}
|
||||
|
|
|
|||
8
initialize-host-id
Normal file
8
initialize-host-id
Normal file
|
|
@ -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
|
||||
13
initialize-host-id.service
Normal file
13
initialize-host-id.service
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue