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