microsoft / azurelinux

Linux OS for Azure 1P services and edge appliances
MIT License
4.08k stars 497 forks source link

Clear systemd state when creating an image #9509

Closed dmcilvaney closed 1 day ago

dmcilvaney commented 1 week ago
Merge Checklist

All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)


Summary

The systemd package creates /etc/machine-id when it installs (in m2 it did not create this file). If this file is populated on a vm image, every instance of that vm will have the same id. This will break networking, k8s, etc. To avoid this, we need to clear the state before creating the image. The correct first-boot behavior is to set the id to 'uninitialized' and let the system generate a new one on boot. Clearing the file is similar, systemd will generate a new id on boot, but it will not run the first-boot setup.

We will keep the current behavior with /etc/machine-id being empty. A new config flag will allow an image to use the first-boot flow.

As part of https://systemd.io/BUILDING_IMAGES several other files are listed that should be cleared out. Currently we don't seem to have them but for correctness I've also included a check that will delete them if found. 

Change Log
Does this affect the toolchain?

NO

Associated issues
Test Methodology
dmcilvaney commented 1 week ago

Some interesting data points:

tldr, first boot seems to be the preferred path in modern systemd distros

dmcilvaney commented 6 days ago

Per some discussions, going to keep old behavior (ie /etc/machine-id="")