Updated Mender identity and inventory with Yocto

Introduction

This tutorial will guide you through creating custom recipes for Yocto builds to modify the predefined Mender inventory and identity scripts.

Prerequisites

Additionally, this tutorial uses some of the configurations discussed here but is not directly related to that tutorial.

Step 1 - Create a custom layer

To be able to proceed with this tutorial we first must create a custom layer that will contain our custom modifications or additions. Please note that the tutorials on this site will re-use this layer and if you have already created this structure by following another tutorial you can skip this step.

Create a new layer called meta-stargazer using the bitbake-layers helper application:

bitbake-layers create-layer ../sources/meta-stargazer

This will create a basic structure in meta-stargazer directory:

../sources/meta-stargazer/
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    └── example
        └── example_0.1.bb

3 directories, 4 files

Include the layer in our Yocto Project environment:

bitbake-layers add-layer ../sources/meta-stargazer

Step 2 - Create custom scripts for identity and inventory

Here we are creating the custom scripts that will be used. In the case of mender-device-identity, it is a single script so we will be replacing it. In the case of inventory, there can be multiple scripts provided values so we will be supplementing those provided by default.

mkdir -p ../sources/meta-stargazer/recipes-mender/mender/files
cat > ../sources/meta-stargazer/recipes-mender/mender/files/mender-custom-identity <<"EOF"
echo machine_id=$(cat /etc/machine-id)
EOF

cat > ../sources/meta-stargazer/recipes-mender/mender/files/mender-custom-inventory <<"EOF"
echo hostname=$(hostname)
echo date=$(date)
EOF

Step 3 - Create a mender bbappend file.

Using bbappend files is the Yocto approach to modify recipes that are provided by other layers. These files are processed in an order defined by the Yocto Layer priorities. For this particular change, we will use a wildcard bbappend file, named mender_%.bbappend. which will apply to any version of the mender.bb recipe. If you wish to make changes to a particular version of a package, then you will need to include the version name in place of the wildcard, such as mender_2.1.3.bbappend.

mkdir -p ../sources/meta-stargazer/recipes-mender/mender
cat > ../sources/meta-stargazer/recipes-mender/mender/mender_%.bbappend <<"EOF"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI_append = " \
     file://mender-custom-inventory \
     file://mender-custom-identity \
"

do_install_append () {
    install -d ${D}/${datadir}/mender/inventory
    install -m 0755 ${WORKDIR}/mender-custom-inventory ${D}/${datadir}/mender/inventory/

    install -d ${D}/${datadir}/mender/identity
    install -m 0755 ${WORKDIR}/mender-custom-identity ${D}/${datadir}/mender/identity/mender-device-identity
}
EOF

Step 4 - Rebuild your image

Use the bitbake tool to rebuild whatever image you are using.

bitbake core-image-base

Conclusion

In this tutorial we covered creating a Mender recipe bbappend file to modify the default device identity and device inventory fields.

For further reading please visit

If this tutorial was useful to you, please press like, or leave a thank you note to the contributor who put valuable time into this and made it available to you. It will be much appreciated!

5 Likes

A post was split to a new topic: Device identity change after reflash