# Updated Mender identity and inventory with Yocto

**URL:** <https://hub.mender.io/t/updated-mender-identity-and-inventory-with-yocto/1836>\
**Category:** Tutorials\
**Tags:** yocto, mender\
**Created:** [April 23, 2020, 7:14pm UTC](https://hub.mender.io/t/updated-mender-identity-and-inventory-with-yocto/1836 "2020-04-23T19:14:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [April 23, 2020, 7:14pm UTC](https://hub.mender.io/t/updated-mender-identity-and-inventory-with-yocto/1836/1 "2020-04-23T19:14:12Z")

</div>

## Introduction

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

## Prerequisites

- **A configured Yocto environment**. Please take a look at one of the following if you do not have this prepared:
  - [Preparing the Yocto Project environment from scratch](https://hub.mender.io/t/preparing-the-yocto-project-environment-from-scratch/801)
  - [Preparing the Yocto Project environment based on Mender demo environment](https://hub.mender.io/t/preparing-the-yocto-project-environment-based-on-mender-demo-environment)

- **Enough Free Memory:** Your system should have at least 50 Gbytes of free disk space for building images.

Additionally, this tutorial uses some of the [configurations discussed here](https://hub.mender.io/t/how-to-create-custom-images-using-yocto-project/902) 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:

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

```

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

```auto
../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:

```auto
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.

```auto
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_.

```auto
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.

```auto
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

- [https://www.yoctoproject.org/docs/3.1/overview-manual/overview-manual.html#overview-components-recipes](https://www.yoctoproject.org/docs/3.1/overview-manual/overview-manual.html#overview-components-recipes)
- [https://www.yoctoproject.org/docs/3.1/dev-manual/dev-manual.html#using-bbappend-files](https://www.yoctoproject.org/docs/3.1/dev-manual/dev-manual.html#using-bbappend-files)

_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!_

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [November 2, 2023, 8:04am UTC](https://hub.mender.io/t/updated-mender-identity-and-inventory-with-yocto/1836/2 "2023-11-02T08:04:45Z")

</div>

A post was split to a new topic: [Device identity change after reflash](https://hub.mender.io/t/device-identity-change-after-reflash/6312)
