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