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