3. Using RAUC

For using RAUC in your embedded project, you will need to build at least two versions of it:

  • One for your host (build or development) system. This will allow you to create, inspect and modify bundles.
  • One for your target system. This can act both as the service for handling the installation on your system, as a command line tool that allows triggering the installation and inspecting your system or obtaining bundle information.

All common embedded Linux build system recipes for RAUC will solve the task of creating appropriate binaries for you as well as caring for bundle creation and partly system configuration. If you intend to use RAUC with Yocto, use the meta-rauc layer, in case you use PTXdist, simply enable RAUC in your configuration.

Note

When using the RAUC service from your application, the D-Bus interface is preferable to using the provided command-line tool.

3.1. Creating Bundles

To create an update bundle on your build host, RAUC provides the bundle sub-command:

rauc bundle --cert=<certfile> --key=<keyfile> <input-dir> <output-file>

Where <input-dir> must be a directory containing all images and scripts the bundle should include, as well as a manifest file manifest.raucm that describes the content of the bundle for the RAUC updater on the target: which image to install to which slot, which scripts to execute etc. <output-file> must be the path of the bundle file to create. Note that RAUC bundles must always have a .raucb file name suffix in order to ensure that RAUC treats them as bundles.

3.2. Obtaining Bundle Information

rauc info [--output-format=<format>] <input-file>

The info command lists the basic meta data of a bundle (compatible, version, build-id, description) and the images and hooks contained in the bundle.

You can control the output format depending on your needs. By default it will print a human readable representation of the bundle not intended for being processed programmatically. Alternatively you can obtain a shell-parsable description or a JSON representation of the bundle content.

3.3. Installing Bundles

To actually install an update bundle on your target hardware, RAUC provides the install command:

rauc install <input-file>

Alternatively you can trigger a bundle installation via D-Bus.

3.4. Viewing the System Status

For debugging purposes and for scripting it is helpful to gain an overview of the current system as RAUC sees it. The status command allows this:

rauc status [--output-format=<format>]

You can choose the output style of RAUC status depending on your needs. By default it will print a human readable representation of your system. Alternatively you can obtain a shell-parsable description, or a JSON representation of the system status.

3.5. Resigning Bundles

Note

This feature is not fully implemented yet

RAUC allows to resign a bundle from your build host, e.g. for making a testing bundle a release bundle that should have a key that is accepted by non-debugging platforms:

rauc resign --cert=<certfile> --key=<keyfile> <input-file> <output-file>

3.6. Reacting to a Successfully/Failed Boot

Normally, the full system update chain is not complete before being sure that the newly installed system runs without any errors. As the definition and detection of a successful operation is really system-dependent, RAUC provides commands to preserve a slot as being the preferred one to boot or to discard a slot from being bootable.

rauc status mark-good

After verifying that the currently booted system is fully operational, one wants to signal this information to the underlying bootloader implementation which then, for example, resets a boot attempt counter.

rauc status mark-bad

If the current boot failed in some kind, this command can be used to communicate that to the underlying bootloader implementation. In most cases this will disable the currently booted slot or at least switch to a different one.

3.7. Customizing the Update

RAUC provides several ways to customize the update process. Some allow adding and extending details more fine-grainedly, some allow replacing major parts of the default behavior of RAUC.

In general, there exist three major types of customization: configuration, handlers and hooks.

The first is configuration through variables. This allow controlling the update in a predefined way.

The second type is using handlers. Handlers allow extending or replacing the installation process. They are executables (most likely shell scripts) located in the root filesystem and configured in the system’s configuration file. They control static behavior of the system that should remain the same over future updates.

The last type are hooks. They are similar to handlers, except that they are contained in the update bundle. Thus they allow to flexibly extend or customize one or more updates by some special behavior. A common example would be using a per-slot post-install hook that handles configuration migration for a new software version. Hooks are especially useful to handle details of installing an update which were not considered in the previously deployed version.

In the following, handlers and hooks will be explained in more detail.

3.7.1. System Configuration File

Beside providing the basic slot layout, RAUC’s system configuration file also allows you to configure parts of its runtime behavior, such as handlers (see below), paths, etc. For a detailed list of possible configuration options, see System Configuration File section in the Reference chapter.

3.7.2. System-Based Customization: Handlers

For a detailed list of all environment variables exported for the handler scripts, see the Custom Handlers (Interface) section.

Pre-Install Handler

[handlers]
pre-install=/usr/lib/rauc/pre-install

RAUC will call the pre-install handler (if given) during the bundle installation process, right before calling the default or custom installation process. At this stage, the bundle is mounted, its content is accessible and the target group has been determined successfully.

If calling the handler fails or the handler returns a non-zero exit code, RAUC will abort installation with an error.

Install Handler

[handlers]
install=/usr/lib/rauc/install

The install handler is the most powerful one RAUC provides. If you use this, you replace the entire default update procedure of RAUC. It will be executed between the pre-install and post-install handlers.

If calling the handler fails or the handler returns a non-zero exit code, RAUC will abort installation with an error.

Post-Install Handler

[handlers]
post-install=/usr/lib/rauc/post-install

The post install handler will be called right after RAUC successfully performed a system update. If any error occurred during installation, the post-install handler will not be called.

Note that a failed call of the post-install handler or a non-zero exit code will cause a notification about the error but will not change the result of the performed update anymore.

A possible usage for the post-install handler could be to trigger an automatic restart of the system.

System-Info Handler

[handlers]
system-info=/usr/lib/rauc/system-info

The system-info handler is called after loading the configuration file. This way it can collect additional variables from the system, like the system’s serial number.

The handler script must return a system serial number by echoing RAUC_SYSTEM_SERIAL=<value> to standard out.

3.7.3. Bundle-Based Customization: Hooks

Unlike handlers, hooks allow the author of a bundle to add or replace functionality for the installation of a specific bundle. This can be useful for performing additional migration steps, checking for specific previously installed bundle versions or for manually handling updates of images RAUC cannot handle natively.

To reduce the complexity and number of files in a bundle, all hooks must be handled by a single executable that is registered in the bundle’s manifest:

[hooks]
filename=hook

Each hook must be activated explicitly and leads to a call of the hook executable with a specific argument that allows to distinguish between the different hook types. Multiple hook types must be separated with a ;.

In the following the available hooks are listed. Depending on their purpose, some are image-specific, i.e. they will be executed for the installation of a specific image only, while some other are global.

3.7.3.1. Install Hooks

Install hooks operate globally on the bundle installation.

The following environment variables will be passed to the hook executable:

RAUC_SYSTEM_COMPATIBLE
The compatible value set in the system configuration file
RAUC_MF_COMPATIBLE
The compatible value provided by the current bundle
RAUC_MF_VERSION
The value of the version field as provided by the current bundle
RAUC_MOUNT_PREFIX
The global RAUC mount prefix path

Install-Check Hook

[hooks]
filename=hook
hooks=install-check

This hook will be executed instead of the normal compatible check in order to allow performing a custom compatibility check based on compatible and/or version information.

To indicate that a bundle should be rejected, the script must return with an exit code >= 10.

If available, RAUC will use the last line printed to standard error by the hook executable as the rejection reason message and provide it to the user:

#!/bin/sh

case "$1" in
        install-check)
                if [[ "$RAUC_MF_COMPATIBLE" != "$RAUC_SYSTEM_COMPATIBLE" ]]; then
                        echo "Comptaible does not match!" 1>&2
                        exit 10
                fi
                ;;
        *)
                exit 1
                ;;
esac

exit 0

3.7.3.2. Slot Hooks

Slot hooks are called for each slot an image will be installed to. In order to enable them, you have to specify them in the hooks key under the respective image section.

Note that hook slot operations will be passed to the executable with the prefix slot-. Thus if you intend to check for the pre-install hook, you have to check for the argument to be slot-pre-install.

The following environment variables will be passed to the hook executable:

RAUC_SLOT_NAME
The name of the currently installed slot
RAUC_SLOT_CLASS
The class of the currently installed slot
RAUC_SLOT_DEVICE
The device of the currently installed slot
RAUC_SLOT_BOOTNAME
If set, the bootname of the currently installed slot
RAUC_SLOT_PARENT
If set, the parent of the currently installed slot
RAUC_SLOT_MOUNT_POINT
If available, the mount point of the currently installed slot
RAUC_IMAGE_NAME
If set, the file name of the image currently to be installed
RAUC_IMAGE_DIGEST
If set, the digest of the image currently to be installed
RAUC_IMAGE_CLASS
If set, the target class of the image currently to be installed
RAUC_MOUNT_PREFIX
The global RAUC mount prefix path

Pre-Install Hook

The pre-install hook will be called right before the update procedure for the respective slot will be started. For slot types that represent a mountable file system, the hook will be executed with having the file system mounted.

[hooks]
filename=hook

[image.rootfs]
filename=rootfs.img
size=...
sha256=...
hooks=pre-install

Post-Install Hook

The post-install hook will be called right after the update procedure for the respective slot was finished successfully. For slot types that represent a mountable file system, the hook will be executed with having the file system mounted. This allows to write some post-install information to the slot. It is also useful to copy files from the currently active system to the newly installed slot, for example to preserve application configuration data.

[hooks]
filename=hook

[image.rootfs]
filename=rootfs.img
size=...
sha256=...
hooks=post-install

An example on how to use a post-install hook:

#!/bin/sh

case "$1" in
        slot-post-install)
                # only rootfs needs to be handled
                test "$RAUC_SLOT_CLASS" = "rootfs" || exit 0

                touch "$RAUC_SLOT_MOUNT_POINT/extra-file"
                ;;
        *)
                exit 1
                ;;
esac

exit 0

Install Hook

The install hook will replace the entire default installation process for the target slot of the image it was specified for. Note that when having the install hook enabled, pre- and post-install hooks will not be executed. The install hook allows to fully customize the way an image is installed. This allows performing special installation methods that are not natively supported by RAUC, for example to upgrade the bootloader to a new version while also migrating configuration settings.

[hooks]
filename=hook

[image.rootfs]
filename=rootfs.img
size=...
sha256=...
hooks=install

3.7.4. Full Custom Update

For some special tasks (recovery, testing, migration) it might be required to completely replace the default RAUC update mechanism and to only use its infrastructure for executing an application or a script on the target side.

For this case, you may replace the entire default installation handler of rauc by a custom handler script or application.

Refer system.conf [handler] section description on how to achieve this.

3.8. Using the D-Bus API

The RAUC D-BUS API allows seamless integration into existing or project-specific applications, incorporation with bridge services such as the rauc-hawkbit client and also the rauc CLI uses it.

The API’s service domain is de.pengutronix.rauc while the object path is /.

The D-Bus API’s main purpose is to trigger and monitor the installation process via its Installer interface. While the Install operation starts the installation progress, constant progress information will be emitted in form of changes to the Progress property. Upon completing the installation RAUC emits the Completed signal indicating either successful or failed installation.

3.8.1. Processing Progress Data

The progress property will be updated upon each change of the progress value. For details see the The “Progress” Property chapter in the reference documentation.

To monitor Progress property changes from your application, attach to the PropertiesChanged signal and filter on the Operation properties.

Each progress step emitted is a tuple (percentage, message, nesting depth) describing a tree of progress steps:

├"Installing" (0%)
│ ├"Determining slot states" (0%)
│ ├"Determining slot states done." (20%)
│ ├"Checking bundle" (20%)
│ │ ├"Verifying signature" (20%)
│ │ └"Verifying signature done." (40%)
│ ├"Checking bundle done." (40%)
│ ...
└"Installing done." (100%)

This hierarchical structure allows applications to decide for the appropriate granularity to display information. Progress messages with a nesting depth of 1 are only Installing and Installing done.. A nesting depth of 2 means more fine-grained information while larger depths are even more detailed.

Additionally, the nesting depth information allows the application to print tree-like views as shown above. The percentage value always goes from 0 to 100 while the message is always a human-readable English string. For internationalization you may use a gettext-based approach.

3.8.2. Examples Using busctl Command

Triggering an installation:

busctl call de.pengutronix.rauc / de.pengutronix.rauc.Installer Install s "/path/to/bundle"

Get the Operation property containing the current operation:

busctl get-property de.pengutronix.rauc / de.pengutronix.rauc.Installer Operation

Get the Progress property containing the progress information:

busctl get-property de.pengutronix.rauc / de.pengutronix.rauc.Installer Progress

Get the LastError property, which contains the last error that occurred during an installation.

busctl get-property de.pengutronix.rauc / de.pengutronix.rauc.Installer LastError

Monitor the D-Bus interface

busctl monitor de.pengutronix.rauc