How to update .deb package with a Raspberry Pi 3

Introduction

For this tutorial, we quickly refresh some topics that you will need to have a grasp of such as Mender client, Mender Artifact and Update Modules in order to deploy an application-based update over-the-air (OTA). As part of the prerequisites for this tutorial, it is recommended that you have completed the Mender onboarding to get familiar with the Mender workflow.

Mender Client is a process that runs in user space on top of an embedded Linux operating system which talks to the Mender server and applies the update. The Mender client needs to be integrated with the device so it can install software updates to it. This integration also adds functionality to work with a Mender server such as provisioning, authentication, inventory monitoring and deployment reporting. When integrated, all images built for this device supports robust OTA updates. For a robust update process, Mender defines and uses a file format with .mender suffix, called Mender Artifact to handle additional metadata alongside the raw bits of the image file system namely, the Name of the software build, compatibility with device type, and checksum of the root file system for controllability during transit or storage.

Mender uses a framework called Update Modules to enable application-based or partial updates and comes with support for these types of updates out-of-the-box:

  • Packages (deb and rpm)
  • Containers (docker)
  • Files (directory copy/sync)

In Mender taxonomy, an Update Module is essentially a method for deploying over-the-air (OTA) software updates with the advantage of customizability and flexibility at its core. An Update Module is just a piece of user-written code that defines how the Mender client installs an update to a device. They are customizable and can be written in any programming language, so it can be tailored to meet the specific needs of a device or environment.

This tutorial will guide you through how to use Deb Update Module in Mender to update a Debian package using a Raspberry Pi 3.

Prerequisites

To follow this tutorial, you will need:

  • A Raspberry Pi 3 board running Raspbian with SSH enabled. You can use any of the methods suggested to install the OS image to your device.

  • A deployment environment using a desktop PC with Ubuntu 18.04 and Google Chrome as a web browser and at least 10 GB free disk space and 2 GB RAM available for Mender.

  • To complete Mender onboarding using the latest version of Mender documentation.

  • To have a .deb package ready or download one from Raspberry Pi archives.

Step 1 Install and Configure Mender Client Properly on Device

We assume that you have familiarized yourself with Mender by doing the latest Mender onboarding as stated in the prerequisites section of this tutorial. To make sure the experience is smoother we will revisit this step since we are doing a partial update and it is important to have installed and configured the Mender client properly in order to do this tutorial.

Installing this way does not offer a full Mender integration in your Raspberry Pi board and only enables Update Modules to do partial updates as intended for this tutorial, in this case a Docker container.

In order to make Mender easy to install and use with application-based updates, there is a Debian package for the Mender client! With its support for ARMv6 (and newer) and Debian family OSes, it will work on most development boards using Debian, Ubuntu and Raspbian.

Download a Debian package .deb to install on Debian, Ubuntu or Raspbian:

wget https://d1b0l86ne08fsf.cloudfront.net/2.1.0/dist-packages/debian/armhf/mender-client_2.1.0-1_armhf.deb

Install the package:

sudo dpkg -i mender-client_2.1.0-1_armhf.deb

After successfully installing the Mender client Debian package, some initial setup is required. First, we have to configure the Mender client for the demo setting using the configuration file at /etc/mender/mender.conf. The `.mender.conf’ file resides on the client side

Copy the demo configuration file:

sudo cp /etc/mender/mender.conf.demo /etc/mender/mender.conf

By viewing the content of the file you should see the following:

{
    "ServerCertificate": "/etc/mender/server.crt",
    "InventoryPollIntervalSeconds": 5,
    "RetryPollIntervalSeconds": 30,
    "ServerURL": "https://docker.mender.io/",
    "UpdatePollIntervalSeconds": 5
}

The demo server uses docker.mender.io and hosted server uses hosted.mender.io. In this tutorial, we are using the demo server so you need to make sure that ServerURL in the configuration file is set to https://docker.mender.io/. These URLs are not valid domain names and for it to be useful you will need an entry in “/etc/hosts” such as an IP address docker.mender.io s3.docker.mender.io, with the IP address being the IP of the PC or any environment that is running the demo server.

Next, you need to configure your device type.The device type is a string that defines your device and is used to ensure software compatibility by comparing the device type set in a Mender Artifact with the string on the device.

Create Mender client state directory:

sudo mkdir -p /var/lib/mender

Create the device type file:

echo "device_type=raspberrypi3" | sudo tee /var/lib/mender/device_type

Now you should have the Mender client installed and properly setup in your device.

Start the Mender client:

sudo systemctl enable mender && sudo systemctl restart mender

At this point you should have a login password and have also accepted your Raspberry Pi 3.

Step 2 - Install Deb Update Module

Debian packages are one of the most popular package management systems due to its support for ARMv6 (and newer) and the popularity of Debian, Ubuntu, Raspbian and their derivatives.

Mender enables this workflow through Deb Update Modules. The Mender client (installed in step 1) supports different types of updates, using Update Modules. Installing the Deb Update Module will enable support for installing .deb packages. When the Mender client downloads a .deb package from the server, it will run the Deb Update Module executable associated with the type of software downloaded. The Update Module is responsible for carrying out the steps needed to install software of this type.

This approach enables targeted application-level updates for the benefit of lower bandwidth usage, faster updates and more frequent deployments.

In order to use this Update Module you will need to download the mender.artifact.

Make it executable and make sure your location is in your PATH:

chmod +x ~/PATH/mender-artifact

Download the latest version of this Update Module by running:

sudo mkdir -p /usr/share/mender/modules/v3 && sudo wget -P /usr/share/mender/modules/v3 https://raw.githubusercontent.com/mendersoftware/mender/master/support/modules/deb

Step 3 - Create a Mender Artifact

You will need to set the variables first just like any standard shell scripting and set a path to an output file or directory where your .deb package is stored.

ARTIFACT_NAME="my-update-1.0"
DEVICE_TYPE="raspberrypi3"
OUTPUT_PATH="~/PATH/my-update-1.0.mender"
PACKAGES="alacarte_3.11.91-2+rpi4_all.deb"

As you note, you need to set the file or directory PATH to where your .deb package is stored.

The Artifact can be generated using the mender-artifact tool.

Now after assigning variables, generate a Mender Artifact using the following command:

mender-artifact write module-image -T deb -n ${ARTIFACT_NAME} -t ${DEVICE_TYPE} -o ${OUTPUT_PATH} -f $(echo "$PACKAGES" | sed -e 's/ / -f /g')

Step 4 - Update a .deb Package

Now you are all set to deploy a .deb package to your Raspberry Pi 3. Login to the Mender web UI and upload the Artifact file you created in Step 3 in the ‘RELEASES’ tab. You should also have accepted your Raspberry Pi 3 in the DEVICES tab (no pending device) and create a deployment in the DEPLOYMENTS tab.

To make sure you have updated your device successfully, run the following command on the Raspberry Pi 3 board:

Dpkg -l | grep PACKAGE  

Note in this tutorial the PACKAGE file name is alacarte_3.11.91-2+rpi4_all.deb. Use the package file you are using.

You should see the following message for successful update:

Conclusion

In this tutorial we went through a step-by-step guide on how to utilize Mender Update Modules to do a simple Debian (.deb) package update to a Raspberry Pi 3 board.

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!

3 Likes