| 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 the data on the last partition |
| 244 |
can be retained. |
| 245 |
|
| 246 |
``rd.kiwi.install.retain_past`` |
| 247 |
Instructs an OEM installation to retain the contents of the |
| 248 |
last partition on the target disk in a less strict mode than |
| 249 |
it is the case with `rd.kiwi.install.retain_last`. In the retain_past |
| 250 |
mode the partition to preserve must not be part of the initial image. |
| 251 |
It can retain the content of any last partition if its start address |
| 252 |
is past the OS image. |
| 253 |
|
| 254 |
.. note:: Retain Past Mode Limitations |
| 255 |
|
| 256 |
There are no sanity checks for the partition to retain in this mode. |
| 257 |
From an implementation perspective {kiwi-ng} simply takes the last |
| 258 |
partition prior dump as reported by sfdisk and rebuilds this partition |
| 259 |
after the OS image is deployed. This can lead to a gap in the partition |
| 260 |
table between the OS end and the start of the retained partition. There |
| 261 |
is also no sanity checking when there are multiple partitions after the |
| 262 |
OS image. In this case, the last partition is retained, and all other |
| 263 |
partitions are removed. In constrast to `rd.kiwi.install.retain_last`, |
| 264 |
there is no tight coupling to the OS image partition table layout and |
| 265 |
as such `rd.kiwi.install.retain_last` should be used with caution. |
| 266 |
|
| 267 |
``rd.kiwi.oem.luks.reencrypt`` |
| 268 |
For OEM LUKS2-encrypted disk images. If set, it re-encrypts the disk |
| 269 |
prior to an eventual resize and therefore creates a new key pool and |
| 270 |
master key. The re-encryption is advisable if the image binary is |
| 271 |
not protected. With access to the image binary, it's possible to |
| 272 |
extract the LUKS header, which then allows you to decrypt the data |
| 273 |
unless it was re-encrypted. The re-encryption process only runs if |
| 274 |
the checksum of the LUKS header still matches the one from the |
| 275 |
original disk image. Be aware that the re-encryption will ask |
| 276 |
for the passphrase if the image has been built with an initial |
| 277 |
LUKS passphrase. |
| 278 |
|
| 279 |
``rd.kiwi.oem.luks.reencrypt_randompass`` |
| 280 |
For OEM LUKS2-encrypted disk images in combination |
| 281 |
with `rd.kiwi.oem.luks.reencrypt`. Resets the insecure built-time |
| 282 |
passphrase, set via the `luks=` attribute, with a random |
| 283 |
one-time passphrase that will be stored in memory at |
| 284 |
`/run/.kiwi_reencrypt.keyfile`. |
| 285 |
|
| 286 |
.. warning:: |
| 287 |
|
| 288 |
The passphrase will only persist as long as the system |
| 289 |
does not reboot. Using this option usually requires that |
| 290 |
the boot process implements code to set retrievable keyfile |
| 291 |
information for subsequent boot processes of this system, e.g., |
| 292 |
TPM setup or similar. |
| 293 |
|
| 294 |
``rd.kiwi.oem.disk.consistency`` |
| 295 |
For OEM disk images providing an installation image. If set, |
| 296 |
the installation image will check against all disks that are |
| 297 |
not the selected target disk to see if there is any disk in the system |
| 298 |
that has the same PTUUID compared to the image that is about |
| 299 |
to be installed. If such a disk is found, this indicates that |
| 300 |
the same image was already installed to another storage disk |
| 301 |
on the same system, which will cause device ID inconsistencies |
| 302 |
for the entire system. In such a case, an error message is |
| 303 |
displayed, providing information about the conflicting device, |
| 304 |
and the installation will be canceled. |
| 305 |
|
| 306 |
``rd.kiwi.oem.maxdisk=size[KMGT]`` |
| 307 |
Specifies the maximum disk size an unattended OEM installation uses for image |
| 308 |
deployment. Unattended OEM deployments default to deploying on `/dev/sda` (or |
| 309 |
more precisely, the first device that is not filtered out by |
| 310 |
`oem-device-filter`). With RAID controllers, you may have big JBOD disks along |
| 311 |
with a 480G RAID1 configured for OS deployment. With |
| 312 |
`rd.kiwi.oem.maxdisk=500G`, the deployment is performed on the RAID disk. |
| 313 |
|
| 314 |
``rd.kiwi.oem.force_resize`` |
| 315 |
Forces the disk resize process on an OEM disk image. If set, no sanity |
| 316 |
check for unpartitioned/free space is performed, and also an eventually |
| 317 |
configured `<oem-resize-once>` configuration from the image description |
| 318 |
will not be taken into account. The disk resize will be started, which |
| 319 |
includes re-partitioning as well as all steps to resize the block layers |
| 320 |
up to the filesystem holding the data. As `rd.kiwi.oem.force_resize` |
| 321 |
bypasses all sanity checks to detect if such a resize process is |
| 322 |
needed or not, it can happen that all program calls of the resize |
| 323 |
process end without any effect if the disk is already properly |
| 324 |
resized. It's also important to understand that the partition UUIDs |
| 325 |
will change on every resize, which might be an unwanted side effect |
| 326 |
of a forced resize. |
| 327 |
|
| 328 |
``rd.kiwi.oem.installdevice`` |
| 329 |
Configures the disk device to use in an OEM installation. This overwrites or |
| 330 |
resets any other OEM device-specific settings, such as `oem-device-filter`, |
| 331 |
`oem-unattended-id`, or `rd.kiwi.oem.maxdisk`, and continues the |
| 332 |
installation on the given device. The device must exist and must be a |
| 333 |
block special. |
| 334 |
|
| 335 |
.. note:: Non-interactive mode activated by rd.kiwi.oem.installdevice |
| 336 |
|
| 337 |
When setting `rd.kiwi.oem.installdevice` explicitly through the |
| 338 |
kernel command line, {kiwi} uses the device without prompting for |
| 339 |
confirmation. |
| 340 |
|
| 341 |
``rd.kiwi.oem.sha512`` |
| 342 |
Expect sha512 checksums and use the respective `sha512sum` tool and |
| 343 |
the `.sha512` extension for filename match and checksum calculation. |
| 344 |
By default sha256 is used. |
| 345 |
|
| 346 |
``rd.kiwi.oem.smallest_disk`` |
| 347 |
Alters the logic that chooses the destination device during non-interactive |
| 348 |
mode deployments. The device with the smallest capacity gets selected |
| 349 |
instead of the drive with the alphabetical first device name. USB flash |
| 350 |
drives are filtered out. For big JBOD setups this parameter is an |
| 351 |
alternative to `rd.kiwi.oem.maxdisk`. |
| 352 |
|
| 353 |
``rd.live.overlay.size`` |
| 354 |
Specifies the size for the `tmpfs` filesystem of a live ISO image that is used |
| 355 |
for the `overlayfs` mount process. If the write area of the overlayfs mount |
| 356 |
uses this `tmpfs`, any new data written during the runtime of the system is |
| 357 |
written in this space. The default value is `50%`, meaning half of the |
| 358 |
available RAM space can be used for writing new data. |
| 359 |
|
| 360 |
``rd.live.overlay.persistent`` |
| 361 |
Instructs a live ISO image to prepare a persistent write partition. |
| 362 |
|
| 363 |
``rd.live.encrypt`` |
| 364 |
Instructs a live ISO image to encrypt the persistent write partition. |
| 365 |
The boot process becomes interactive in this case, and the user has |
| 366 |
to specify a passphrase at boot time. |
| 367 |
|
| 368 |
``rd.live.overlay.cowfs`` |
| 369 |
Specifies which filesystem of a live ISO image to use for storing data on the |
| 370 |
persistent write partition. |
| 371 |
|
| 372 |
``rd.live.cowfile.mbsize`` |
| 373 |
Specifies the size of the COW file in MB. When using tools like |
| 374 |
`live-grub-stick`, the live ISO image is copied as a file on the target device, |
| 375 |
and a GRUB loopback setup is created there to boot the live system from the |
| 376 |
file. In this case, the persistent write setup that normally creates an extra |
| 377 |
write partition on the target will fail in most situations because the target |
| 378 |
has no free and unpartitioned space available. To prevent this from happening, |
| 379 |
a COW file (live_system.cow) of a partition is created alongside the live ISO |
| 380 |
image file. The default size of the COW file is 500MB. |
| 381 |
|
| 382 |
``rd.live.cowfile.path`` |
| 383 |
Effectively used in isoscan loop-mounted live systems. For details on this |
| 384 |
type of live system, refer to :ref:`iso_as_file_to_usb_stick`. |
| 385 |
Specifies the path of the COW file below the `/run/initramfs/isoscan` loop |
| 386 |
mount point. If not specified, the cowfile is placed at |
| 387 |
`/run/initramfs/isoscan/live_system.cow`. |
| 388 |
|
| 389 |
``rd.live.dir`` |
| 390 |
Specifies a directory that contains the live OS root directory. The default is |
| 391 |
`LiveOS`. |
| 392 |
|
| 393 |
``rd.live.squashimg`` |
| 394 |
Specifies the name of the squashfs image file that contains the OS root. |
| 395 |
The default is `squashfs.img`. |
| 396 |
|
| 397 |
``rd.kiwi.allow_plymouth`` |
| 398 |
By default, kiwi stops plymouth if it is present and active in the |
| 399 |
initrd. Setting `rd.kiwi.allow_plymouth` will keep plymouth |
| 400 |
active in the initrd, including all effects that might have |
| 401 |
on the available consoles. |
| 402 |
|
| 403 |
Boot Debugging |
| 404 |
'''''''''''''' |
| 405 |
|
| 406 |
If the boot process encounters a fatal error, the default behavior is to |
| 407 |
stop the boot process without any possibility to interact with the system. |
| 408 |
To prevent this, activate dracut's built-in debug mode in combination |
| 409 |
with the {kiwi} debug mode as follows: |
| 410 |
|
| 411 |
.. code:: bash |
| 412 |
|
| 413 |
rd.debug rd.kiwi.debug |
| 414 |
|
| 415 |
This must be set at the kernel command line. With these parameters activated, |
| 416 |
the system enters a limited shell environment when a fatal error occurs |
| 417 |
during boot. The shell provides a basic set of tools, and it can be used for inspection using the following command: |
| 418 |
|
| 419 |
.. code:: bash |
| 420 |
|
| 421 |
less /run/initramfs/log/boot.kiwi |