44a72b9
From 3a5ffde6675f952785d39593bb5038e8f827b22d Mon Sep 17 00:00:00 2001
44a72b9
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
44a72b9
Date: Wed, 18 Oct 2017 18:47:34 +0200
44a72b9
Subject: [PATCH] man: describe how machine-id should be initialized (#7051)
44a72b9
44a72b9
(cherry picked from commit 74a79c657e17fc43172a59f1f158d4a26aec2be1)
44a72b9
(cherry picked from commit 07ba9da0bc0d4e3309e766d3734ac56683d3298d)
44a72b9
---
44a72b9
 man/machine-id.xml | 90 +++++++++++++++++++++++++++++++++++++++++-------------
44a72b9
 1 file changed, 69 insertions(+), 21 deletions(-)
44a72b9
44a72b9
diff --git a/man/machine-id.xml b/man/machine-id.xml
44a72b9
index 3c261bffcc..e434c89de9 100644
44a72b9
--- a/man/machine-id.xml
44a72b9
+++ b/man/machine-id.xml
44a72b9
@@ -53,18 +53,26 @@
44a72b9
   <refsect1>
44a72b9
     <title>Description</title>
44a72b9
 
44a72b9
-    <para>The <filename>/etc/machine-id</filename> file contains the unique machine ID of the local
44a72b9
-    system that is set during installation. The machine ID is a single newline-terminated,
44a72b9
-    hexadecimal, 32-character, lowercase ID. When decoded from hexadecimal, this corresponds to a
44a72b9
-    16-byte/128-bit value.</para>
44a72b9
+    <para>The <filename>/etc/machine-id</filename> file contains the unique machine ID of
44a72b9
+    the local system that is set during installation or boot. The machine ID is a single
44a72b9
+    newline-terminated, hexadecimal, 32-character, lowercase ID. When decoded from
44a72b9
+    hexadecimal, this corresponds to a 16-byte/128-bit value. This ID may not be all
44a72b9
+    zeros.</para>
44a72b9
 
44a72b9
-    <para>The machine ID is usually generated from a random source
44a72b9
-    during system installation and stays constant for all subsequent
44a72b9
-    boots. Optionally, for stateless systems, it is generated during
44a72b9
-    runtime at early boot if it is found to be empty.</para>
44a72b9
+    <para>The machine ID is usually generated from a random source during system
44a72b9
+    installation or first boot and stays constant for all subsequent boots. Optionally,
44a72b9
+    for stateless systems, it is generated during runtime during early boot if necessary.
44a72b9
+    </para>
44a72b9
 
44a72b9
-    <para>The machine ID does not change based on local or network configuration or when hardware is
44a72b9
-    replaced. Due to this and its greater length, it is a more useful replacement for the
44a72b9
+    <para>The machine ID may be set, for example when network booting, with the
44a72b9
+    <varname>systemd.machine_id=</varname> kernel command line parameter or by passing the
44a72b9
+    option <option>--machine-id=</option> to systemd. An ID is specified in this manner
44a72b9
+    has higher priority and will be used instead of the ID stored in
44a72b9
+    <filename>/etc/machine-id</filename>.</para>
44a72b9
+
44a72b9
+    <para>The machine ID does not change based on local or network configuration or when
44a72b9
+    hardware is replaced. Due to this and its greater length, it is a more useful
44a72b9
+    replacement for the
44a72b9
     <citerefentry project='man-pages'><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>
44a72b9
     call that POSIX specifies.</para>
44a72b9
 
44a72b9
@@ -79,19 +87,59 @@
44a72b9
     the original machine ID from the application-specific one. The
44a72b9
     <citerefentry><refentrytitle>sd_id128_get_machine_app_specific</refentrytitle><manvolnum>3</manvolnum></citerefentry>
44a72b9
     API provides an implementation of such an algorithm.</para>
44a72b9
+  </refsect1>
44a72b9
 
44a72b9
-    <para>The
44a72b9
+  <refsect1>
44a72b9
+    <title>Initialization</title>
44a72b9
+
44a72b9
+    <para>Each machine should have a non-empty ID in normal operation. The ID of each
44a72b9
+    machine should be unique. To achive those objectives,
44a72b9
+    <filename>/etc/machine-id</filename> can be initialized in a few different ways.
44a72b9
+    </para>
44a72b9
+
44a72b9
+    <para>For normal operating system installations, where a custom image is created for a
44a72b9
+    specific machine, <filename>/etc/machine-id</filename> should be populated during
44a72b9
+    installation.</para>
44a72b9
+
44a72b9
+    <para>
44a72b9
     <citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44a72b9
-    tool may be used by installer tools to initialize the machine ID
44a72b9
-    at install time. Use
44a72b9
-    <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44a72b9
-    to initialize it on mounted (but not booted) system images.</para>
44a72b9
-
44a72b9
-    <para>The machine-id may also be set, for example when network
44a72b9
-    booting, by setting the <varname>systemd.machine_id=</varname>
44a72b9
-    kernel command line parameter or passing the option
44a72b9
-    <option>--machine-id=</option> to systemd. A machine-id may not
44a72b9
-    be set to all zeros.</para>
44a72b9
+    may be used by installer tools to initialize the machine ID at install time, but
44a72b9
+    <filename>/etc/machine-id</filename> may also be written using any other means.
44a72b9
+    </para>
44a72b9
+
44a72b9
+    <para>For operating system images which are created once and used on multiple
44a72b9
+    machines, for example for containers or in the cloud,
44a72b9
+    <filename>/etc/machine-id</filename> should be an empty file in the generic file
44a72b9
+    system image. An ID will be generated during boot and saved to this file if
44a72b9
+    possible. Having an empty file in place is useful because it allows a temporary file
44a72b9
+    to be bind-mounted over the real file, in case the image is used read-only.</para>
44a72b9
+
44a72b9
+    <para><citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44a72b9
+    may be used to to initialize <filename>/etc/machine-id</filename> on mounted (but not
44a72b9
+    booted) system images.</para>
44a72b9
+
44a72b9
+    <para>When a machine is booted with
44a72b9
+    <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44a72b9
+    the ID of the machine will be established. If <varname>systemd.machine_id=</varname>
44a72b9
+    or <option>--machine-id=</option> options (see first section) are specified, this
44a72b9
+    value will be used. Otherwise, the value in <filename>/etc/machine-id</filename> will
44a72b9
+    be used. If this file is empty or missing, <filename>systemd</filename> will attempt
44a72b9
+    to use the D-Bus machine ID from <filename>/var/lib/dbus/machine-id</filename>, the
44a72b9
+    value of the kernel command line option <varname>container_uuid</varname>, the KVM DMI
44a72b9
+    <filename>product_uuid</filename> (on KVM systems), and finally a randomly generated
44a72b9
+    UUID.</para>
44a72b9
+
44a72b9
+    <para>After the machine ID is established,
44a72b9
+    <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>
44a72b9
+    will attempt to save it to <filename>/etc/machine-id</filename>. If this fails, it
44a72b9
+    will attempt to bind-mount a temporary file over <filename>/etc/machine-id</filename>.
44a72b9
+    It is an error if the file system is read-only and does not contain a (possibly empty)
44a72b9
+    <filename>/etc/machine-id</filename> file.</para>
44a72b9
+
44a72b9
+    <para><citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
44a72b9
+    will attempt to write the machine ID to the file system if
44a72b9
+    <filename>/etc/machine-id</filename> or <filename>/etc</filename> are read-only during
44a72b9
+    early boot but become writable later on.</para>
44a72b9
   </refsect1>
44a72b9
 
44a72b9
   <refsect1>