Yocto Project Basics: Layers, Recipes and core-image-minimal
Learn what Yocto layers and recipes are, how to set up the build environment, create a layer, and build core-image-minimal with BitBake.
Contents
The Yocto Project builds custom embedded Linux images from metadata: recipes that describe how to build each piece of software, grouped into layers. This article explains those two terms, shows how to prepare a build host and a build directory, and ends with the command that builds core-image-minimal. The steps follow the 6.1 “blacksail” documentation.
Layers and recipes
A recipe is a file with the .bb suffix that describes one piece of software: where to fetch the source, which patches to apply, how to configure and compile it, and how to package the result. The docs avoid calling recipes “packages” because a package is the output (.ipk, .deb or .rpm).
A layer is a repository of related metadata. Layers keep things separate, for example hardware-specific settings in one layer and shared software recipes in another. By convention a layer directory is named meta-<name>; the docs say this is not strictly required but advise keeping the prefix because tools may assume it.
BitBake is the task executor. It parses the metadata, generates a list of tasks, and runs them, including the tasks of dependencies. Poky is the reference distribution, and OpenEmbedded-Core combines BitBake with the configuration files and metadata that BitBake uses.
Two files in the build directory control a build: conf/bblayers.conf lists the layers BitBake considers, and conf/local.conf holds build settings.
Prepare the build host
The 6.1 docs list recent Ubuntu, Debian, Fedora, openSUSE and several RHEL-compatible releases as supported hosts. They state that building core-image-sato for qemux86-64 needs at least 140 GB of free disk and can be done with as little as 32 GB of RAM. The docs give no separate figure for core-image-minimal.
On Debian and Ubuntu, install the packages from the docs:
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential chrpath cpio debianutils diffstat file gawk gcc git iputils-ping libacl1 libcrypt-dev locales python3 python3-git python3-jinja2 python3-pexpect python3-pip python3-subunit socat texinfo unzip wget xz-utils zstdOn Fedora the docs give this list:
sudo dnf install bzip2 chrpath cpio cpp diffstat diffutils file findutils gawk gcc gcc-c++ git glibc-devel glibc-langpack-en gzip hostname libacl make patch perl perl-Data-Dumper perl-File-Compare perl-File-Copy perl-FindBin perl-Text-ParseWords perl-Thread-Queue perl-bignum perl-locale python python3 python3-GitPython python3-jinja2 python3-pexpect python3-pip python3-websockets rpcgen socat tar texinfo unzip wget which xz zstd util-linux-scriptThe build also needs the en_US.UTF-8 locale. Check it with locale --all-locales | grep en_US.utf8. The docs also note that on distributions other than Debian 11 and Ubuntu 22.04 you should install python3-websockets separately.
Clone the Yocto layers and initialize the environment
The manual setup clones three repositories into a layers/ directory, using the yocto-6.1 branch:
mkdir bitbake-builds
cd bitbake-builds
mkdir layers
git clone -b yocto-6.1 https://git.openembedded.org/bitbake ./layers/bitbake
git clone -b yocto-6.1 https://git.openembedded.org/openembedded-core ./layers/openembedded-core
git clone -b yocto-6.1 https://git.yoctoproject.org/meta-yocto ./layers/meta-yocto
source ./layers/openembedded-core/oe-init-build-envSourcing oe-init-build-env creates the build directory and changes your working directory to it. The Quick Build guide describes a newer alternative, the bitbake-setup tool, which picks a configuration such as poky-blacksail, a machine and a distro for you. Use whichever method your team standardizes on.
Create and add your own layer
With the environment sourced, bitbake-layers manages layers. This creates a layer next to the others and registers it in bblayers.conf:
bitbake-layers create-layer ../layers/meta-mylayer
bitbake-layers add-layer ../layers/meta-mylayer
bitbake-layers show-layerscreate-layer generates conf/layer.conf, an example recipe at recipes-example/example/example.bb, a COPYING.MIT license file and a README. In layer.conf, BBFILES tells BitBake where the recipes are, BBFILE_COLLECTIONS gives the layer its identifier, and BBFILE_PRIORITY decides which layer wins when two have a recipe of the same name (the default is 6). LAYERSERIES_COMPAT lists the compatible release names, such as blacksail.
Build core-image-minimal
The Images reference describes core-image-minimal as a small image that is just capable of letting a device boot. Build it with:
bitbake core-image-minimalThe Quick Build guide builds core-image-sato rather than core-image-minimal, uses qemux86-64 as its default machine, and starts the result with runqemu snapshot. I did not run the build myself.
The Quick Build guide also mentions an optional shared-state cache mirror, enabled with bitbake-config-build enable-fragment core/yocto/sstate-mirror-cdn, to speed up builds.
Where to go next
For another embedded build system, compare it with Buildroot, and see BusyBox for the kind of userland a minimal image carries. To see a root filesystem assembled by hand, read the initramfs guide. Later, a custom layer is the place for your own recipes and .bbappend files that modify recipes from other layers.
Sources
- Yocto Project documentation: Setting Up the Poky Reference Distro Manually
- Yocto Project Quick Build
- Yocto Project Overview and Concepts Manual
- Yocto Project Development Tasks Manual: Understanding and Creating Layers
- Yocto Project Reference Manual: System Requirements
- Yocto Project Reference Manual: Images
This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.