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