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