Skip to content
systemcoding.dev
Embedded Linux

Add Packages to a Yocto Image With IMAGE_INSTALL

Add packages to a Yocto 5.0 image with IMAGE_INSTALL:append in local.conf or a custom image recipe, and avoid the += ordering trap that silently drops them.

6 min read
Summarize in AI
Flat illustration of a single-board computer with its SoC, memory, header and ports, with the Linux, Raspberry Pi and Debian logos.

You built core-image-minimal, booted it, and found there is no strace, no nano and no curl. The image contains exactly what the recipe asked for and nothing else, which is the point of Yocto, so adding a tool means telling the build system to put its package into the root filesystem. The variable that does that is IMAGE_INSTALL. It is also the variable people break most often, because one innocent-looking operator makes the line do nothing. This post shows the two places to set it on Yocto Project 5.0 (Scarthgap), how to confirm the result before you wait for a build, and why :append is the operator to use.

What IMAGE_INSTALL holds

An image recipe is a list of packages to install into a root filesystem. IMAGE_INSTALL is that list, as space-separated package names. The core-image class and each image recipe set a default, and the Yocto Reference Manual describes the variable as the one that image recipes use to specify packages to install, with a warning to use it with care to avoid ordering issues.

Two details trip up beginners straight away. First, the value is package names, not recipe names. A recipe usually produces several packages, such as openssh, openssh-sshd and openssh-scp, and a recipe called strace produces a package called strace. Second, the names follow OpenEmbedded notation, so you write glibc-dev, not the Debian name libc6-dev.

Add a package to every image from local.conf

The quickest route is conf/local.conf in your build directory. The manual's own example is one line:

conf/local.confbitbake
IMAGE_INSTALL:append = " strace nano curl"

The leading space inside the quotes is required. The :append operator joins the new text to the existing value with no separator of its own, so without the space you would get packagegroup-core-bootstrace and a build failure about a package that does not exist.

This line affects every image you build from this build directory, not just one. To limit it to a single image, add the image recipe name as an override:

conf/local.confbitbake
IMAGE_INSTALL:append:pn-core-image-minimal = " strace nano curl"

Now only core-image-minimal gets the three packages, and core-image-base stays as it was. For core-image-* images there is a second variable, CORE_IMAGE_EXTRA_INSTALL, that the manual describes as a similar approach, and it only touches images that inherit core-image.

Why not +=

Most people reach for += because it works in a shell script and in many other configuration languages. In local.conf it is the wrong choice. The manual says you must use :append instead of += to avoid ordering issues, because :append is applied unconditionally after all assignments, while += happens at parse time in file order.

Here is the failure in concrete terms. local.conf is parsed before any recipe. If you write IMAGE_INSTALL += "strace" there, the variable is still empty, so it becomes strace. When the image recipe is then parsed, one of two things happens. core-image-minimal assigns the variable with a plain =, which overwrites your line and drops strace. An image that sets a default with ?= sees that the variable already has a value, skips its default, and you end up with an image that contains strace and none of the base packages it needed to boot. Both outcomes are quiet. Neither raises an error at parse time, and you only learn about it from the finished image.

:append avoids this because the operation is recorded and executed last, after every recipe and class has finished its assignments.

Check the value before you build

You do not have to wait for a full image build to know whether your change landed. bitbake -e prints the final value of every variable for a target, and grep narrows it:

Shell
bitbake -e core-image-minimal | grep '^IMAGE_INSTALL='
Text
IMAGE_INSTALL="packagegroup-core-boot  strace nano curl"

The exact spacing and any extra package groups depend on your layers and distro, so your line may be longer. What matters is that your three names are at the end. If you had used += in local.conf, this is where you would see the list missing them.

Put the packages in a custom image recipe

local.conf is local to one build directory and is not under version control in most teams. For anything you want to keep, write an image recipe in your own layer. The manual's form uses inherit core-image and sets the list directly:

meta-mine/recipes-core/images/my-image.bbbitbake
SUMMARY = "Minimal image with a few debugging tools"
LICENSE = "MIT"

inherit core-image

IMAGE_INSTALL += "strace nano curl"

Inside an image recipe, after the inherit, += is fine, because you are adding to the value the class already built and the ordering is the one you wrote. Another style is to base your image on an existing one by pulling it in with require recipes-core/images/core-image-minimal.bb and then adding your line.

Build it the same way as any image:

Shell
bitbake my-image
Text
NOTE: Tasks Summary: Attempted 3842 tasks of which 3790 didn't need to be rerun and all succeeded.

The task counts differ on every machine and every state of the sstate cache, so treat the number as an example. The success line is what to look for.

Read the result from the manifest

After the build, the image's package manifest lists everything that went in. It sits next to the image files under tmp/deploy/images/<machine>/, in a file ending in .manifest:

Shell
grep -E '^(strace|nano|curl) ' tmp/deploy/images/qemux86-64/*.manifest
Text
curl core2-64 8.7.1-r0
nano core2-64 7.2-r0
strace core2-64 6.8-r0

Each line is the package name, its architecture and its version, so this also tells you the exact upstream version you shipped. The versions here are examples; yours follow the recipes in your checkout. If a package is missing from the manifest, the IMAGE_INSTALL value never contained it, and bitbake -e will show why.

Find the right package name

A recipe name and a package name are not always the same. When you know a file the package should ship, ask the package data:

Shell
oe-pkgdata-util find-path /usr/bin/strace
Text
strace: /usr/bin/strace

The part before the colon is the package name to put in IMAGE_INSTALL. The tool needs a build that has already produced package data, so run it after at least one successful image build in the same build directory. If it reports nothing, the file is not in any built package yet.

When IMAGE_INSTALL is not the right tool

A list of packages is the lowest-level way to shape an image, and it is not always the best one. For debug tools such as strace and gdb, the tools-debug image feature installs a curated set, and ssh-server-openssh brings in a full SSH server with its configuration. The next post in this cluster covers IMAGE_FEATURES, which map to groups of packages and to root filesystem settings such as read-only mode that no package name can express. If you add more than a handful of packages for one purpose, wrap them in a package group recipe so the intent has a name. And if you are working with an initramfs image, the manual says to use PACKAGE_INSTALL, not IMAGE_INSTALL, because the initramfs recipe uses a fixed package set.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.
Kernels

Write a Pin Controller Driver With pinctrl

Write a Linux 6.12 pin controller driver: pinctrl_desc, pins, groups and functions, the set_mux callback, and the device tree states that consumers select.

8 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.