summaryrefslogtreecommitdiffstats
path: root/meta-oe/classes/sysext-image.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/classes/sysext-image.bbclass')
-rw-r--r--meta-oe/classes/sysext-image.bbclass87
1 files changed, 87 insertions, 0 deletions
diff --git a/meta-oe/classes/sysext-image.bbclass b/meta-oe/classes/sysext-image.bbclass
new file mode 100644
index 0000000000..3771236c6e
--- /dev/null
+++ b/meta-oe/classes/sysext-image.bbclass
@@ -0,0 +1,87 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# System extension images may – dynamically at runtime — extend the
8# /usr/ and /opt/ directory hierarchies with additional files. This is
9# particularly useful on immutable system images where a /usr/ and/or
10# /opt/ hierarchy residing on a read-only file system shall be
11# extended temporarily at runtime without making any persistent
12# modifications.
13
14## Example usage:
15# extension-image-example.bb
16#SUMMARY = "An example image to showcase a system extension image."
17#LICENSE = "MIT"
18#inherit discoverable-disk-image sysext-image
19#IMAGE_FEATURES = ""
20#IMAGE_LINGUAS = ""
21#IMAGE_INSTALL = "gdb"
22#
23## After building, the resulting 'extension-image-example-*sysext.rootfs.ddi'
24# can be deployed to an embedded system (running from a RO rootfs) and
25# 'merged' into the OS by following steps:
26## 1. place a symlink into the systemd-sysext image search path:
27# $> mkdir /run/extensions
28# $> ln -s /tmp/extension-example.sysext.ddi /run/extensions/example.raw
29## 2. list all available extensions:
30# $> systemd-sysext list
31## 3. and enable the found extensions:
32# $> SYSTEMD_LOG_LEVEL=debug systemd-sysext merge
33
34# Note: PACKAGECONFIG:pn-systemd needs to include 'sysext'
35
36# systemd-sysext [1] has a simple mechanism for version compatibility:
37# the extension to be loaded has to contain a file named
38# /usr/lib/extension-release.d/extension-release.NAME
39# with "NAME" part *exactly* matching the filename of the extensions
40# raw-device filename/
41#
42# From the extension-release file the "ID" and "VERSION_ID" fields are
43# matched against same fields present in `os-release` and the extension
44# is "merged" only if values in both fields from both files are an
45# exact match.
46#
47# Link: https://www.freedesktop.org/software/systemd/man/latest/systemd-sysext.html
48
49inherit image
50
51# Include '.sysext' in the deployed image filename and symlink
52IMAGE_NAME = "${IMAGE_BASENAME}${IMAGE_MACHINE_SUFFIX}${IMAGE_VERSION_SUFFIX}.sysext"
53IMAGE_LINK_NAME = "${IMAGE_BASENAME}${IMAGE_MACHINE_SUFFIX}.sysext"
54EXTENSION_NAME = "${IMAGE_LINK_NAME}.${IMAGE_FSTYPES}"
55
56# Base extension identification fields
57EXTENSION_ID_FIELD ?= "${DISTRO}"
58EXTENSION_VERSION_FIELD ?= "${DISTRO_VERSION}"
59
60sysext_image_add_version_identifier_file() {
61 # Use matching based on Distro name and version
62 echo 'ID=${EXTENSION_ID_FIELD}' > ${WORKDIR}/extension-release.base
63 # os-release.bb does "sanitise_value(ver)", which needs to be done here too
64 echo 'VERSION_ID=${EXTENSION_VERSION_FIELD}' \
65 | sed 's,+,-,g;s, ,_,g' \
66 >> ${WORKDIR}/extension-release.base
67
68 # Instruct `systemd-sysext` to perform re-load once extension image is verified
69 echo 'EXTENSION_RELOAD_MANAGER=1' >> ${WORKDIR}/extension-release.base
70
71 install -d ${IMAGE_ROOTFS}${nonarch_libdir}/extension-release.d
72 install -m 0644 ${WORKDIR}/extension-release.base \
73 ${IMAGE_ROOTFS}${nonarch_libdir}/extension-release.d/extension-release.${EXTENSION_NAME}
74
75 # systemd-sysext expects an extension-release file of the exact same name as the image;
76 # by setting a xattr we allow renaming of the extension image file.
77 # (Kernel: this requires xattr support in the used filesystem)
78 setfattr -n user.extension-release.strict -v false \
79 ${IMAGE_ROOTFS}${nonarch_libdir}/extension-release.d/extension-release.${EXTENSION_NAME}
80}
81
82ROOTFS_POSTPROCESS_COMMAND += "sysext_image_add_version_identifier_file"
83
84# remove 'os-release' from the packages to be installed into the image.
85# systemd-sysext otherwise raises the error:
86# Extension contains '/usr/lib/os-release', which is not allowed, refusing.
87PACKAGE_EXCLUDE += "os-release"