Build your own Linux Distribution

In the previous posts we talked about how to setup and use the Yocto framework for doing custom embedded Linux builds.

Now that the toes have been put into the water, let’s start to take deeper dives in the pool. Let’s start with the idea of building your own version of Linux. For example.g. I am interested in a bearcreektech linux that I would like to use to create my own apps and deployments. So instead of using ubuntu as the base to build on, I might want o start with my own.

An image of a CD on a bed of roses. DVD is labelled MY Linux

Why would I want to create my own linux:

  1. Decide which version of the kernel I want to use.

  2. It helps me control how many kernel packages I install e.g. ssh, virtualization etc.

  3. I can decide the applications that should be on the system by default

  4. Define the security profiles defined by default. E.g. Firewalls, SELinux etc.

How can this be done in Yocto framework?

Yocto has a great concept of creating a distro to make this magic happen.

Here are some links to learn what yocto provides:

https://docs.yoctoproject.org/scarthgap/overview-manual/concepts.html#distro-layer

https://docs.yoctoproject.org/scarthgap/dev-manual/custom-distribution.html

Show me how to add a new distro

Just like the other blogs, I created a new demo to help you get started.

I am building the example linux distribution to be meant for a ARM based device deployment. I used the bearcreektech/yocto-scartgap docker with tag 1.1 that can be found here: https://hub.docker.com/repository/docker/bearcreektech/yocto-scarthgap/general

Steps that differ from the generic Yocto bitable build

Create your own meta layer

The first step is to create your own meta layer that you can put specific information in there.

mkdir /workdir/poky/meta-bearcreektech

mkdir /workdir/poky/meta-bearcreektech/conf

Add this meta layer to the bblayer

bitbake-layers add-layer /workdir/poky/meta-bearcreektech

In the new layer, there are two directories:

  • conf : this is where layer.conf files go. The layer.conf file defines the path to the meta layer, the directories to look for recipes, which version of Yocto this layer is compatible with.

  • recipes-example : Sample recipe directory created by default

My sample layer.conf is as follows:

BBPATH .= ":${LAYERDIR}"

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \

${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-bearcreektech"

BBFILE_PATTERN_meta-bearcreektech = "^${LAYERDIR}/"

BBFILE_PRIORITY_meta-bearcreektech = "6"

LAYERDEPENDS_meta-bearcreektech = "core"

LAYERSERIES_COMPAT_meta-bearcreektech = "scarthgap"

Next step create the distro.conf file

This file is created in the poky/build/conf/distro directory. My sample is a file called bearcreeklinux.conf. Here is what is looks like:

DISTRO = "bearcreeklinux"

DISTRO_VERSION = "0.0.1"

PACKAGE_CLASSES = "package_ipk"

MACHINE = "qemuarm64"

DISTRO_FEATURES = "ssh-server"

IMAGE_INSTALL = "wget curl"

IMAGE_FSTYPES ?= "ext4 tar.bz2"

PREFFERED_PROVIDER_virtual/kernel = "linux-yocto"

Do the build:

Make sure that the poky/build/conf/bblayers.conf has the required bitbake layers.

Update poky/build/conf/local.conf file for the required updates for ARM build. Define the specific DISTRO in there with the one:

DISTRO = "bearcreeklinux"

To run the build the command we use will be 

bitbake core-image-minimal

See the code on GitHub

Want to see the steps and the configuration files for your use?

https://github.com/anilve/YoctoResearch/tree/main/Scarthgap/BuildYourOwnLinuxDistro

Yocto Article Series

Older articles links:

  1. https://www.bearcreektech.com/blog/tailoring-custom-linux-with-yocto-scarthgap-introduction‍ ‍

  2. https://www.bearcreektech.com/blog/bake-your-own-custom-linux-w-bitbake

  3. https://www.bearcreektech.com/blog/part-3-using-poky-to-build-linux-images

  4. https://www.bearcreektech.com/blog/setting-up-the-foundation-for-yocto-builds

  5. https://www.bearcreektech.com/blog/building-x86-linux-on-mac

  6. https://www.bearcreektech.com/blog/building-arm-linux-on-mac‍ ‍

  7. https://www.bearcreektech.com/blog/build-your-own-yocto-docker-image

Next
Next

Build your own Docker for Yocto Builds