Fix machine-id workaround to also work on first boot #242
+19
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To make this work, we have to do two things:
Run the
systemd-machine-id-commit
service only on first bootsystemd-machine-id-commit
does its job just fine if the file containsuninitialized
, even if it's bind mounted from persistent storage. It only misbehaves if the file contains an actual machine-id, since it then thinks it needs to be committed.This can be worked around by only running the service on the first boot.
Create the machine-id file with the string
uninitialized
in itOur standard handling of non-existent files is to create a symlink, but this makes systemd behave a bit strangely. It follows the symlink and creates the
uninitialized
machine-id at the linked location. Then it bind mounts a newly generated machine-id over the file in persistent storage. This works, but it seems to confusesystemd-machine-id-commit
since the file is not actually a bind mount over /etc/machine-id, so the machine-id will not be committed on this boot cycle and will still containuninitialized
on the next boot. This makes the next boot also recognized as the “first boot”. This time, however,systemd-machine-id-commit
does its job, since the file is a bind mount to persistent storage.The workaround for this is to just skip the symlinking step and go straight to bind mounting. However, since the file needs to exist to be bind mounted, we also have to create it with the string
uninitialized
as its contents.