Debian Codegraph @

man/ukify.xml

raw
1 <?xml version="1.0"?>
2 <!--*-nxml-*-->
3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
5 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="ukify" xmlns:xi="http://www.w3.org/2001/XInclude" conditional='ENABLE_UKIFY'>
7
8 <refentryinfo>
9 <title>ukify</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>ukify</refentrytitle>
15 <manvolnum>1</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>ukify</refname>
20 <refpurpose>Combine components into a signed Unified Kernel Image for UEFI systems</refpurpose>
21 </refnamediv>
22
23 <refsynopsisdiv>
24 <cmdsynopsis>
25 <command>ukify</command>
26 <arg choice="opt" rep="repeat">OPTIONS</arg>
27 <arg choice="plain">build</arg>
28 </cmdsynopsis>
29
30 <cmdsynopsis>
31 <command>ukify</command>
32 <arg choice="opt" rep="repeat">OPTIONS</arg>
33 <arg choice="plain">genkey</arg>
34 </cmdsynopsis>
35
36 <cmdsynopsis>
37 <command>ukify</command>
38 <arg choice="opt" rep="repeat">OPTIONS</arg>
39 <arg choice="plain">inspect</arg>
40 <arg choice="plain" rep="repeat">FILE</arg>
41 </cmdsynopsis>
42 </refsynopsisdiv>
43
44 <refsect1>
45 <title>Description</title>
46
47 <para><command>ukify</command> is a tool whose primary purpose is to combine components (usually a
48 kernel, an initrd, and the
49 <citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry> UEFI
50 stub) to create a <ulink url="https://uapi-group.org/specifications/specs/unified_kernel_image/">UAPI.5 Unified
51 Kernel Image (UKI)</ulink> — a single PE binary that boots the system. When the UKI is executed, the stub
52 extracts and boots the embedded linux kernel. The UKI can be started directly by the firmware or through
53 a boot loader. When used with <ulink url="https://www.qemu.org/docs/master/">qemu</ulink>, a UKI can also
54 be executed through "direct kernel boot", see example below.</para>
55
56 <para><command>ukify</command> can also be used generate other types of UKI-like images, in particular
57 extensions. See the description of the <command>build</command> verb below. <command>ukify</command> can
58 also generate certificates and keys for SecureBoot and PCR signing, see the description of the
59 <command>genkey</command> verb below. <command>ukify</command> can also print detailed information about
60 unified kernel images, see the description of <command>inspect</command> verb below.</para>
61 </refsect1>
62
63 <refsect1>
64 <title>Commands</title>
65
66 <para>The following commands are understood:</para>
67
68 <refsect2>
69 <title><command>build</command></title>
70
71 <para>This command creates a Unified Kernel Image. The two primary options that should be specified for
72 the <command>build</command> verb are <varname>Linux=</varname>/<option>--linux=</option>, and
73 <varname>Initrd=</varname>/<option>--initrd=</option>. <varname>Initrd=</varname> accepts multiple
74 whitespace-separated paths and <option>--initrd=</option> can be specified multiple times.</para>
75
76 <para>Additional sections will be inserted into the UKI, either automatically or only if a specific
77 option is provided. See the discussions of
78 <varname>Microcode=</varname>/<option>--microcode=</option>,
79 <varname>Cmdline=</varname>/<option>--cmdline=</option>,
80 <varname>OSRelease=</varname>/<option>--os-release=</option>,
81 <varname>DeviceTree=</varname>/<option>--devicetree=</option>,
82 <varname>DeviceTreeAuto=</varname>/<option>--devicetree-auto=</option>,
83 <varname>HWIDs=</varname>/<option>--hwids=</option>,
84 <varname>Splash=</varname>/<option>--splash=</option>,
85 <varname>PCRPKey=</varname>/<option>--pcrpkey=</option>,
86 <varname>Uname=</varname>/<option>--uname=</option>,
87 <varname>SBAT=</varname>/<option>--sbat=</option>,
88 and <option>--section=</option>
89 below.</para>
90
91 <para><command>ukify</command> can also be used to assemble a PE binary that is not executable but
92 contains auxiliary data, for example additional kernel command line entries.</para>
93
94 <para>If PCR signing keys are provided via the
95 <varname>PCRPrivateKey=</varname>/<option>--pcr-private-key=</option> and
96 <varname>PCRPublicKey=</varname>/<option>--pcr-public-key=</option> or
97 <varname>PCRCertificate=</varname>/<option>--pcr-certificate=</option> options, PCR values that will be seen
98 after booting with the given kernel, initrd, and other sections, will be calculated, signed, and embedded
99 in the UKI.
100 <citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry> is
101 used to perform this calculation and signing.</para>
102
103 <para>The calculation of PCR values is done for specific boot phase paths. Those can be specified with
104 the <varname>Phases=</varname>/<option>--phases=</option> option. If not specified, the default provided
105 by <command>systemd-measure</command> is used. It is also possible to specify the
106 <varname>PCRPrivateKey=</varname>/<option>--pcr-private-key=</option>,
107 <varname>PCRPublicKey=</varname>/<option>--pcr-public-key=</option> or
108 <varname>PCRCertificate=</varname>/<option>--pcr-certificate=</option>, and
109 <varname>Phases=</varname>/<option>--phases=</option> arguments more than once. Signatures will then be
110 performed with each of the specified keys. On the command line, when both <option>--phases=</option> and
111 <option>--pcr-private-key=</option> are used, they must be specified the same number of times, and then
112 the n-th boot phase path set will be signed by the n-th key. This can be used to build different trust
113 policies for different phases of the boot. In the config file, <varname>PCRPrivateKey=</varname>,
114 <varname>PCRPublicKey=</varname>, and <varname>Phases=</varname> are grouped into separate sections,
115 describing separate boot phases. If one of
116 <varname>SigningEngine=</varname>/<option>--signing-engine=</option> or
117 <varname>SigningProvider=</varname>/<option>--signing-provider=</option> is specified, then the private
118 key arguments will be passed verbatim to
119 <citerefentry project='openssl'><refentrytitle>openssl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
120 as URIs, and the public key arguments will be loaded as X.509 certificates, so that signing can be
121 performed with an OpenSSL engine or provider respectively.</para>
122
123 <para>If a SecureBoot signing key is provided via the
124 <varname>SecureBootPrivateKey=</varname>/<option>--secureboot-private-key=</option> option, the resulting
125 PE binary will be signed as a whole, allowing the resulting UKI to be trusted by SecureBoot. Also see the
126 discussion of automatic enrollment in
127 <citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
128 </para>
129
130 <para>If the stub and/or the kernel contain <literal>.sbat</literal> sections they will be merged in
131 the UKI so that revocation updates affecting either are considered when the UKI is loaded by Shim. For
132 more information on SBAT see
133 <ulink url="https://github.com/rhboot/shim/blob/main/SBAT.md">Shim documentation</ulink>.
134 </para>
135 </refsect2>
136
137 <refsect2>
138 <title><command>genkey</command></title>
139
140 <para>This command creates the keys for PCR signing and the key and certificate used for SecureBoot
141 signing. The same configuration options that determine what keys and in which paths will be needed for
142 signing when <command>build</command> is used, here determine which keys will be created. See the
143 discussion of <varname>PCRPrivateKey=</varname>/<option>--pcr-private-key=</option>,
144 <varname>PCRPublicKey=</varname>/<option>--pcr-public-key=</option>, and
145 <varname>SecureBootPrivateKey=</varname>/<option>--secureboot-private-key=</option> below.</para>
146
147 <para>The output files must not exist.</para>
148 </refsect2>
149
150 <refsect2>
151 <title><command>inspect</command></title>
152
153 <para>Display information about the sections in a given binary or binaries.
154 If <option>--all</option> is given, all sections are shown.
155 Otherwise, if <option>--section=</option> option is specified at least once, only those sections are shown.
156 Otherwise, well-known sections that are typically included in an UKI are shown.
157 For each section, its name, size, and sha256-digest is printed.
158 For text sections, the contents are printed.</para>
159
160 <para>Also see the description of <option>-j</option>/<option>--json=</option> and
161 <option>--section=</option>.</para>
162
163 <para>Other tools that may be useful for inspect UKIs:
164 <citerefentry project='man-pages'><refentrytitle>llvm-objdump</refentrytitle><manvolnum>1</manvolnum></citerefentry>
165 <option>-p</option> and <command>pe-inspect</command>.
166 <!-- TODO: add link to pe-inspect man page when it gets one -->
167 </para>
168 </refsect2>
169 </refsect1>
170
171 <refsect1>
172 <title>Configuration settings</title>
173
174 <para>Settings can appear in configuration files (the syntax with <varname
175 index='false'>SomeSetting=<replaceable>value</replaceable></varname>) and on the command line (the syntax
176 with <option index='false'>--some-setting=<replaceable>value</replaceable></option>). For some command
177 line parameters, a single-letter shortcut is also allowed. In the configuration files, the setting must
178 be in the appropriate section, so the descriptions are grouped by section below. When the same setting
179 appears in the configuration file and on the command line, generally the command line setting has higher
180 priority and overwrites the config file setting completely. If some setting behaves differently, this is
181 described below.</para>
182
183 <para>If no config file is provided via the option <option>--config=<replaceable>PATH</replaceable></option>,
184 <command>ukify</command> will try to look for a default configuration file in the following paths in this
185 order: <filename>/etc/systemd/ukify.conf</filename>, <filename>/run/systemd/ukify.conf</filename>,
186 <filename>/usr/local/lib/systemd/ukify.conf</filename>, and <filename>/usr/lib/systemd/ukify.conf</filename>,
187 and then load the first one found. <command>ukify</command> will proceed normally if no configuration file
188 is specified and no default one is found.</para>
189
190 <para>The <replaceable>LINUX</replaceable> and <replaceable>INITRD</replaceable> positional arguments, or
191 the equivalent <varname>Linux=</varname> and <varname>Initrd=</varname> settings, are optional. If more
192 than one initrd is specified, they will all be combined into a single PE section. This is useful to, for
193 example, prepend microcode before the actual initrd.</para>
194
195 <para>The following options and settings are understood:</para>
196
197 <refsect2>
198 <title>Command line-only options</title>
199
200 <variablelist>
201 <varlistentry>
202 <term><option>--config=<replaceable>PATH</replaceable></option></term>
203
204 <listitem><para>Load configuration from the given config file. In general, settings specified in
205 the config file have lower precedence than the settings specified via options. In cases where the
206 command line option does not fully override the config file setting are explicitly mentioned in the
207 descriptions of individual options.</para>
208
209 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
210 </varlistentry>
211
212 <varlistentry>
213 <term><option>--measure</option></term>
214 <term><option>--no-measure</option></term>
215
216 <listitem><para>Enable or disable a call to
217 <citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry>
218 to print pre-calculated PCR values. Defaults to false.</para>
219
220 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
221 </varlistentry>
222
223 <varlistentry>
224 <term><option>--policy-digest</option></term>
225 <term><option>--no-policy-digest</option></term>
226
227 <listitem><para>Enable or disable a call to
228 <citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry>
229 to print pre-calculated TPM2 policy digests. Useful for offline signing of PCR policies.
230 Defaults to false.</para>
231
232 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
233 </varlistentry>
234
235 <varlistentry>
236 <term><option>--section=<replaceable>NAME</replaceable>:<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></option></term>
237 <term><option>--section=<replaceable>NAME</replaceable>:text|binary<optional>@<replaceable>PATH</replaceable></optional></option></term>
238
239 <listitem><para>For all verbs except <command>inspect</command>, the first syntax is used.
240 Specify an arbitrary additional section <literal><replaceable>NAME</replaceable></literal>.
241 The argument may be a literal string, or <literal>@</literal> followed by a path name.
242 This option may be specified more than once. Any sections specified in this fashion will be
243 inserted (in order) before the <literal>.linux</literal> section which is always last.</para>
244
245 <para>For the <command>inspect</command> verb, the second syntax is used.
246 The section <replaceable>NAME</replaceable> will be inspected (if found).
247 If the second argument is <literal>text</literal>, the contents will be printed.
248 If the third argument is given, the contents will be saved to the file named
249 <replaceable>PATH</replaceable>.
250 </para>
251
252 <para>Note that the name is used as-is, and if the section name should start with a dot, it must be
253 included in <replaceable>NAME</replaceable>.</para>
254
255 <xi:include href="version-info.xml" xpointer="v253"/>
256 </listitem>
257 </varlistentry>
258
259 <varlistentry>
260 <term><option>--join-profile=<replaceable>PATH</replaceable></option></term>
261
262 <listitem><para>Takes a path to an existing PE file containing an additional profile to add to the
263 unified kernel image. The profile can be generated beforehand with <command>ukify</command>. The
264 profile does not need to be signed or contain PCR measurements. All UKI PE sections of the
265 specified PE file are copied into the generated UKI. This is useful for generating multi-profile
266 UKIs. Note that this only copies PE sections that are defined by the UKI specification, and ignores
267 any other, for example <literal>.text</literal> or similar.</para>
268
269 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
270 </varlistentry>
271
272 <varlistentry>
273 <term><option>--sign-profile=<replaceable>ID</replaceable></option></term>
274
275 <listitem><para>Takes a profile ID for which signed PCR measurements should be generated by ukify.
276 This option can be used together with <option>--join-profile=</option> when building the final
277 unified kernel image. If not specified, signed PCR measurements will be added for all profiles.
278 </para>
279
280 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
281 </varlistentry>
282
283 <varlistentry>
284 <term><option>--join-pcrsig=<replaceable>PATH</replaceable></option></term>
285 <term><option>--pcrsig=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></option></term>
286
287 <listitem><para><option>--join-pcrsig=</option> takes a path to an existing PE file containing a
288 previously built UKI. <option>--pcrsig=</option> takes a path to an existing pcrsig JSON blob, or
289 a verbatim inline blob. They must be used together, and without specifying any other UKI section
290 parameters. <command>ukify</command> will attach the pcrsig JSON blob to the UKI. This is useful
291 in combination with <option>--policy-digest</option> to create a UKI and then sign the TPM2 policy
292 digests offline.</para>
293
294 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
295 </varlistentry>
296
297 <varlistentry>
298 <term><option>--tools=<replaceable>DIRS</replaceable></option></term>
299
300 <listitem><para>Specify one or more directories with helper tools. <command>ukify</command> will
301 look for helper tools in those directories first, and if not found, try to load them from
302 <varname>$PATH</varname> in the usual fashion.</para>
303
304 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
305 </varlistentry>
306
307 <varlistentry>
308 <term><option>--output=<replaceable>FILENAME</replaceable></option></term>
309
310 <listitem><para>The output filename. If not specified, the name of the
311 <replaceable>LINUX</replaceable> argument, with the suffix <literal>.unsigned.efi</literal> or
312 <literal>.signed.efi</literal> will be used, depending on whether signing for SecureBoot was
313 performed.</para>
314
315 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
316 </varlistentry>
317
318 <varlistentry>
319 <term><option>--summary</option></term>
320
321 <listitem><para>Print a summary of loaded config and exit. This is useful to check how the options
322 from the configuration file and the command line are combined.</para>
323
324 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
325 </varlistentry>
326
327 <varlistentry>
328 <term><option>--all</option></term>
329
330 <listitem><para>Print all sections (with <command>inspect</command> verb).</para>
331
332 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
333 </varlistentry>
334
335 <varlistentry>
336 <term><option>--json</option></term>
337
338 <listitem><para>Generate JSON output (with <command>inspect</command> verb).</para>
339
340 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
341 </varlistentry>
342
343 <xi:include href="standard-options.xml" xpointer="help" />
344 <xi:include href="standard-options.xml" xpointer="version" />
345 </variablelist>
346 </refsect2>
347
348 <refsect2>
349 <title>[UKI] section</title>
350
351 <variablelist>
352 <varlistentry>
353 <term><varname>Linux=<replaceable>LINUX</replaceable></varname></term>
354 <term><option>--linux=<replaceable>LINUX</replaceable></option></term>
355
356 <listitem><para>A path to the kernel binary.</para>
357
358 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
359 </varlistentry>
360
361 <varlistentry>
362 <term><varname>OSRelease=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></varname></term>
363 <term><option>--os-release=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></option></term>
364
365 <listitem><para>The os-release description (the <literal>.osrel</literal> section). The argument
366 may be a literal string, or <literal>@</literal> followed by a path name. If not specified, the
367 <citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry> file
368 will be picked up from the host system. If explicitly set to an empty string, the ".osrel" section
369 is omitted from the UKI (this is not recommended in most cases, and causes the resulting artifact
370 to not be recognized as a UKI by other tools like <command>kernel-install</command>
371 and <command>bootctl</command>).</para>
372
373 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
374 </varlistentry>
375
376 <varlistentry>
377 <term><varname>Cmdline=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></varname></term>
378 <term><option>--cmdline=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></option></term>
379
380 <listitem><para>The kernel command line (the <literal>.cmdline</literal> section). The argument may
381 be a literal string, or <literal>@</literal> followed by a path name. If not specified, no command
382 line will be embedded.</para>
383
384 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
385 </varlistentry>
386
387 <varlistentry>
388 <term><varname>Initrd=<replaceable>INITRD</replaceable>...</varname></term>
389 <term><option>--initrd=<replaceable>LINUX</replaceable></option></term>
390
391 <listitem><para>Zero or more initrd paths. In the configuration file, items are separated by
392 whitespace. The initrds are combined in the order of specification, with the initrds specified in
393 the config file first.</para>
394
395 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
396 </varlistentry>
397
398 <varlistentry>
399 <term><varname>Microcode=<replaceable>UCODE</replaceable></varname></term>
400 <term><option>--microcode=<replaceable>UCODE</replaceable></option></term>
401
402 <listitem><para>Path to initrd containing microcode updates. If not specified, the section
403 will not be present.</para>
404
405 <xi:include href="version-info.xml" xpointer="v256"/></listitem>
406 </varlistentry>
407
408 <varlistentry>
409 <term><varname>Splash=<replaceable>PATH</replaceable></varname></term>
410 <term><option>--splash=<replaceable>PATH</replaceable></option></term>
411
412 <listitem><para>A picture to display during boot (the <literal>.splash</literal> section). The
413 argument is a path to a BMP file. If not specified, the section will not be present.
414 </para>
415
416 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
417 </varlistentry>
418
419 <varlistentry>
420 <term><varname>DeviceTree=<replaceable>PATH</replaceable></varname></term>
421 <term><option>--devicetree=<replaceable>PATH</replaceable></option></term>
422
423 <listitem><para>The devicetree description (the <literal>.dtb</literal> section). The argument is a
424 path to a compiled binary DeviceTree file. If not specified, the section will not be present.
425 </para>
426
427 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
428 </varlistentry>
429
430 <varlistentry>
431 <term><varname>DeviceTreeAuto=<replaceable>PATH</replaceable>...</varname></term>
432 <term><option>--devicetree-auto=<replaceable>PATH</replaceable></option></term>
433
434 <listitem><para>Zero or more automatically selectable DeviceTree files. In the configuration file, items are separated by
435 whitespace. Each DeviceTree will be in a separate <literal>.dtbauto</literal> section.</para>
436
437 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
438 </varlistentry>
439
440 <varlistentry>
441 <term><varname>HWIDs=<replaceable>PATH</replaceable></varname></term>
442 <term><option>--hwids=<replaceable>PATH</replaceable></option></term>
443
444 <listitem><para>The hardware ID device table (the <literal>.hwids</literal> section). The argument
445 is a path to a directory with JSON HWID device description files. Each file needs to contain a
446 single JSON object with a <literal>name</literal>, <literal>compatible</literal> and
447 <literal>hwids</literal> keys. The <literal>name</literal> and <literal>compatible</literal> keys
448 must have string values and the <literal>hwids</literal> key must have a list of strings as value,
449 where the strings must be valid UUIDs that represent CHIDs/HWIDs.
450 Example:
451 <programlisting><xi:include href="ukify_hwid.json.example" parse="text" /></programlisting>
452 Here <literal>Example Laptop 16 Gen 7</literal> is the device <literal>name</literal> (as defined
453 by the manufacturer), <literal>example,laptop-16-g7</literal> is the <literal>compatible</literal>
454 (as defined by the kernel) and <literal>hwids</literal> is an array of CHIDs/HWIDs (extracted i.e.
455 from <command>fwupdtool hwids</command> output). If not specified, and the
456 <literal>/usr/lib/systemd/boot/hwids/[EFI_ARCH]/</literal> directory exists, then the section will
457 be automatically populated from that directory (specify an empty string as the parameter for this
458 option to disable this behavior), otherwise it will not be present. It is recommended to specify
459 this parameter if automatically selectable DeviceTrees are to be used.</para>
460
461 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
462 </varlistentry>
463
464 <varlistentry>
465 <term><varname>Uname=<replaceable>VERSION</replaceable></varname></term>
466 <term><option>--uname=<replaceable>VERSION</replaceable></option></term>
467
468 <listitem><para>Specify the kernel version (as in <command>uname -r</command>, the
469 <literal>.uname</literal> section). If not specified, an attempt will be made to extract the
470 version string from the kernel image. It is recommended to pass this explicitly if known, because
471 the extraction is based on heuristics and not very reliable. If not specified and extraction fails,
472 the section will not be present.</para>
473
474 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
475 </varlistentry>
476
477 <varlistentry>
478 <term><varname>SBAT=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></varname></term>
479 <term><option>--sbat=<replaceable>TEXT</replaceable>|<replaceable>@PATH</replaceable></option></term>
480
481 <listitem><para>SBAT metadata associated with the UKI or addon. SBAT policies are useful to revoke
482 whole groups of UKIs or addons with a single, static policy update that does not take space in
483 DBX/MOKX. If not specified manually, a default metadata entry consisting of
484 <programlisting>uki,1,UKI,uki,1,https://uapi-group.org/specifications/specs/unified_kernel_image/</programlisting>
485 for UKIs and
486 <programlisting>uki-addon,1,UKI Addon,addon,1,https://www.freedesktop.org/software/systemd/man/latest/systemd-stub.html</programlisting>
487 for addons will be used, to ensure it is always possible to revoke them. For more information on
488 SBAT see <ulink url="https://github.com/rhboot/shim/blob/main/SBAT.md">Shim documentation</ulink>.
489 </para>
490
491 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
492 </varlistentry>
493
494 <varlistentry>
495 <term><varname>PCRPKey=<replaceable>PATH</replaceable></varname></term>
496 <term><option>--pcrpkey=<replaceable>PATH</replaceable></option></term>
497
498 <listitem><para>A path to a public key to embed in the <literal>.pcrpkey</literal> section. If not
499 specified, and there's exactly one
500 <varname>PCRPublicKey=</varname>/<option>--pcr-public-key=</option> or
501 <varname>PCRCertificate=</varname>/<option>--pcr-certificate=</option> argument, that key will be
502 used. Otherwise, the section will not be present.</para>
503
504 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
505 </varlistentry>
506
507 <varlistentry>
508 <term><varname>Profile=<replaceable>PATH</replaceable></varname></term>
509 <term><option>--profile=<replaceable>PATH</replaceable></option></term>
510
511 <listitem><para>A path to a UKI profile to place in an <literal>.profile</literal> section. This
512 option is useful for creating multi-profile UKIs, and is typically used in combination with
513 <option>--join-profile=</option>, to extend the specified UKI with an additional profile.</para>
514
515 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
516 </varlistentry>
517
518 <varlistentry>
519 <term><varname>PCRBanks=<replaceable>PATH</replaceable></varname></term>
520 <term><option>--pcr-banks=<replaceable>PATH</replaceable></option></term>
521
522 <listitem><para>A comma or space-separated list of PCR banks to sign a policy for. If not present,
523 all known banks will be used (<literal>sha1</literal>, <literal>sha256</literal>,
524 <literal>sha384</literal>, <literal>sha512</literal>), which will fail if not supported by the
525 system.</para>
526
527 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
528 </varlistentry>
529
530 <varlistentry>
531 <term><varname>SecureBootSigningTool=<replaceable>SIGNER</replaceable></varname></term>
532 <term><option>--signtool=<replaceable>SIGNER</replaceable></option></term>
533
534 <listitem><para>Whether to use <literal>sbsign</literal>, <literal>pesign</literal>, or
535 <literal>systemd-sbsign</literal>. Depending on this choice, different parameters are required in
536 order to sign an image. Defaults to <literal>sbsign</literal>.</para>
537
538 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
539 </varlistentry>
540
541 <varlistentry>
542 <term><varname>SecureBootPrivateKey=<replaceable>SB_KEY</replaceable></varname></term>
543 <term><option>--secureboot-private-key=<replaceable>SB_KEY</replaceable></option></term>
544
545 <listitem><para>A path to a private key to use for signing of the resulting binary. If the
546 <varname>SigningEngine=</varname>/<option>--signing-engine=</option> or
547 <varname>SigningProvider=</varname>/<option>--signing-provider=</option> option is used, this may
548 also be an engine or provider specific designation. This option is required by
549 <varname>SecureBootSigningTool=sbsign</varname>/<option>--signtool=sbsign</option> and
550 <varname>SecureBootSigningTool=systemd-sbsign</varname>/<option>--signtool=systemd-sbsign</option>. </para>
551
552 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
553 </varlistentry>
554
555 <varlistentry>
556 <term><varname>SecureBootCertificate=<replaceable>SB_CERT</replaceable></varname></term>
557 <term><option>--secureboot-certificate=<replaceable>SB_CERT</replaceable></option></term>
558
559 <listitem><para>A path to a certificate to use for signing of the resulting binary. If the
560 <varname>SigningEngine=</varname>/<option>--signing-engine=</option> or
561 <varname>SigningProvider=</varname>/<option>--signing-provider=</option> option is used, this may
562 also be an engine or provider specific designation. This option is required by
563 <varname>SecureBootSigningTool=sbsign</varname>/<option>--signtool=sbsign</option> and
564 <varname>SecureBootSigningTool=systemd-sbsign</varname>/<option>--signtool=systemd-sbsign</option>. </para>
565
566 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
567 </varlistentry>
568
569 <varlistentry>
570 <term><varname>SecureBootCertificateDir=<replaceable>SB_PATH</replaceable></varname></term>
571 <term><option>--secureboot-certificate-dir=<replaceable>SB_PATH</replaceable></option></term>
572
573 <listitem><para>A path to a nss certificate database directory to use for signing of the resulting binary.
574 Takes effect when <varname>SecureBootSigningTool=pesign</varname>/<option>--signtool=pesign</option> is used.
575 Defaults to <filename>/etc/pki/pesign</filename>.</para>
576
577 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
578 </varlistentry>
579
580 <varlistentry>
581 <term><varname>SecureBootCertificateName=<replaceable>SB_CERTNAME</replaceable></varname></term>
582 <term><option>--secureboot-certificate-name=<replaceable>SB_CERTNAME</replaceable></option></term>
583
584 <listitem><para>The name of the nss certificate database entry to use for signing of the resulting binary.
585 This option is required by <varname>SecureBootSigningTool=pesign</varname>/<option>--signtool=pesign</option>.</para>
586
587 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
588 </varlistentry>
589
590 <varlistentry>
591 <term><varname>SecureBootCertificateValidity=<replaceable>DAYS</replaceable></varname></term>
592 <term><option>--secureboot-certificate-validity=<replaceable>DAYS</replaceable></option></term>
593
594 <listitem><para>Period of validity (in days) for a certificate created by
595 <command>genkey</command>. Defaults to 3650, i.e. 10 years.</para>
596
597 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
598 </varlistentry>
599
600 <varlistentry>
601 <term><varname>SigningEngine=<replaceable>ENGINE</replaceable></varname></term>
602 <term><option>--signing-engine=<replaceable>ENGINE</replaceable></option></term>
603
604 <listitem><para>An OpenSSL engine to be used for signing the resulting binary and PCR measurements,
605 see
606 <citerefentry project='openssl'><refentrytitle>openssl-engine</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
607 </para>
608
609 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
610 </varlistentry>
611
612 <varlistentry>
613 <term><varname>SigningProvider=<replaceable>PROVIDER</replaceable></varname></term>
614 <term><option>--signing-provider=<replaceable>PROVIDER</replaceable></option></term>
615
616 <listitem><para>An OpenSSL provider to be used for signing the resulting binary and PCR
617 measurements, see
618 <citerefentry project='openssl'><refentrytitle>provider</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
619 This option can only be used when <command>systemd-sbsign</command> is used as the signing
620 tool.</para>
621
622 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
623 </varlistentry>
624
625 <varlistentry>
626 <term><varname>CertificateProvider=<replaceable>PROVIDER</replaceable></varname></term>
627 <term><option>--certificate-provider=<replaceable>PROVIDER</replaceable></option></term>
628
629 <listitem><para>An OpenSSL provider to be used for loading the certificate used to sign the
630 resulting binary and PCR measurements, see
631 <citerefentry project='openssl'><refentrytitle>provider</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
632 This option can only be used when <command>systemd-sbsign</command> is used as the signing
633 tool.</para>
634
635 <xi:include href="version-info.xml" xpointer="v257"/></listitem>
636 </varlistentry>
637
638 <varlistentry>
639 <term><varname>SignKernel=<replaceable>BOOL</replaceable></varname></term>
640 <term><option>--sign-kernel</option></term>
641 <term><option>--no-sign-kernel</option></term>
642
643 <listitem><para>Override the detection of whether to sign the Linux binary itself before it is
644 embedded in the combined image. If not specified, it will be signed if a SecureBoot signing key is
645 provided via the
646 <varname>SecureBootPrivateKey=</varname>/<option>--secureboot-private-key=</option> option and the
647 binary has not already been signed. If
648 <varname>SignKernel=</varname>/<option>--sign-kernel</option> is true, and the binary has already
649 been signed, the signature will be appended anyway.</para>
650
651 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
652 </varlistentry>
653 </variablelist>
654 </refsect2>
655
656 <refsect2>
657 <title>[PCRSignature:<replaceable>NAME</replaceable>] section</title>
658
659 <para>In the config file, those options are grouped by section. On the command line, they
660 must be specified in the same order. The sections specified in both sources are combined.
661 </para>
662
663 <variablelist>
664 <varlistentry>
665 <term><varname>PCRPrivateKey=<replaceable>PATH</replaceable></varname></term>
666 <term><option>--pcr-private-key=<replaceable>PATH</replaceable></option></term>
667
668 <listitem><para>A private key to use for signing PCR policies. On the command line, this option may
669 be specified more than once, in which case multiple signatures will be made.</para>
670
671 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
672 </varlistentry>
673
674 <varlistentry>
675 <term><varname>PCRPublicKey=<replaceable>PATH</replaceable></varname></term>
676 <term><option>--pcr-public-key=<replaceable>PATH</replaceable></option></term>
677
678 <listitem><para>A public key to use for signing PCR policies.</para>
679
680 <para>On the command line, this option may be specified more than once, similarly to the
681 <option>--pcr-private-key=</option> option. If not present, the public keys will be extracted from
682 the private keys. On the command line, if present, this option must be specified the same number of
683 times as the <option>--pcr-private-key=</option> option. Cannot be specified if
684 <option>--pcr-certificate=</option> is used.</para>
685
686 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
687 </varlistentry>
688
689 <varlistentry>
690 <term><varname>PCRCertificate=<replaceable>PATH</replaceable></varname></term>
691 <term><option>--pcr-certificate=<replaceable>PATH</replaceable></option></term>
692
693 <listitem><para>An X.509 certificate to use for signing PCR policies.</para>
694
695 <para>On the command line, this option may be specified more than once, similarly to the
696 <option>--pcr-private-key=</option> option. If not present, the public keys will be extracted from
697 the private keys. On the command line, if present, this option must be specified the same number of
698 times as the <option>--pcr-private-key=</option> option. Cannot be specified if
699 <option>--pcr-public-key=</option> is used.</para>
700
701 <xi:include href="version-info.xml" xpointer="v258"/></listitem>
702 </varlistentry>
703
704 <varlistentry>
705 <term><varname>Phases=<replaceable>LIST</replaceable></varname></term>
706 <term><option>--phases=<replaceable>LIST</replaceable></option></term>
707
708 <listitem><para>A comma or space-separated list of colon-separated phase paths to sign a policy
709 for. Each set of boot phase paths will be signed with the corresponding private key. If not
710 present, the default of
711 <citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry>
712 will be used.</para>
713
714 <para>On the command line, when this argument is present, it must appear the same number of times as
715 the <option>--pcr-private-key=</option> option. </para>
716
717 <xi:include href="version-info.xml" xpointer="v253"/></listitem>
718 </varlistentry>
719 </variablelist>
720 </refsect2>
721 </refsect1>
722
723 <refsect1>
724 <title>Examples</title>
725
726 <example>
727 <title>Minimal invocation</title>
728
729 <programlisting>$ ukify build \
730 --linux=/lib/modules/6.0.9-300.fc37.x86_64/vmlinuz \
731 --initrd=/some/path/initramfs-6.0.9-300.fc37.x86_64.img \
732 --cmdline='quiet rw'
733 </programlisting>
734
735 <para>This creates an unsigned UKI <filename>./vmlinuz.unsigned.efi</filename>.</para>
736 </example>
737
738 <example>
739 <title>Direct kernel boot in a virtual machine</title>
740
741 <para>When using <ulink url="https://www.qemu.org/docs/master/">qemu</ulink> with
742 <ulink url="https://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt">OVMF</ulink>
743 (UEFI Firmware for virtual machines) the <option>-kernel</option> switch can be used directly with a
744 UKI. Example:</para>
745
746 <para>
747 <command>qemu-kvm
748 -drive if=pflash,format=qcow2,readonly=on,file=/usr/share/edk2/ovmf/OVMF_CODE_4M.qcow2
749 -kernel <filename index='false'>./vmlinuz.unsigned.efi</filename>
750 <replaceable>[ ... ]</replaceable>
751 </command>
752 </para>
753
754 <para>(The path to the firmware file might need to be adjusted depending on the distribution.) Usually,
755 another <option>-drive</option> argument would to be used to attach an actual disk image, but this
756 is not required.</para>
757 </example>
758
759 <example>
760 <title>All the bells and whistles</title>
761
762 <programlisting>$ ukify build \
763 --linux=/lib/modules/6.0.9-300.fc37.x86_64/vmlinuz \
764 --initrd=early_cpio \
765 --initrd=/some/path/initramfs-6.0.9-300.fc37.x86_64.img \
766 --sbat='sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
767 uki.author.myimage,1,UKI for System,uki.author.myimage,1,https://uapi-group.org/specifications/specs/unified_kernel_image/' \
768 --pcr-private-key=tpm2-pcr-initrd-private-key.pem \
769 --pcr-public-key=tpm2-pcr-initrd-public-key.pem \
770 --phases='enter-initrd' \
771 --pcr-private-key=tpm2-pcr-private-key-system.pem \
772 --pcr-public-key=tpm2-pcr-public-key-system.pem \
773 --phases='enter-initrd:leave-initrd enter-initrd:leave-initrd:sysinit \
774 enter-initrd:leave-initrd:sysinit:ready' \
775 --pcr-banks=sha384,sha512 \
776 --secureboot-private-key=secureboot-private-key.pem \
777 --secureboot-certificate=secureboot-certificate.pem \
778 --sign-kernel \
779 --cmdline='quiet rw rhgb'
780 </programlisting>
781
782 <para>This creates a signed UKI <filename index='false'>./vmlinuz.signed.efi</filename>.
783 The initrd section contains two concatenated parts, <filename index='false'>early_cpio</filename>
784 and <filename index='false'>initramfs-6.0.9-300.fc37.x86_64.img</filename>.
785 The policy embedded in the <literal>.pcrsig</literal> section will be signed for the initrd (the
786 <constant>enter-initrd</constant> phase) with the key
787 <filename index='false'>tpm2-pcr-initrd-private-key.pem</filename>, and for the main system (phases
788 <constant>leave-initrd</constant>, <constant>sysinit</constant>, <constant>ready</constant>) with the
789 key <filename index='false'>tpm2-pcr-private-key-system.pem</filename>. The Linux binary and the resulting
790 combined image will be signed with the SecureBoot key <filename index='false'>secureboot-private-key.pem</filename>.</para>
791 </example>
792
793 <example>
794 <title>All the bells and whistles, via a config file</title>
795
796 <para>This is the same as the previous example, but this time the configuration is stored in a
797 file:</para>
798
799 <programlisting>$ cat ukify.conf
800 [UKI]
801 Initrd=early_cpio
802 Cmdline=quiet rw rhgb
803
804 SecureBootPrivateKey=secureboot-private-key.pem
805 SecureBootCertificate=secureboot-certificate.pem
806 SignKernel=yes
807 PCRBanks=sha384,sha512
808
809 [PCRSignature:initrd]
810 PCRPrivateKey=tpm2-pcr-initrd-private-key.pem
811 PCRPublicKey=tpm2-pcr-initrd-public-key.pem
812 Phases=enter-initrd
813
814 [PCRSignature:system]
815 PCRPrivateKey=tpm2-pcr-private-key-system.pem
816 PCRPublicKey=tpm2-pcr-public-key-system.pem
817 Phases=enter-initrd:leave-initrd
818 enter-initrd:leave-initrd:sysinit
819 enter-initrd:leave-initrd:sysinit:ready
820
821 $ ukify -c ukify.conf build \
822 --linux=/lib/modules/6.0.9-300.fc37.x86_64/vmlinuz \
823 --initrd=/some/path/initramfs-6.0.9-300.fc37.x86_64.img
824 </programlisting>
825
826 <para>One "initrd" (<filename index='false'>early_cpio</filename>) is specified in the config file, and
827 the other initrd (<filename index='false'>initramfs-6.0.9-300.fc37.x86_64.img</filename>) is specified
828 on the command line. This may be useful for example when the first initrd contains microcode for the CPU
829 and does not need to be updated when the kernel version changes, unlike the actual initrd.</para>
830 </example>
831
832 <example>
833 <title>Kernel command line PE addon</title>
834
835 <programlisting>ukify build \
836 --secureboot-private-key=secureboot-private-key.pem \
837 --secureboot-certificate=secureboot-certificate.pem \
838 --cmdline='debug' \
839 --sbat='sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
840 uki-addon.author,1,UKI Addon for System,uki-addon.author,1,https://www.freedesktop.org/software/systemd/man/systemd-stub.html'
841 --output=debug.addon.efi
842 </programlisting>
843
844 <para>This creates a signed PE binary that contains the additional kernel command line parameter
845 <literal>debug</literal> with SBAT metadata referring to the owner of the addon.</para>
846 </example>
847
848 <example>
849 <title>Decide signing policy, and create certificate and keys</title>
850
851 <para>First, let's create a configuration file that specifies what signatures shall be made:</para>
852
853 <programlisting># cat >/etc/kernel/uki.conf &lt;&lt;EOF
854 <xi:include href="uki.conf.example" parse="text" />EOF</programlisting>
855
856 <para>Next, we can generate the certificate and keys:</para>
857 <programlisting># ukify genkey --config=/etc/kernel/uki.conf
858 Writing SecureBoot private key to /etc/kernel/secureboot-private-key.pem
859 Writing SecureBoot certificate to /etc/kernel/secureboot-certificate.pem
860 Writing private key for PCR signing to /etc/systemd/tpm2-pcr-initrd-private-key.pem
861 Writing public key for PCR signing to /etc/systemd/tpm2-pcr-initrd-public-key.pem
862 Writing private key for PCR signing to /etc/systemd/tpm2-pcr-private-key-system.pem
863 Writing public key for PCR signing to /etc/systemd/tpm2-pcr-public-key-system.pem
864 </programlisting>
865
866 <para>(Both operations need to be done as root to allow write access
867 to <filename>/etc/kernel/</filename>.)</para>
868
869 <para>Subsequent invocations using the config file
870 (<command>ukify build --config=/etc/kernel/uki.conf</command>)
871 will use this certificate and key files. Note that the
872 <citerefentry><refentrytitle>kernel-install</refentrytitle><manvolnum>8</manvolnum></citerefentry>
873 plugin <filename>60-ukify.install</filename> uses <filename>/etc/kernel/uki.conf</filename>
874 by default, so after this file has been created, installations of kernels that create a UKI on the
875 local machine using <command>kernel-install</command> will perform signing using this config.</para>
876 </example>
877
878 <example>
879 <title>Multi-Profile UKI</title>
880
881 <para>First, create a few profiles:</para>
882
883 <programlisting>$ ukify build \
884 --profile='TITLE=Base' \
885 --output=profile0.efi
886 </programlisting>
887
888 <para>Add a second profile (@1):</para>
889
890 <programlisting>$ ukify build \
891 --profile='TITLE=Boot into Storage Target Mode
892 ID=storagetm' \
893 --cmdline='quiet rw rd.systemd.unit=storage-target-mode.target' \
894 --output=profile1.efi
895 </programlisting>
896
897 <para>Add a third profile (@2):</para>
898
899 <programlisting>$ ukify build \
900 --profile='TITLE=Factory Reset
901 ID=factory-reset' \
902 --cmdline='quiet rw systemd.unit=factory-reset.target' \
903 --output=profile2.efi
904 </programlisting>
905
906 <para>Then, create a UKI and include all the generated profiles:</para>
907
908 <programlisting>$ ukify build \
909 --linux=/lib/modules/6.0.9-300.fc37.x86_64/vmlinuz \
910 --initrd=/some/path/initramfs-6.0.9-300.fc37.x86_64.img \
911 --cmdline='quiet rw' \
912 --join-profile=profile0.efi \
913 --join-profile=profile1.efi \
914 --join-profile=profile2.efi \
915 --output=base.efi
916 </programlisting>
917
918 <para>The resulting UKI <filename>base-with-profile-0-1-2.efi</filename> will now contain three profiles.</para>
919 </example>
920
921 <example>
922 <title>Offline signing of pcrsig section</title>
923
924 <para>First, create a UKI and save the PCR JSON blob:</para>
925
926 <programlisting>$ ukify build \
927 --linux=/lib/modules/6.0.9-300.fc37.x86_64/vmlinuz \
928 --initrd=/some/path/initramfs-6.0.9-300.fc37.x86_64.img \
929 --cmdline='quiet rw' \
930 --pcr-public-key=tpm2-pcr-initrd-public-key.pem \
931 --policy-digest \
932 --json=short \
933 --output=base.efi >base.pcrs
934 </programlisting>
935
936 <para>Then, sign the PCR digests offline and insert them in the JSON blob:</para>
937
938 <programlisting>#!/usr/bin/python3
939 import base64, json, subprocess
940
941 priv_key = '/home/zbyszek/src/systemd/tpm2-pcr-private.pem'
942 base_file = 'base.pcrs'
943
944 base = json.load(open(base_file))
945
946 for bank,policies in base.items():
947 for policy in policies:
948 pol = base64.b16decode(policy['pol'].upper())
949 call = subprocess.run(['openssl', 'dgst', f'-{bank}', '-sign', priv_key],
950 input=pol,
951 check=True,
952 capture_output=True)
953 sig = base64.b64encode(call.stdout).decode()
954 policy['sig'] = sig
955
956 print(json.dumps(base))
957 </programlisting>
958
959 <para>Finally, attach the updated JSON blob to the UKI:</para>
960
961 <programlisting>$ ukify build \
962 --join-pcrsig=base.efi \
963 [email protected] \
964 --json=short \
965 --output=base-signed.efi
966 </programlisting>
967
968 <para>The resulting UKI <filename>base-signed.efi</filename> will now contain the signed PCR digests.</para>
969 </example>
970
971 </refsect1>
972
973 <refsect1>
974 <title>See Also</title>
975 <para><simplelist type="inline">
976 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
977 <member><citerefentry><refentrytitle>systemd-stub</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
978 <member><citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>
979 <member><citerefentry><refentrytitle>systemd-measure</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
980 <member><citerefentry><refentrytitle>systemd-pcrphase.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
981 </simplelist></para>
982 </refsect1>
983
984 </refentry>