ossystems-factory-defaults allows users to restore "factory" default configuration for software available in images.

The factory-defaults feature is implemented as a class and a recipe (which is automatically added to RDEPENDS when a recipe inherits the ossystems-factory-defaults class).

Here’s an example on how to extend a recipe (openssh) to use ossystems-factory-defaults:

$ cat openssh_%.bbappend

FILESEXTRAPATHS_prepend := "${THISDIR}/openssh:"

SRC_URI += "file://openssh.factory-defaults-hook"

do_install_append() {
    # Install the script referenced in SRC_URI in
    # ${sysconfdir}/factory-defaults.d/ as openssh. This script will
    # be invoked when users restore the factory-defaults configuration.
    # In this case, it will just create the configuration directory.
    install -d ${D}${sysconfdir}/factory-defaults.d/
    install -m 755 ${WORKDIR}/openssh.factory-defaults-hook \

inherit ossystems-factory-defaults

# Here we specify which files will be part of the default factory
# configuration
    ${sysconfdir}/ssh/ssh_host_rsa_key \
    ${sysconfdir}/ssh/ssh_host_dsa_key \
    ${sysconfdir}/ssh/ssh_host_ecdsa_key \
$ cat openssh/openssh.factory-defaults-hook

#! /bin/sh

mkdir -p /config/etc/ssh


The ossystems-factory-defaults class provides some variables that can be configured.


files to be added to the factory default configuration. Default: empty.


files generated by postinst tasks to be added to the factory default configuration. Default: empty.


directory where factory default configuration is stored. Default: "${datadir}/factory-defaults"


directory where configuration files link to. Usually in a filesystem mounted with read-write permissions. Default: /config.


files to be installed in $OSSYSTEMS_FACTORY_DEFAULTS_HOOKS_DIR. The syntax for referencing files is the same as for BitBake’s SRC_URI. Default: empty.


directory for hook programs. Hook programs are run by factory-defaults right after restoring the default configuration. Default: ${sysconfdir}/factory-defaults.d.

Restoring defaults

The fatory-defaults recipe (automatically added to the image when recipes inherit the ossystems-factory-defaults class) installs a factory-defaults tool in the image. That tool is run on boot, checking for the existence of a special file in the filesystem. If that file does not exist, it will restore factory defaults and create the special file (so that next time it won’t restore defaults again). If the special file exists, it won’t do anything.

That scheme provides a flexible way to integrate factory-tools to your image and applications: when you need to restore the factory default configuration, all you have to do is remove a file and reboot the system. On the following boot, the default configuration will be restored.

The special file factory-defaults looks for is $OSSYSTEMS_FACTORY_DEFAULTS_RUNTIME_DIR/.factory-defaults. Under normal circumstances, it will exist. To cause the default configuration to be restored on the next boot, just remove that file.

After restoring configuration files, factory-default runs hook scripts it finds in /etc/factory-defaults.d. Hook scripts in that directory may be any executable file (e.g., shell script, python script etc).