Debian Codegraph @

doc/source/concept_and_workflow.rst

raw
1 Concept and Workflow
2 ====================
3
4 .. note:: **Abstract**
5
6 The following sections describe the concept and general workflow
7 of building appliances with {kiwi} |version|.
8
9 .. toctree::
10 :maxdepth: 1
11
12 concept_and_workflow/systemdeps.rst
13 concept_and_workflow/repository_setup
14 concept_and_workflow/packages
15 concept_and_workflow/profiles
16 concept_and_workflow/users
17 concept_and_workflow/shell_scripts
18 concept_and_workflow/runtime_configuration
19 concept_and_workflow/customize_the_boot_process
20
21 {kiwi} builds so-called *system images* (a fully installed and optionally
22 configured system in a single file) of a Linux distribution in two steps (for
23 further details, see :ref:`working-with-kiwi-image-building-process`):
24
25 1. *Prepare operation*: generate an *unpacked image tree* of your
26 image. The unpacked tree is a directory containing the future filesystem
27 of your image, generated from your image description.
28
29 2. *Create operation*: the unpacked tree generated in step 1 is packaged
30 into the format required for the final usage (e.g., a `qcow2` disk
31 image to launch the image with QEMU).
32
33 {kiwi} executes these steps using the following components, which it expects
34 to find in the *description directory*:
35
36 :ref:`image-description`:
37 The :file:`config.xml` file contains the image description, which is a
38 collection of general settings of the final image, like the image layout,
39 installed packages, present users, etc.
40
41 .. note::
42
43 The filename :file:`config.xml` is not mandatory; the image description
44 file can also have an arbitrary name plus the :file:`*.kiwi` extension.
45 {kiwi} first looks for a :file:`config.xml` file. If it cannot be found,
46 it picks the first :file:`*.kiwi` file. When using a file with the
47 :file:`.kiwi` extension, multiple markup options are supported,
48 including `XML`, `YAML`, and `TOML`.
49
50 :ref:`working-with-kiwi-user-defined-scripts`:
51 If present, custom configuration shell scripts run at different
52 stages of the build process. They can be used to fine-tune
53 the image in ways that are not possible via the settings provided in
54 :file:`config.xml`.
55
56 Overlay tree directory:
57 The *overlay tree* is a folder (called :file:`root`) or a tarball
58 (called :file:`root.tar.gz`) that contains files and directories that
59 will be copied into the *unpacked image tree* during the *Prepare
60 operation*.
61 The copying is executed after all the packages included in
62 :file:`config.xml` have been installed. Any files that are already
63 present will be overwritten.
64
65 CD root user data:
66 For live ISO images and install ISO images, an optional archive
67 is supported. This is a tar archive matching the name
68 :file:`config-cdroot.tar[.compression_postfix]`.
69
70 If present, the archive will be unpacked as user data on the ISO
71 image. For example, this is used to add license files or user
72 documentation. The documentation can then be read directly from the
73 CD/DVD without booting from the media.
74
75 .. _working-with-kiwi-image-building-process:
76
77 Image Building Process
78 ~~~~~~~~~~~~~~~~~~~~~~
79
80 .. figure:: .images/flow-diagram.png
81 :align: center
82 :alt: {kiwi} Build Process Flow Diagram
83
84 {kiwi} Build Process Flow Diagram
85
86 {kiwi} creates images in a two-step process: The first step, the *prepare*
87 operation, generates a so-called *unpacked image tree* (directory) using
88 the information provided in the :file:`config.xml` configuration file
89 (see :ref:`image-description`).
90
91 The second step, the *create* operation, creates the *packed image* or
92 *image* in the specified format based on the unpacked image tree and the
93 information provided in the :file:`config.xml` configuration file.
94
95 .. _prepare-step:
96
97 The Prepare Step
98 ^^^^^^^^^^^^^^^^
99
100 As the first step, {kiwi} creates an *unpackaged image tree*, also called a "root tree". This
101 directory will be the installation target for software packages to be
102 installed during the image creation process.
103
104 For the package installation, {kiwi} relies on the package manager specified
105 in the `packagemanager` element in :file:`config.xml`. {kiwi} supports the
106 following package managers: `apk`, `apt`, `dnf4` (default), `dnf5`,
107 `microdnf`, `pacman`, and `zypper`.
108
109 The prepare step consists of the following substeps:
110
111 #. **Create Target Root Directory**
112
113 By default, {kiwi} aborts with an error if the target root tree
114 already exists to avoid accidental deletion of an existing
115 unpacked image. The option `--allow-existing-root` can be used
116 to work based on an existing root tree.
117
118 #. **Bootstrap Target Root Directory**
119
120 First, {kiwi} configures the package manager to use the repositories
121 specified in the configuration file, via the command line, or
122 both. After the repository setup, the packages specified in the
123 `bootstrap` section of the image description are installed into the
124 target root tree using the package manager of the build host (not
125 chrooted). This establishes
126 the initial environment to support the completion of the process in a
127 chroot setting. At the end of the `bootstrap` phase, the script
128 :file:`post_bootstrap.sh` is executed, if present.
129
130 .. note::
131
132 The essential bootstrap packages are usually `filesystem` and
133 `glibc-locale` to specify as part of the bootstrap. The dependency
134 chain of these two packages is usually sufficient to populate the
135 bootstrap environment with all required software to support the
136 installation of packages into the new root tree.
137
138 #. **Install Packages**
139
140 After the `bootstrap` phase, all other `<packages>` sections are
141 used to complete the installation as a chroot operation. {kiwi} uses
142 the package manager as installed in the `bootstrap` phase and
143 installs all other packages as configured.
144
145 .. note::
146
147 The installation of software packages through the selected package
148 manager may install unwanted packages. Removing these packages can be
149 accomplished by marking them for deletion in the image description; see
150 :ref:`uninstall-system-packages`.
151
152 #. **Apply Archives**
153
154 All archives specified in the `archive` element of the
155 :file:`config.xml` file are applied in the specified order (top to
156 bottom) after the package installation is complete (see
157 :ref:`archive-element`). Files and directories are
158 extracted relative to the top level of the new root tree. It is
159 possible to overwrite files already existing in the target root tree.
160
161 #. **Apply the Overlay Tree**
162
163 Next, {kiwi} applies all files and directories present in the overlay
164 directory named :file:`root` or in the compressed overlay,
165 :file:`root.tar.gz`, to the target root tree. Files already present in
166 the target root directory are overwritten. This allows you to
167 overwrite any file that was installed by one of the packages or
168 archives during the installation phase.
169
170 #. **Execute the user-defined script** :file:`config.sh`.
171
172 At the end of the preparation stage, the script :file:`config.sh` is
173 executed (if present). It is run in the top-level directory of the
174 target root tree. The script's primary function is to complete the
175 system configuration. For more details about custom scripts,
176 see :ref:`working-with-kiwi-user-defined-scripts`.
177
178 #. **Modify the Root Tree**
179
180 The unpacked image tree is now finished and can be converted into the final
181 image in the *create step*. It is possible to make manual modifications
182 to the unpacked tree before it is converted into the final image.
183
184 Since the unpacked image tree is just a directory, it can be modified
185 using the standard tools. Optionally, it is also possible to 'change
186 root (`chroot`)' into it, for instance, to invoke the package
187 manager. Besides the standard filesystem layout, the unpacked image tree
188 contains an additional directory named :file:`/image` that is not
189 present in a regular system. It contains information {kiwi} requires
190 during the create step, including a copy of the :file:`config.xml` file.
191
192 By default, {kiwi} will not stop after the *prepare step* and will
193 proceed directly with the *create step*. Therefore, to perform manual
194 modifications, proceed as follows:
195
196 .. code:: shell-session
197
198 $ kiwi-ng system prepare $ARGS
199 $ # make your changes
200 $ kiwi-ng system create $ARGS
201
202 .. warning:: Modifications of the unpacked root tree
203
204 When performing manual modifications of the unpacked image tree,
205 be aware that these changes might be lost when calling the prepare
206 step again. Therefore, avoid making changes that should be
207 persistent across multiple runs of the `prepare` step. The recommended
208 way to apply persistent changes to the unpacked image directory
209 is to change the original image description and re-run the `prepare`
210 step.
211
212 .. _create-step:
213
214 The Create Step
215 ^^^^^^^^^^^^^^^
216
217 {kiwi} creates the final image during the *create step*: it converts the
218 unpacked root tree into one or multiple output files appropriate for the
219 respective build type.
220
221 It is possible to create multiple images from the same unpacked
222 root tree, for example, a self-installing OEM
223 image and a virtual machine image from the same image description. The only
224 prerequisite is that both image types are specified in :file:`config.xml`.
225
226 During the *create step*, the following operations are performed by {kiwi}:
227
228 #. **Execute the User-defined Script** :file:`images.sh`.
229
230 At the beginning of the image creation process, the script named
231 :file:`images.sh` is executed (if present). For more details about
232 custom scripts, see :ref:`working-with-kiwi-user-defined-scripts`.
233
234 #. **Create the Requested Image Type**
235
236 {kiwi} converts the unpacked root into an output format appropriate for
237 the requested build type. During this process further image type
238 specific user defined scripts may be executed
239 (see :ref:`working-with-kiwi-user-defined-scripts`).