fix(template): clear machine-id in Prepare-LinuxBuild2404 (Step 7b)
Each Ubuntu clone derived from the same snapshot shared an identical machine-id, causing systemd-networkd to use the same DHCP client-id and receive the same NAT IP triggering IP collision failures. Step 7b truncates /etc/machine-id and removes /var/lib/dbus/machine-id before the snapshot is taken. On first boot each clone generates a fresh machine-id from /dev/urandom -> unique DHCP client-id -> unique IP.
This commit is contained in:
@@ -374,6 +374,20 @@ if ($failures.Count -gt 0) {
|
|||||||
}
|
}
|
||||||
Write-Host "[Prepare] All post-setup checks passed." -ForegroundColor Green
|
Write-Host "[Prepare] All post-setup checks passed." -ForegroundColor Green
|
||||||
|
|
||||||
|
# ── Step 7b — Clear machine-id (DHCP uniqueness for clones) ──────────────────
|
||||||
|
# Each clone boots with an empty machine-id; systemd generates a fresh one from
|
||||||
|
# /dev/urandom on first boot. Without this, all clones share the same DHCP
|
||||||
|
# client-id and receive the same IP from VMware DHCP — causing IP collisions.
|
||||||
|
Write-Host "[Prepare] Step 7b — Clearing machine-id for DHCP uniqueness..."
|
||||||
|
Invoke-SshCommand -IP $VMIPAddress -User $CloudUser -KeyPath $SshKeyPath `
|
||||||
|
-Command 'sudo truncate -s 0 /etc/machine-id && sudo rm -f /var/lib/dbus/machine-id'
|
||||||
|
Assert-Step 'MachineId' '/etc/machine-id is empty' {
|
||||||
|
$size = (Invoke-SshCommand -IP $VMIPAddress -User $CloudUser -KeyPath $SshKeyPath `
|
||||||
|
-Command 'stat -c %s /etc/machine-id' -PassThru).Trim()
|
||||||
|
$size -eq '0'
|
||||||
|
}
|
||||||
|
Write-Host "[Prepare] machine-id cleared — each clone will generate a unique ID on first boot." -ForegroundColor Green
|
||||||
|
|
||||||
# ── Step 8 — Shutdown + snapshot ─────────────────────────────────────────────
|
# ── Step 8 — Shutdown + snapshot ─────────────────────────────────────────────
|
||||||
if ($TakeSnapshot -or $VMXPath -ne '') {
|
if ($TakeSnapshot -or $VMXPath -ne '') {
|
||||||
Write-Host "[Prepare] Step 8 — Sending graceful shutdown to guest..."
|
Write-Host "[Prepare] Step 8 — Sending graceful shutdown to guest..."
|
||||||
|
|||||||
Reference in New Issue
Block a user