]>
Commit | Line | Data |
---|---|---|
d7ccca2e | 1 | <?xml version='1.0'?> <!--*-nxml-*--> |
3a54a157 | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
0307f791 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> |
d7ccca2e LP |
5 | |
6 | <refentry id="machine-id"> | |
798d3a52 ZJS |
7 | <refentryinfo> |
8 | <title>machine-id</title> | |
9 | <productname>systemd</productname> | |
798d3a52 ZJS |
10 | </refentryinfo> |
11 | ||
12 | <refmeta> | |
13 | <refentrytitle>machine-id</refentrytitle> | |
14 | <manvolnum>5</manvolnum> | |
15 | </refmeta> | |
16 | ||
17 | <refnamediv> | |
18 | <refname>machine-id</refname> | |
19 | <refpurpose>Local machine ID configuration file</refpurpose> | |
20 | </refnamediv> | |
21 | ||
22 | <refsynopsisdiv> | |
23 | <para><filename>/etc/machine-id</filename></para> | |
24 | </refsynopsisdiv> | |
25 | ||
26 | <refsect1> | |
27 | <title>Description</title> | |
28 | ||
74a79c65 ZJS |
29 | <para>The <filename>/etc/machine-id</filename> file contains the unique machine ID of |
30 | the local system that is set during installation or boot. The machine ID is a single | |
31 | newline-terminated, hexadecimal, 32-character, lowercase ID. When decoded from | |
32 | hexadecimal, this corresponds to a 16-byte/128-bit value. This ID may not be all | |
33 | zeros.</para> | |
34 | ||
35 | <para>The machine ID is usually generated from a random source during system | |
36 | installation or first boot and stays constant for all subsequent boots. Optionally, | |
37 | for stateless systems, it is generated during runtime during early boot if necessary. | |
38 | </para> | |
39 | ||
40 | <para>The machine ID may be set, for example when network booting, with the | |
41 | <varname>systemd.machine_id=</varname> kernel command line parameter or by passing the | |
42 | option <option>--machine-id=</option> to systemd. An ID is specified in this manner | |
43 | has higher priority and will be used instead of the ID stored in | |
44 | <filename>/etc/machine-id</filename>.</para> | |
45 | ||
46 | <para>The machine ID does not change based on local or network configuration or when | |
47 | hardware is replaced. Due to this and its greater length, it is a more useful | |
48 | replacement for the | |
d48bb46b ZJS |
49 | <citerefentry project='man-pages'><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
50 | call that POSIX specifies.</para> | |
798d3a52 ZJS |
51 | |
52 | <para>This machine ID adheres to the same format and logic as the | |
53 | D-Bus machine ID.</para> | |
54 | ||
70fc4f57 LP |
55 | <para>This ID uniquely identifies the host. It should be considered "confidential", and must not be exposed in |
56 | untrusted environments, in particular on the network. If a stable unique identifier that is tied to the machine is | |
57 | needed for some application, the machine ID or any part of it must not be used directly. Instead the machine ID | |
58 | should be hashed with a cryptographic, keyed hash function, using a fixed, application-specific key. That way the | |
59 | ID will be properly unique, and derived in a constant way from the machine ID but there will be no way to retrieve | |
60 | the original machine ID from the application-specific one. The | |
61 | <citerefentry><refentrytitle>sd_id128_get_machine_app_specific</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
62 | API provides an implementation of such an algorithm.</para> | |
74a79c65 ZJS |
63 | </refsect1> |
64 | ||
65 | <refsect1> | |
66 | <title>Initialization</title> | |
67 | ||
68 | <para>Each machine should have a non-empty ID in normal operation. The ID of each | |
1b2ad5d9 | 69 | machine should be unique. To achieve those objectives, |
74a79c65 ZJS |
70 | <filename>/etc/machine-id</filename> can be initialized in a few different ways. |
71 | </para> | |
72 | ||
73 | <para>For normal operating system installations, where a custom image is created for a | |
74 | specific machine, <filename>/etc/machine-id</filename> should be populated during | |
75 | installation.</para> | |
798d3a52 | 76 | |
74a79c65 | 77 | <para> |
798d3a52 | 78 | <citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
74a79c65 ZJS |
79 | may be used by installer tools to initialize the machine ID at install time, but |
80 | <filename>/etc/machine-id</filename> may also be written using any other means. | |
81 | </para> | |
82 | ||
83 | <para>For operating system images which are created once and used on multiple | |
84 | machines, for example for containers or in the cloud, | |
85 | <filename>/etc/machine-id</filename> should be an empty file in the generic file | |
86 | system image. An ID will be generated during boot and saved to this file if | |
87 | possible. Having an empty file in place is useful because it allows a temporary file | |
88 | to be bind-mounted over the real file, in case the image is used read-only.</para> | |
89 | ||
90 | <para><citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
1b2ad5d9 | 91 | may be used to initialize <filename>/etc/machine-id</filename> on mounted (but not |
74a79c65 ZJS |
92 | booted) system images.</para> |
93 | ||
94 | <para>When a machine is booted with | |
95 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
96 | the ID of the machine will be established. If <varname>systemd.machine_id=</varname> | |
97 | or <option>--machine-id=</option> options (see first section) are specified, this | |
98 | value will be used. Otherwise, the value in <filename>/etc/machine-id</filename> will | |
99 | be used. If this file is empty or missing, <filename>systemd</filename> will attempt | |
100 | to use the D-Bus machine ID from <filename>/var/lib/dbus/machine-id</filename>, the | |
101 | value of the kernel command line option <varname>container_uuid</varname>, the KVM DMI | |
8fa0de65 DJL |
102 | <filename>product_uuid</filename> or the devicetree <filename>vm,uuid</filename> |
103 | (on KVM systems), and finally a randomly generated UUID.</para> | |
74a79c65 ZJS |
104 | |
105 | <para>After the machine ID is established, | |
106 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
107 | will attempt to save it to <filename>/etc/machine-id</filename>. If this fails, it | |
108 | will attempt to bind-mount a temporary file over <filename>/etc/machine-id</filename>. | |
109 | It is an error if the file system is read-only and does not contain a (possibly empty) | |
110 | <filename>/etc/machine-id</filename> file.</para> | |
111 | ||
112 | <para><citerefentry><refentrytitle>systemd-machine-id-commit.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> | |
113 | will attempt to write the machine ID to the file system if | |
114 | <filename>/etc/machine-id</filename> or <filename>/etc</filename> are read-only during | |
115 | early boot but become writable later on.</para> | |
798d3a52 ZJS |
116 | </refsect1> |
117 | ||
118 | <refsect1> | |
119 | <title>Relation to OSF UUIDs</title> | |
120 | ||
121 | <para>Note that the machine ID historically is not an OSF UUID as | |
122 | defined by <ulink url="https://tools.ietf.org/html/rfc4122">RFC | |
123 | 4122</ulink>, nor a Microsoft GUID; however, starting with systemd | |
124 | v30, newly generated machine IDs do qualify as v4 UUIDs.</para> | |
125 | ||
126 | <para>In order to maintain compatibility with existing | |
127 | installations, an application requiring a UUID should decode the | |
128 | machine ID, and then apply the following operations to turn it | |
129 | into a valid OSF v4 UUID. With <literal>id</literal> being an | |
130 | unsigned character array:</para> | |
131 | ||
132 | <programlisting>/* Set UUID version to 4 --- truly random generation */ | |
8d41a963 LP |
133 | id[6] = (id[6] & 0x0F) | 0x40; |
134 | /* Set the UUID variant to DCE */ | |
135 | id[8] = (id[8] & 0x3F) | 0x80;</programlisting> | |
136 | ||
798d3a52 ZJS |
137 | <para>(This code is inspired by |
138 | <literal>generate_random_uuid()</literal> of | |
139 | <filename>drivers/char/random.c</filename> from the Linux kernel | |
140 | sources.)</para> | |
141 | ||
142 | </refsect1> | |
143 | ||
144 | <refsect1> | |
145 | <title>History</title> | |
146 | ||
147 | <para>The simple configuration file format of | |
148 | <filename>/etc/machine-id</filename> originates in the | |
149 | <filename>/var/lib/dbus/machine-id</filename> file introduced by | |
150 | D-Bus. In fact, this latter file might be a symlink to | |
22065311 | 151 | <filename>/etc/machine-id</filename>.</para> |
798d3a52 ZJS |
152 | </refsect1> |
153 | ||
154 | <refsect1> | |
155 | <title>See Also</title> | |
156 | <para> | |
157 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
158 | <citerefentry><refentrytitle>systemd-machine-id-setup</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
3ba3a79d | 159 | <citerefentry project='man-pages'><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
798d3a52 ZJS |
160 | <citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
161 | <citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
162 | <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>, | |
163 | <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
164 | <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
165 | <citerefentry><refentrytitle>systemd-firstboot</refentrytitle><manvolnum>1</manvolnum></citerefentry> | |
166 | </para> | |
167 | </refsect1> | |
d7ccca2e LP |
168 | |
169 | </refentry> |