| 1 |
.. _packages: |
| 2 |
|
| 3 |
Adding and Removing Packages |
| 4 |
============================ |
| 5 |
|
| 6 |
In addition to the :ref:`repositories` setup, the package setup is |
| 7 |
required. {kiwi} allows the end user to completely customize the selection |
| 8 |
of packages via the `packages` element. |
| 9 |
|
| 10 |
.. code:: xml |
| 11 |
|
| 12 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 13 |
<packages type="bootstrap"> |
| 14 |
<package name="udev"/> |
| 15 |
<package name="filesystem"/> |
| 16 |
<package name="openSUSE-release"/> |
| 17 |
<!-- additional packages installed before the chroot is created --> |
| 18 |
</packages> |
| 19 |
<packages type="image"> |
| 20 |
<package name="patterns-openSUSE-base"/> |
| 21 |
<!-- additional packages to be installed into the chroot --> |
| 22 |
</packages> |
| 23 |
</image> |
| 24 |
|
| 25 |
The `packages` element provides a collection of different child elements |
| 26 |
that instruct {kiwi} when and how to perform package installation or |
| 27 |
removal. Each `packages` element acts as a group whose behavior can be |
| 28 |
configured via the following attributes: |
| 29 |
|
| 30 |
- `type`: either `bootstrap`, `image`, `delete`, `uninstall`, `systemfiles` |
| 31 |
or one of the following build types: `docker`, `iso`, `oem`, `pxe`, `kis`, |
| 32 |
`oci`. |
| 33 |
|
| 34 |
Packages for `type="bootstrap"` are pre-installed to populate the image's |
| 35 |
root filesystem before chrooting into it. |
| 36 |
|
| 37 |
Packages in `type="image"` are installed immediately after the initial |
| 38 |
chroot into the new root filesystem. |
| 39 |
|
| 40 |
Packages in `type="delete"` and `type="uninstall"` are removed from the |
| 41 |
image. For details, see :ref:`uninstall-system-packages`. |
| 42 |
|
| 43 |
And packages that belong to a build type are only installed when that |
| 44 |
specific build type is currently processed by {kiwi}. |
| 45 |
|
| 46 |
- `profiles`: a list of profiles to which this package selection applies |
| 47 |
(see :ref:`image-profiles`). |
| 48 |
|
| 49 |
- `patternType`: selection type for patterns; supported values are: |
| 50 |
`onlyRequired`, `plusRecommended`; see: |
| 51 |
:ref:`product-and-namedCollection-element`. |
| 52 |
|
| 53 |
The following sections describe the different child elements of |
| 54 |
a `packages` group. |
| 55 |
|
| 56 |
.. _package-element: |
| 57 |
|
| 58 |
The `package` element |
| 59 |
^^^^^^^^^^^^^^^^^^^^^ |
| 60 |
|
| 61 |
The `package` element represents a single package to be installed (or |
| 62 |
removed), whose name is specified via the mandatory `name` attribute: |
| 63 |
|
| 64 |
.. code:: xml |
| 65 |
|
| 66 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 67 |
<!-- snip --> |
| 68 |
<packages type="bootstrap"> |
| 69 |
<package name="udev"/> |
| 70 |
</packages> |
| 71 |
</image> |
| 72 |
|
| 73 |
This adds the package `udev` to the list of packages to be added to the |
| 74 |
initial filesystem. Note that the value that you pass via the `name` |
| 75 |
attribute is passed directly to the used package manager. Thus, if the |
| 76 |
package manager supports other means of how packages can be specified, you may |
| 77 |
pass them in this context too. For example, RPM-based package managers |
| 78 |
(like :command:`dnf` or :command:`zypper`) can install packages via their |
| 79 |
`Provides:`. This can be used to add a package that provides a certain |
| 80 |
capability (for example, `Provides: /usr/bin/my-binary`) via: |
| 81 |
|
| 82 |
.. code:: xml |
| 83 |
|
| 84 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 85 |
<!-- snip --> |
| 86 |
<packages type="bootstrap"> |
| 87 |
<package name="/usr/bin/my-binary"/> |
| 88 |
</packages> |
| 89 |
</image> |
| 90 |
|
| 91 |
Whether this works depends on the package manager and on the environment |
| 92 |
that is being used. In the Open Build Service, certain `Provides` are either |
| 93 |
not visible or cannot be properly extracted from the {kiwi} |
| 94 |
description. Therefore, relying on `Provides` is not recommended. |
| 95 |
|
| 96 |
Packages can also be included only on specific host architectures via the |
| 97 |
`arch` attribute. {kiwi} compares the `arch` attribute's value with the host |
| 98 |
architecture that builds the image according to the output of `uname -m`. |
| 99 |
|
| 100 |
.. code:: xml |
| 101 |
|
| 102 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 103 |
<!-- snip --> |
| 104 |
<packages type="image"> |
| 105 |
<package name="grub2"/> |
| 106 |
<package name="grub2-x86_64-efi" arch="x86_64"/> |
| 107 |
<package name="shim" arch="x86_64"/> |
| 108 |
</packages> |
| 109 |
</image> |
| 110 |
|
| 111 |
This results in `grub2-x86_64-efi` and `shim` being only installed if the |
| 112 |
build host is a 64-bit x86 machine, but `grub2` will be installed independent |
| 113 |
of the architecture. |
| 114 |
|
| 115 |
|
| 116 |
.. _archive-element: |
| 117 |
|
| 118 |
The `archive` element |
| 119 |
^^^^^^^^^^^^^^^^^^^^^ |
| 120 |
|
| 121 |
In certain situations, it is necessary to include additional packages into the |
| 122 |
image that are not available in the package manager's native format. {kiwi} |
| 123 |
supports the inclusion of regular tar archives via the `archive` element, whose |
| 124 |
`name` attribute specifies the filename of the archive ({kiwi} looks for the |
| 125 |
archive in the image description folder). |
| 126 |
|
| 127 |
.. code:: xml |
| 128 |
|
| 129 |
<packages type="image"> |
| 130 |
<archive name="custom-program1.tgz"/> |
| 131 |
<archive name="custom-program2.tar"/> |
| 132 |
</packages> |
| 133 |
|
| 134 |
{kiwi} extracts the archive into the root directory of the image using |
| 135 |
`GNU tar <https://www.gnu.org/software/tar/>`_. This means that only archives |
| 136 |
supported by it can be included. When multiple `archive` elements are |
| 137 |
specified, then they are applied in a top-to-bottom order. If a file is |
| 138 |
already present in the image, then the file from the archive overwrites |
| 139 |
it (same as with the image overlay). |
| 140 |
|
| 141 |
.. _uninstall-system-packages: |
| 142 |
|
| 143 |
Uninstall System Packages |
| 144 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 145 |
|
| 146 |
{kiwi} supports two different methods for removing packages from the |
| 147 |
appliance: |
| 148 |
|
| 149 |
1. Packages present as a child element of `<packages type="uninstall">` |
| 150 |
are gracefully uninstalled by the package manager, together with |
| 151 |
dependent packages and orphaned dependencies. |
| 152 |
|
| 153 |
2. Packages present as a child element of `<packages type="delete">` are removed |
| 154 |
by RPM/DPKG without any dependency check, potentially breaking |
| 155 |
dependencies and compromising the underlying package database. |
| 156 |
|
| 157 |
Both types of removals take place after :file:`config.sh` is run in the |
| 158 |
:ref:`prepare step <prepare-step>` |
| 159 |
(see also :ref:`working-with-kiwi-user-defined-scripts`). |
| 160 |
|
| 161 |
.. warning:: |
| 162 |
|
| 163 |
An `uninstall` packages request deletes: |
| 164 |
|
| 165 |
* the listed packages |
| 166 |
* the packages dependent on the listed ones |
| 167 |
* any orphaned dependency of the listed packages |
| 168 |
|
| 169 |
Use this feature with caution, as it can cause the removal of |
| 170 |
required tools, leading to failures in later build stages. |
| 171 |
|
| 172 |
|
| 173 |
Removing packages via `type="uninstall"` can be used to completely remove a |
| 174 |
build-time tool (for example, a compiler) without having to specify all |
| 175 |
dependencies of that tool (as opposed to when using |
| 176 |
`type="delete"`). Consider the following example, where we want to compile a |
| 177 |
custom program in :file:`config.sh`. We ship its source code via an |
| 178 |
`archive` element and add the build tools (`ninja`, `meson`, and `clang`) to |
| 179 |
`<packages type="image">` and `<packages type="uninstall">`: |
| 180 |
|
| 181 |
.. code:: xml |
| 182 |
|
| 183 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 184 |
<!-- snip --> |
| 185 |
<packages type="image"> |
| 186 |
<package name="ca-certificates"/> |
| 187 |
<package name="coreutils"/> |
| 188 |
<package name="ninja"/> |
| 189 |
<package name="clang"/> |
| 190 |
<package name="meson"/> |
| 191 |
<archive name="foo_app_sources.tar.gz"/> |
| 192 |
</packages> |
| 193 |
<!-- These packages will be uninstalled after running config.sh --> |
| 194 |
<packages type="uninstall"> |
| 195 |
<package name="ninja"/> |
| 196 |
<package name="meson"/> |
| 197 |
<package name="clang"/> |
| 198 |
</packages> |
| 199 |
</image> |
| 200 |
|
| 201 |
The tools `meson`, `clang`, and `ninja` are then available during the |
| 202 |
:ref:`prepare step <prepare-step>`, and they can be used in |
| 203 |
:file:`config.sh` (for further details, see |
| 204 |
:ref:`working-with-kiwi-user-defined-scripts`), for example, to build |
| 205 |
`foo_app`: |
| 206 |
|
| 207 |
.. code:: bash |
| 208 |
|
| 209 |
pushd /opt/src/foo_app |
| 210 |
mkdir build |
| 211 |
export CC=clang |
| 212 |
meson build |
| 213 |
cd build && ninja && ninja install |
| 214 |
popd |
| 215 |
|
| 216 |
The `<packages type="uninstall">` element ensures that the final |
| 217 |
appliance no longer contains the tools required to build `foo_app`, |
| 218 |
thus making the image smaller. |
| 219 |
|
| 220 |
There are also other use cases for `type="uninstall"`, especially for |
| 221 |
specialized appliances. For containers, you can remove the package |
| 222 |
`shadow` (it is required to set up new user accounts) or any remaining |
| 223 |
partitioning tools (`parted` or `fdisk`). All networking tools can be |
| 224 |
safely uninstalled in images for embedded devices without a network |
| 225 |
connection. |
| 226 |
|
| 227 |
.. _product-and-namedCollection-element: |
| 228 |
|
| 229 |
The `product` and `namedCollection` element |
| 230 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 231 |
|
| 232 |
{kiwi} supports the inclusion of openSUSE products or of named collections |
| 233 |
(*patterns* in SUSE-based distributions or *groups* for RedHat-based |
| 234 |
distributions). These can be added via the `product` and `namedCollection` |
| 235 |
child elements, which both take the mandatory `name` attribute and the |
| 236 |
optional `arch` attribute. |
| 237 |
|
| 238 |
`product` and `namedCollection` can be used to shorten the list of |
| 239 |
packages that need to be added to the image description. A |
| 240 |
named pattern, specified with the `namedCollection` element, is a |
| 241 |
representation of a predefined list of packages. Specifying a pattern |
| 242 |
installs all packages listed in the named pattern. Support for patterns is |
| 243 |
distribution-specific and available in SLES, openSUSE, CentOS, RHEL, and |
| 244 |
Fedora. The optional `patternType` attribute on the packages element allows |
| 245 |
you to control the installation of dependent packages. You may assign one |
| 246 |
of the following values to the `patternType` attribute: |
| 247 |
|
| 248 |
- `onlyRequired`: Incorporates only patterns and packages that the |
| 249 |
specified patterns and packages require. This is a "hard dependency" only |
| 250 |
resolution. |
| 251 |
|
| 252 |
- `plusRecommended`: Incorporates patterns and packages that are required |
| 253 |
and recommended by the specified patterns and packages. |
| 254 |
|
| 255 |
|
| 256 |
The `ignore` element |
| 257 |
^^^^^^^^^^^^^^^^^^^^ |
| 258 |
|
| 259 |
Packages can be explicitly marked to be ignored for installation inside a |
| 260 |
`packages` collection. This can be used to exclude certain packages from being |
| 261 |
installed when using patterns with `patternType="plusRecommended"`, as shown |
| 262 |
in the following example: |
| 263 |
|
| 264 |
.. code:: xml |
| 265 |
|
| 266 |
<image schemaversion="{schema_version}" name="{exc_image_base_name}"> |
| 267 |
<packages type="image" patternType="plusRecommended"> |
| 268 |
<namedCollection name="network-server"/> |
| 269 |
<package name="grub2"/> |
| 270 |
<package name="kernel"/> |
| 271 |
<ignore name="ejabberd"/> |
| 272 |
<ignore name="puppet-server"/> |
| 273 |
</packages> |
| 274 |
</image> |
| 275 |
|
| 276 |
|
| 277 |
Packages can be marked as ignored during the installation by adding an |
| 278 |
`ignore` child element with the mandatory `name` attribute set to the |
| 279 |
name of the package. Optionally, you can specify the architecture via |
| 280 |
`arch`, similarly to :ref:`package-element`. |
| 281 |
|
| 282 |
.. warning:: |
| 283 |
|
| 284 |
Adding `ignore` elements as children of a `<packages type="delete">` or |
| 285 |
a `<packages type="uninstall">` element has no effect! The packages will |
| 286 |
still be deleted. |