Create a custom Linux Distribution using Yocto

  • 0

Create a custom Linux Distribution using Yocto

Category : Yocto

The Yocto Project is an open source collaboration project that provides templates, tools and methods to help creating a custom Linux-based systems for embedded products regardless of the hardware architecture.

Yocto Project uses Poky as a reference distribution but it can also creates a custom one. The purpose of this article is to show how to create, configure and build an alternative Yocto based embedded Linux Distribution.

Our custom distribution example mydistro extends the basic settings of Poky and uses alternate distro features and configurations such as systemd as init system and ipk as package manager.

A good practice is to isolate the distro configuration into a separate layer meta-mydistro:

First step is to checkout a local copy of the poky project :

$ mkdir -p ~/Projects/mydistro-oe

$ git clone -b master git://git.yoctoproject.org/poky ~/Projects/mydistro-oe

$ cd ~/Projects/mydistro-oe

$ source oe-init-build-env

Let’s create the corresponding distro layer meta-mydistro using yocto-layer tool:

$ yocto-layer create meta-mydistro -o ~/Projects/-oe/meta-mydistro

Please enter the layer priority you'd like to use for the layer: [default: 6]
Would you like to have an example recipe created? (y/n) [default: n] n
Would you like to have an example bbappend file created? (y/n) [default: n] n

New layer created in ~/Projects/mydistro-oe/meta-mydistro

Now we can define our distro settings by creating a configuration file:

meta-mydistro/conf/distro/mydistro.conf

# Distro Layer configuration
# include and overwrite default poky distro
include conf/distro/poky.conf
DISTRO = "mydistro"
DISTRO_NAME = "MyDistro-Linux"
DISTRO_VERSION = "1.0"
DISTRO_CODENAME = "Guacamole"
SDK_VENDOR = "-mydistro-sdk"
SDK_VERSION="${DISTRO_VERSION}"
MAINTAINER = "info@mydistro.com"

TARGET_VENDOR = "-mydistro"

# Override these in poky based distros
MYDISTRO_DEFAULT_DISTRO_FEATURES = "bluetooth ext2 usbgadget usbhost wifi xattr nfs zeroconf 3g"
MYDISTRO_DEFAULT_EXTRA_RDEPENDS = "packagegroup-core-boot"
MYDISTRO_DEFAULT_EXTRA_RRECOMMENDS = "kernel-module-af-packet"

DISTRO_EXTRA_RDEPENDS += " ${MYDISTRO_DEFAULT_EXTRA_RDEPENDS}"
DISTRO_EXTRA_RRECOMMENDS += " ${MYDISTO_DEFAULT_EXTRA_RRECOMMENDS}"

DISTRO_FEATURES ?= "${MYDISTRO_DEFAULT_DISTRO_FEATURES} ${DISTRO_FEATURES_LIBC} "

PACKAGE_CLASSES = "package_ipk"

# Use systemd as init manager
DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"

Settings provided in meta-mydistro/conf/distro/mydistro.conf override similar settings that BitBake finds in the conf/local.conf file in the Build Directory.

To enable meta-mydistro layer we need to add it first to the bblayers.conf :

$ mkdir -p meta-mydistro/conf/samples
$ cp conf/bblayers.conf meta-mydistro/conf/samples/bblayers.conf.sample

and fill bblayers.conf.sample with the following:

BBLAYERS ?= " \
##OEROOT##/meta \
##OEROOT##/meta-yocto-bsp \
##OEROOT##/meta-poky \
##OEROOT##/meta-yocto-bsp \
##OEROOT##/meta-mydistro\
"

Then select mydistro as DISTRO either from bitbake or in local.conf :

$ cp conf/local.conf meta-mydistro/conf/samples/local.conf.sample

Point DISTRO variable in local.conf or local.conf.sample to use mydistro :

DISTRO ?= "mydistro"

Finally we are able to build an image using mydistro as distribution:

$ cd ~/Projects/mydistro-oe
$ TEMPLATECONF=meta-mydistro/conf/samples/ source oe-init-build-env
$ MACHINE=beaglebone bitbake core-image-minimal

Leave a Reply