Compare commits

...

4 Commits

Author SHA1 Message Date
MickLesk
e62bbbb256 fix: add warning when virt-customize fallback fails completely 2026-02-22 13:22:35 +01:00
MickLesk
febab23549 Merge branch 'fix/docker-vm-virt-customize-error-handling' of https://github.com/community-scripts/ProxmoxVE into fix/docker-vm-virt-customize-error-handling 2026-02-22 13:09:38 +01:00
MickLesk
57e06a5ef5 docker-vm: add error handling for virt-customize finalize steps
The hostname, machine-id and dbus cleanup calls were missing
|| true, so when virt-customize fails (e.g. on newer distros)
the whole script aborts. The SSH config calls already had
|| true, these were just missed.

Cloud-Init will set the hostname on first boot anyway.

Ref #12073
2026-02-20 21:12:41 +01:00
MickLesk
e2e8fa5b72 fix(docker-vm): add error handling for virt-customize finalization
The hostname/machine-id virt-customize calls had no error handling,
unlike the SSH config calls just below them which already use || true.
When virt-customize fails (e.g. on certain Debian 13 images), the
script aborted instead of continuing gracefully.
These steps are not critical — Cloud-Init can set the hostname later.

Closes #12073
2026-02-20 21:08:14 +01:00

View File

@@ -525,9 +525,9 @@ fi
msg_info "Finalizing image (hostname, SSH config)"
# Set hostname and prepare for unique machine-id
virt-customize -q -a "$WORK_FILE" --hostname "${HN}" >/dev/null 2>&1
virt-customize -q -a "$WORK_FILE" --run-command "truncate -s 0 /etc/machine-id" >/dev/null 2>&1
virt-customize -q -a "$WORK_FILE" --run-command "rm -f /var/lib/dbus/machine-id" >/dev/null 2>&1
virt-customize -q -a "$WORK_FILE" --hostname "${HN}" >/dev/null 2>&1 || true
virt-customize -q -a "$WORK_FILE" --run-command "truncate -s 0 /etc/machine-id" >/dev/null 2>&1 || true
virt-customize -q -a "$WORK_FILE" --run-command "rm -f /var/lib/dbus/machine-id" >/dev/null 2>&1 || true
# Configure SSH for Cloud-Init
if [ "$USE_CLOUD_INIT" = "yes" ]; then
@@ -552,7 +552,7 @@ msg_ok "Finalized image"
# Create first-boot Docker install script (fallback if virt-customize failed)
if [ "$DOCKER_PREINSTALLED" = "no" ]; then
virt-customize -q -a "$WORK_FILE" --run-command 'cat > /root/install-docker.sh << "DOCKERSCRIPT"
if virt-customize -q -a "$WORK_FILE" --run-command 'cat > /root/install-docker.sh << "DOCKERSCRIPT"
#!/bin/bash
exec > /var/log/install-docker.log 2>&1
echo "[$(date)] Starting Docker installation"
@@ -581,9 +581,9 @@ systemctl restart docker
touch /root/.docker-installed
echo "[$(date)] Docker installation completed"
DOCKERSCRIPT
chmod +x /root/install-docker.sh' >/dev/null 2>&1
chmod +x /root/install-docker.sh' >/dev/null 2>&1; then
virt-customize -q -a "$WORK_FILE" --run-command 'cat > /etc/systemd/system/install-docker.service << "DOCKERSERVICE"
virt-customize -q -a "$WORK_FILE" --run-command 'cat > /etc/systemd/system/install-docker.service << "DOCKERSERVICE"
[Unit]
Description=Install Docker on First Boot
After=network-online.target
@@ -598,7 +598,11 @@ RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
DOCKERSERVICE
systemctl enable install-docker.service' >/dev/null 2>&1
systemctl enable install-docker.service' >/dev/null 2>&1 || true
else
msg_warn "virt-customize failed for this image. Docker must be installed manually after first boot:"
msg_warn " curl -fsSL https://get.docker.com | sh"
fi
fi
# Resize disk to target size