Debian Codegraph @

doc/source/concept_and_workflow/customize_the_boot_process.rst

raw
1 .. _working-with-kiwi-customizing-the-boot-process:
2
3 Customizing the Boot Process
4 ----------------------------
5
6 Most Linux systems use a special boot image to control the system boot process
7 after BIOS or UEFI hands over control of the hardware to the operating system.
8 This boot image is a compressed cpio initial RAM disk, and it's called the
9 :file:`initrd`. The Linux kernel loads the :file:`initrd` into the RAM and
10 executes :command:`init` or, if present, :command:`linuxrc`.
11
12 Depending on the image type, {kiwi} creates the boot image automatically during
13 the `create` step. To create the :file:`initrd`, {kiwi} uses a tool called
14 `dracut`. dracut-generated initrd archives can be extended with custom modules to
15 add functionality that is not natively provided by dracut itself. In the scope
16 of {kiwi}, the following dracut modules are used:
17
18 ``kiwi-dump``
19 Serves as an image installer. It provides the required implementation to
20 install a {kiwi} image on a selectable target. This module is required if one
21 of the attributes in the image type definition, `installiso`, `installstick`, or
22 `installpxe`, is set to `true`. Shipped in the `dracut-kiwi-oem-dump`
23 package.
24
25 ``kiwi-dump-reboot``
26 Serves to boot the system into the installed image after installation is
27 completed. Also shipped in the `dracut-kiwi-oem-dump` package, together
28 with `kiwi-dump`.
29
30 ``kiwi-live``
31 Boots up a {kiwi} live image. This module is required
32 if the `iso` image type is selected. Shipped in the `dracut-kiwi-live`
33 package.
34
35 ``kiwi-verity``
36 Sets up dm-verity for images built with the `verity_blocks` or
37 `embed_verity_metadata` type attributes, verifying the integrity of the
38 root device at boot time. Shipped in the `dracut-kiwi-verity` package.
39
40 ``kiwi-overlay``
41 Allows you to boot disk images with the attribute `overlayroot` set to `true`. A
42 disk like that has its root partition compressed and read-only. The disk boots up
43 using overlayfs for the root filesystem with a separate partition on the same
44 disk for persistent data. Shipped in the `dracut-kiwi-overlay` package.
45
46 ``kiwi-repart``
47 Resizes an OEM disk image after installation on
48 the target disk to meet the size limits configured in the `oemconfig`
49 section of the image description. The module takes over the tasks of
50 repartitioning the disk, resizing RAID, LVM, LUKS, and other layers, as well as
51 resizing the system filesystems. Shipped in the `dracut-kiwi-oem-repart`
52 package.
53
54 ``kiwi-lib``
55 Provides common functions used by dracut modules. Shipped in the
56 `dracut-kiwi-lib` package, which the other modules depend on.
57
58 .. note:: Using Custom Boot Image Support
59
60 In addition to the standard dracut-based creation of the boot image, {kiwi}
61 supports the use of custom boot images for the image types `oem`
62 and `pxe`. The use of a custom boot image is enabled by setting the
63 following attribute in the image description:
64
65 .. code:: none
66
67 <type ... initrd_system="kiwi"/>
68
69 Along with this setting, you must provide a reference to
70 a boot image description in the `boot` attribute as follows:
71
72 .. code:: none
73
74 <type ... boot="{exc_netboot}"/>
75
76 While {kiwi} supports this approach, it is recommended to use dracut instead.
77 Keep also in mind that although {kiwi} supports the creation of custom boot
78 images, {kiwi} does not include any official boot image descriptions. You
79 can find an OEM boot description example at
80 https://build.opensuse.org/package/show/Virtualization:Appliances:Images:Testing_x86:tumbleweed/custom-oem-boot-description
81 and a PXE boot description example at
82 https://build.opensuse.org/package/show/Virtualization:Appliances:Images:Testing_x86:tumbleweed/custom-pxe-boot-description.
83
84 The custom boot image descriptions make it possible to completely customize
85 the behavior of the initrd. This concept is mostly used in PXE environments
86 that are usually heavily customized and require a specific boot and
87 deployment workflow.
88
89
90 Boot Image Hook-Scripts
91 .......................
92
93 The dracut initrd system uses `systemd` to implement a predefined workflow
94 of services documented in the bootup man page:
95
96 http://man7.org/linux/man-pages/man7/dracut.bootup.7.html
97
98 To hook in a custom boot script to this workflow, it is necessary to provide
99 a dracut module that dracut picks when {kiwi} calls it.
100 The module files can be provided either as a package or as part of the
101 overlay directory in the image description.
102
103 The following example shows how to include a custom hook script
104 before the system rootfs is mounted.
105
106 1. Create a subdirectory for the dracut module:
107
108 .. code:: bash
109
110 $ mkdir -p root/usr/lib/dracut/modules.d/90my-module
111
112 2. Register the dracut module in the configuration file:
113
114 .. code:: bash
115
116 $ vi root/etc/dracut.conf.d/90-my-module.conf
117
118 add_dracutmodules+=" my-module "
119
120 3. Create the hook script:
121
122 .. code:: bash
123
124 $ touch root/usr/lib/dracut/modules.d/90my-module/my-script.sh
125
126 4. Create a module setup file in
127 :file:`root/usr/lib/dracut/modules.d/90my-module/module-setup.sh` containing the following:
128
129 .. code:: bash
130
131
132 #!/bin/bash
133
134 # called by dracut
135 check() {
136 # check module integrity
137 }
138
139 # called by dracut
140 depends() {
141 # return list of modules depending on this one
142 }
143
144 # called by dracut
145 installkernel() {
146 # load required kernel modules when needed
147 instmods _kernel_module_list_
148 }
149
150 # called by dracut
151 install() {
152 declare moddir=${moddir}
153 inst_multiple _tools_my_module_script_needs_
154
155 inst_hook pre-mount 30 "${moddir}/my-script.sh"
156 }
157
158 .. note:: Declaring Extra Tools for Hook Scripts
159
160 The `install()` function called by dracut can define extra tools required by
161 the specified hook script. The `inst_multiple` command and its parameters
162 instruct dracut to include these extra tools and items into the initrd.
163
164 The specified tools and items can be files. Normally, they are executables
165 and libraries required by the hook script.
166
167 * Each file must be included in the {kiwi} description either in a
168 package, an archive, or in the root tree of the image description
169 directory.
170
171 * The parameters of the `inst_multiple` command are space-separated.
172
173 * Each parameter can be a single executable name if it exists in the `/bin`,
174 `/sbin`, `/usr/bin`, or `/usr/sbin` directories.
175
176 * Otherwise, a full path to the file is required. This normally applies for
177 libraries and other special files.
178
179 When {kiwi} calls dracut, the :file:`90my-module` is installed into the
180 generated initrd. At boot time, systemd calls the scripts as part of the
181 :file:`dracut-pre-mount.service`.
182
183 The dracut system offers many other possibilities to customize the
184 initrd than shown in the example above. For more information, visit
185 the `dracut project page <https://dracut.wiki.kernel.org/index.php/Main_Page>`_.
186
187
188 Boot Image Parameters
189 .....................
190
191 A dracut-generated initrd in a {kiwi} image build process includes one or more
192 of the {kiwi}-provided dracut modules. The following non-exhaustive list
193 documents the most commonly used kernel boot parameters for these modules:
194
195 ``rd.kiwi.term``
196 Exports the `TERM` variable into the initrd environment. If
197 the default value for the terminal emulation is not correct,
198 `rd.kiwi.term` can be used to overwrite the default. The
199 environment is also passed to the systemd unit that calls
200 dialog-based programs in {kiwi} dracut code, which means that the
201 `TERM` setting applies there too.
202
203 ``rd.kiwi.debug``
204 Activates the debug log file for the {kiwi} part of
205 the boot process in :file:`/run/initramfs/log/boot.kiwi`.
206
207 ``rd.kiwi.dialog.timeout=seconds|off``
208 Sets a timeout value for dialogs invoked by kiwi dracut
209 modules. By default, the timeout is set to 60 seconds.
210 If set to the special value `off`, the dialog will never
211 time out.
212
213 ``rd.kiwi.install.devicepersistency=by-*``
214 Instructs an OEM installation image to present the list of
215 available disk devices using the device names as provided
216 by the specified `by-*` representation. For example,
217 `rd.kiwi.install.devicepersistency=by-path` would show the
218 by-path device names in the list of available disks.
219
220 ``rd.kiwi.install.pxe``
221 Instructs an OEM installation image to look up the system
222 image on a remote location specified in `rd.kiwi.install.image`.
223
224 ``rd.kiwi.install.image=URI``
225 Specifies the remote location of the system image in
226 a PXE-based OEM installation.
227
228 ``rd.kiwi.install.pass.bootparam``
229 Instructs an OEM installation image to pass additional
230 boot parameters to the kernel used to boot the installed image. This
231 can be used, for example, to pass on first-boot configuration for a PXE image.
232 Note that options starting with `rd.kiwi` are not passed to avoid
233 side effects.
234
235 ``rd.kiwi.install.retain_last``
236 Instructs an OEM installation to retain the contents of the
237 last partition on the target disk. This setting is only useful
238 if the last partition does not belong to the main OS, e.g., an
239 extra data partition added via the `spare_part` attribute in
240 the type setup of the image description. The implementation
241 also checks if the start address of the last partition on the
242 target disk matches the start address of the image to be
243 deployed. Only if they match can the data on the last partition
244 be retained.
245
246 ``rd.kiwi.oem.luks.reencrypt``
247 For OEM LUKS2-encrypted disk images. If set, it re-encrypts the disk
248 prior to an eventual resize and therefore creates a new key pool and
249 master key. The re-encryption is advisable if the image binary is
250 not protected. With access to the image binary, it's possible to
251 extract the LUKS header, which then allows you to decrypt the data
252 unless it was re-encrypted. The re-encryption process only runs if
253 the checksum of the LUKS header still matches the one from the
254 original disk image. Be aware that the re-encryption will ask
255 for the passphrase if the image has been built with an initial
256 LUKS passphrase.
257
258 ``rd.kiwi.oem.luks.reencrypt_randompass``
259 For OEM LUKS2-encrypted disk images in combination
260 with `rd.kiwi.oem.luks.reencrypt`. Resets the insecure built-time
261 passphrase, set via the `luks=` attribute, with a random
262 one-time passphrase that will be stored in memory at
263 `/run/.kiwi_reencrypt.keyfile`.
264
265 .. warning::
266
267 The passphrase will only persist as long as the system
268 does not reboot. Using this option usually requires that
269 the boot process implements code to set retrievable keyfile
270 information for subsequent boot processes of this system, e.g.,
271 TPM setup or similar.
272
273 ``rd.kiwi.oem.disk.consistency``
274 For OEM disk images providing an installation image. If set,
275 the installation image will check against all disks that are
276 not the selected target disk to see if there is any disk in the system
277 that has the same PTUUID compared to the image that is about
278 to be installed. If such a disk is found, this indicates that
279 the same image was already installed to another storage disk
280 on the same system, which will cause device ID inconsistencies
281 for the entire system. In such a case, an error message is
282 displayed, providing information about the conflicting device,
283 and the installation will be canceled.
284
285 ``rd.kiwi.oem.maxdisk=size[KMGT]``
286 Specifies the maximum disk size an unattended OEM installation uses for image
287 deployment. Unattended OEM deployments default to deploying on `/dev/sda` (or
288 more precisely, the first device that is not filtered out by
289 `oem-device-filter`). With RAID controllers, you may have big JBOD disks along
290 with a 480G RAID1 configured for OS deployment. With
291 `rd.kiwi.oem.maxdisk=500G`, the deployment is performed on the RAID disk.
292
293 ``rd.kiwi.oem.force_resize``
294 Forces the disk resize process on an OEM disk image. If set, no sanity
295 check for unpartitioned/free space is performed, and also an eventually
296 configured `<oem-resize-once>` configuration from the image description
297 will not be taken into account. The disk resize will be started, which
298 includes re-partitioning as well as all steps to resize the block layers
299 up to the filesystem holding the data. As `rd.kiwi.oem.force_resize`
300 bypasses all sanity checks to detect if such a resize process is
301 needed or not, it can happen that all program calls of the resize
302 process end without any effect if the disk is already properly
303 resized. It's also important to understand that the partition UUIDs
304 will change on every resize, which might be an unwanted side effect
305 of a forced resize.
306
307 ``rd.kiwi.oem.installdevice``
308 Configures the disk device to use in an OEM installation. This overwrites or
309 resets any other OEM device-specific settings, such as `oem-device-filter`,
310 `oem-unattended-id`, or `rd.kiwi.oem.maxdisk`, and continues the
311 installation on the given device. The device must exist and must be a
312 block special.
313
314 .. note:: Non-interactive mode activated by rd.kiwi.oem.installdevice
315
316 When setting `rd.kiwi.oem.installdevice` explicitly through the
317 kernel command line, {kiwi} uses the device without prompting for
318 confirmation.
319
320 ``rd.kiwi.oem.sha512``
321 Expect sha512 checksums and use the respective `sha512sum` tool and
322 the `.sha512` extension for filename match and checksum calculation.
323 By default sha256 is used.
324
325 ``rd.kiwi.oem.smallest_disk``
326 Alters the logic that chooses the destination device during non-interactive
327 mode deployments. The device with the smallest capacity gets selected
328 instead of the drive with the alphabetical first device name. USB flash
329 drives are filtered out. For big JBOD setups this parameter is an
330 alternative to `rd.kiwi.oem.maxdisk`.
331
332 ``rd.live.overlay.size``
333 Specifies the size for the `tmpfs` filesystem of a live ISO image that is used
334 for the `overlayfs` mount process. If the write area of the overlayfs mount
335 uses this `tmpfs`, any new data written during the runtime of the system is
336 written in this space. The default value is `50%`, meaning half of the
337 available RAM space can be used for writing new data.
338
339 ``rd.live.overlay.persistent``
340 Instructs a live ISO image to prepare a persistent write partition.
341
342 ``rd.live.encrypt``
343 Instructs a live ISO image to encrypt the persistent write partition.
344 The boot process becomes interactive in this case, and the user has
345 to specify a passphrase at boot time.
346
347 ``rd.live.overlay.cowfs``
348 Specifies which filesystem of a live ISO image to use for storing data on the
349 persistent write partition.
350
351 ``rd.live.cowfile.mbsize``
352 Specifies the size of the COW file in MB. When using tools like
353 `live-grub-stick`, the live ISO image is copied as a file on the target device,
354 and a GRUB loopback setup is created there to boot the live system from the
355 file. In this case, the persistent write setup that normally creates an extra
356 write partition on the target will fail in most situations because the target
357 has no free and unpartitioned space available. To prevent this from happening,
358 a COW file (live_system.cow) of a partition is created alongside the live ISO
359 image file. The default size of the COW file is 500MB.
360
361 ``rd.live.cowfile.path``
362 Effectively used in isoscan loop-mounted live systems. For details on this
363 type of live system, refer to :ref:`iso_as_file_to_usb_stick`.
364 Specifies the path of the COW file below the `/run/initramfs/isoscan` loop
365 mount point. If not specified, the cowfile is placed at
366 `/run/initramfs/isoscan/live_system.cow`.
367
368 ``rd.live.dir``
369 Specifies a directory that contains the live OS root directory. The default is
370 `LiveOS`.
371
372 ``rd.live.squashimg``
373 Specifies the name of the squashfs image file that contains the OS root.
374 The default is `squashfs.img`.
375
376 ``rd.kiwi.allow_plymouth``
377 By default, kiwi stops plymouth if it is present and active in the
378 initrd. Setting `rd.kiwi.allow_plymouth` will keep plymouth
379 active in the initrd, including all effects that might have
380 on the available consoles.
381
382 Boot Debugging
383 ''''''''''''''
384
385 If the boot process encounters a fatal error, the default behavior is to
386 stop the boot process without any possibility to interact with the system.
387 To prevent this, activate dracut's built-in debug mode in combination
388 with the {kiwi} debug mode as follows:
389
390 .. code:: bash
391
392 rd.debug rd.kiwi.debug
393
394 This must be set at the kernel command line. With these parameters activated,
395 the system enters a limited shell environment when a fatal error occurs
396 during boot. The shell provides a basic set of tools, and it can be used for inspection using the following command:
397
398 .. code:: bash
399
400 less /run/initramfs/log/boot.kiwi