Merge pull request #33011 from yuwata/machine-id-setup-follow-ups

machine-id-setup: several follow-ups for #32915
This commit is contained in:
Luca Boccassi
2024-05-25 00:04:11 +02:00
committed by GitHub
2 changed files with 24 additions and 17 deletions

View File

@@ -43,24 +43,31 @@
ID will be acquired in the following fashion:</para>
<orderedlist>
<listitem><para>If a valid D-Bus machine ID is already
configured for the system, the D-Bus machine ID is copied and
used to initialize the machine ID in
<filename>/etc/machine-id</filename>.</para></listitem>
<listitem><para>If a valid machine ID is stored in <filename>/run/machine-id</filename>, the machine ID
is copied and used to initialize the machine ID in <filename>/etc/machine-id</filename>. This step is
skipped if <option>--root=</option> is specified or running in a chroot environment.</para></listitem>
<listitem><para>If run inside a KVM virtual machine and a UUID
is configured (via the <option>-uuid</option>
option), this UUID is used to initialize the machine ID. The
caller must ensure that the UUID passed is sufficiently unique
and is different for every booted instance of the
VM.</para></listitem>
<listitem><para>If a valid D-Bus machine ID is already configured for the system, the D-Bus machine ID
is copied and used to initialize the machine ID in <filename>/etc/machine-id</filename>.
</para></listitem>
<listitem><para>If a valid machine ID is provided through <option>system.machine_id</option> credential,
the machine ID is copied and used to initialize the machine ID in <filename>/etc/machine-id</filename>.
This step is skipped if <option>--root=</option> is specified or running in a chroot environment.
</para></listitem>
<listitem><para>If run inside a KVM virtual machine and a UUID is configured (via the
<option>-uuid</option> option), this UUID is used to initialize the machine ID. The caller must ensure
that the UUID passed is sufficiently unique and is different for every booted instance of the VM. This
step is skipped if <option>--root=</option> is specified or running in a chroot environment.
</para></listitem>
<listitem><para>Similarly, if run inside a Linux container environment and a UUID is configured for the
container, this is used to initialize the machine ID. For details, see the documentation of the <ulink
url="https://systemd.io/CONTAINER_INTERFACE">Container Interface</ulink>.</para></listitem>
url="https://systemd.io/CONTAINER_INTERFACE">Container Interface</ulink>. This step is skipped if
<option>--root=</option> is specified or running in a chroot environment.</para></listitem>
<listitem><para>Otherwise, a new ID is randomly
generated.</para></listitem>
<listitem><para>Otherwise, a new ID is randomly generated.</para></listitem>
</orderedlist>
<para>The <option>--commit</option> switch may be used to commit a

View File

@@ -55,9 +55,9 @@ static int acquire_machine_id(const char *root, sd_id128_t *ret) {
assert(ret);
/* First, try reading the machine ID from /run/machine-id, which may not be mounted on
* /etc/machine-id yet. This is important on switching root, Otherwise, machine ID may be changed
* after the transition. */
if (empty_or_root(root) && running_in_chroot() <= 0 &&
* /etc/machine-id yet. This is important on switching root especially on soft-reboot, Otherwise,
* machine ID may be changed after the transition. */
if (isempty(root) && running_in_chroot() <= 0 &&
id128_read("/run/machine-id", ID128_FORMAT_PLAIN, ret) >= 0) {
log_info("Reusing machine ID stored in /run/machine-id.");
return 1; /* Indicate that the machine ID is reused. */
@@ -70,7 +70,7 @@ static int acquire_machine_id(const char *root, sd_id128_t *ret) {
return 0;
}
if (empty_or_root(root) && running_in_chroot() <= 0) {
if (isempty(root) && running_in_chroot() <= 0) {
/* Let's use a system credential for the machine ID if we can */
if (acquire_machine_id_from_credential(ret) >= 0)
return 0;