diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-09-30 12:50:40 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-10-01 11:35:46 +0200 |
commit | 7cd43e34c5a302ff323c013f437092d2ff5ccbbf (patch) | |
tree | c17ee76a58c31ad2efe833a1ff4823f71d5b762c /man/machine-id.xml | |
parent | firstboot: add debug logging (diff) | |
download | systemd-7cd43e34c5a302ff323c013f437092d2ff5ccbbf.tar.xz systemd-7cd43e34c5a302ff323c013f437092d2ff5ccbbf.zip |
manager: fix/change evaluation of ConditionFirstBoot
The code to evaluate the kernel command line option was busted because it
was doing 'return b == !!r' at a point where 'r > 0'. Thus we'd return "true"
in both cases:
$ SYSTEMD_PROC_CMDLINE=systemd.condition-first-boot build/systemd-analyze condition 'ConditionFirstBoot=true'
test.service: ConditionFirstBoot=true succeeded.
Conditions succeeded.
$ SYSTEMD_PROC_CMDLINE=systemd.condition-first-boot build/systemd-analyze condition 'ConditionFirstBoot=false'
test.service: ConditionFirstBoot=false succeeded.
Conditions succeeded.
We only use 'ConditionFirstBoot=true' in units, so this wasn't noticed.
But I think the logic is broken in general: the condition should evaluate as
true only during initial boot. If we rerun the units at later points, we should
not consider ConditionFirstBoot to be true.
Also, the first boot logic is also used in pid1 itself. AFAICT, for two
things: in first boot machine-id is initialized transiently (this allows
first-boot operations to be restarted if boot fails), and preset-all is
executed. But this logic was different and separate from the logic to
evaluate ConditionFirstBoot. The distinction is abolished, and the operations
in pid1 now use the same logic as ConditionFirstBoot, which means that the
kernel command line option is checked, and condition_test_first_boot()
just tests whether pid1 thinks we're in first boot.
This makes things easier to grok for the user: there's just one condition for
"first boot" and it applies to both pid1 and units.
Diffstat (limited to 'man/machine-id.xml')
-rw-r--r-- | man/machine-id.xml | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/man/machine-id.xml b/man/machine-id.xml index 9bd49582fc..b40e26bbab 100644 --- a/man/machine-id.xml +++ b/man/machine-id.xml @@ -119,20 +119,26 @@ <refsect1> <title>First Boot Semantics</title> - <para><filename>/etc/machine-id</filename> is used to decide whether a boot is the first one. The rules + <para><filename>/etc/machine-id</filename> is used to decide whether a boot is the first one. The rules are as follows:</para> <orderedlist> - <listitem><para>If <filename>/etc/machine-id</filename> does not exist, this is a first boot. During - early boot, <command>systemd</command> will write <literal>uninitialized\n</literal> to this file and overmount - a temporary file which contains the actual machine ID. Later (after <filename>first-boot-complete.target</filename> - has been reached), the real machine ID will be written to disk.</para></listitem> + <listitem><para>The kernel command argument <varname>systemd.condition-first-boot=</varname> may be + used to override the autodetection logic, see + <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry>. + </para></listitem> + + <listitem><para>Otherwise, if <filename>/etc/machine-id</filename> does not exist, this is a first + boot. During early boot, <command>systemd</command> will write <literal>uninitialized\n</literal> to + this file and overmount a temporary file which contains the actual machine ID. Later (after + <filename>first-boot-complete.target</filename> has been reached), the real machine ID will be written + to disk.</para></listitem> <listitem><para>If <filename>/etc/machine-id</filename> contains the string <literal>uninitialized</literal>, - a boot is also considered the first boot. The same mechanism as above applies.</para></listitem> + a boot is also considered the first boot. The same mechanism as above applies.</para></listitem> <listitem><para>If <filename>/etc/machine-id</filename> exists and is empty, a boot is - <emphasis>not</emphasis> considered the first boot. <command>systemd</command> will still bind-mount a file + <emphasis>not</emphasis> considered the first boot. <command>systemd</command> will still bind-mount a file containing the actual machine-id over it and later try to commit it to disk (if <filename>/etc/</filename> is writable).</para></listitem> @@ -140,8 +146,8 @@ not a first boot.</para></listitem> </orderedlist> - <para>If by any of the above rules, a first boot is detected, units with <varname>ConditionFirstBoot=yes</varname> - will be run.</para> + <para>If according to the above rules a first boot is detected, units with + <varname>ConditionFirstBoot=yes</varname> will be run.</para> </refsect1> <refsect1> |