diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-10 04:33:43 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-10 21:04:20 +0000 |
| commit | a71e7b0499c51c74686e41e7810e2f202d851ce6 (patch) | |
| tree | 427d8b0fde510ce30f4dc3bb9a5ca5c93d634f21 | |
| parent | 56f78049cff106e52a57e2544d025ea94fd0c702 (diff) | |
| download | meta-virtualization-a71e7b0499c51c74686e41e7810e2f202d851ce6.tar.gz | |
container-systemd-base: replace ROOTFS_POSTPROCESS_COMMAND with package
Factor systemd service masking into container-systemd-config package
that installs mask symlinks via do_install. This replaces the
ROOTFS_POSTPROCESS_COMMAND approach which is ignored in multi-layer
OCI mode.
The mask list is customizable via CONTAINER_SYSTEMD_MASK variable.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
3 files changed, 35 insertions, 46 deletions
diff --git a/recipes-extended/container-systemd-config/container-systemd-config_1.0.bb b/recipes-extended/container-systemd-config/container-systemd-config_1.0.bb new file mode 100644 index 00000000..a808fcd1 --- /dev/null +++ b/recipes-extended/container-systemd-config/container-systemd-config_1.0.bb | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | SUMMARY = "Systemd service masking for container use" | ||
| 2 | DESCRIPTION = "Masks systemd services that are inappropriate inside containers \ | ||
| 3 | (udev, hwdb, serial-getty, etc.). Installed as a package so it works \ | ||
| 4 | with both single-layer and multi-layer OCI images." | ||
| 5 | LICENSE = "MIT" | ||
| 6 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
| 7 | |||
| 8 | inherit allarch | ||
| 9 | |||
| 10 | # Default services to mask in containers | ||
| 11 | # Customizable: CONTAINER_SYSTEMD_MASK:pn-container-systemd-config:append = " extra.service" | ||
| 12 | CONTAINER_SYSTEMD_MASK ?= "\ | ||
| 13 | systemd-udevd.service \ | ||
| 14 | systemd-udevd-control.socket \ | ||
| 15 | systemd-udevd-kernel.socket \ | ||
| 16 | proc-sys-fs-binfmt_misc.automount \ | ||
| 17 | sys-fs-fuse-connections.mount \ | ||
| 18 | sys-kernel-debug.mount \ | ||
| 19 | systemd-hwdb-update.service \ | ||
| 20 | serial-getty@ttyS0.service \ | ||
| 21 | dev-ttyS0.device \ | ||
| 22 | console-getty.service \ | ||
| 23 | serial-getty@.service \ | ||
| 24 | " | ||
| 25 | |||
| 26 | do_install() { | ||
| 27 | install -d ${D}${sysconfdir}/systemd/system | ||
| 28 | for service in ${CONTAINER_SYSTEMD_MASK}; do | ||
| 29 | ln -sf /dev/null ${D}${sysconfdir}/systemd/system/$service | ||
| 30 | done | ||
| 31 | } | ||
diff --git a/recipes-extended/images/container-systemd-base.bb b/recipes-extended/images/container-systemd-base.bb index 96ef4667..3264e6cf 100644 --- a/recipes-extended/images/container-systemd-base.bb +++ b/recipes-extended/images/container-systemd-base.bb | |||
| @@ -7,11 +7,8 @@ SYSTEMD_CONTAINER_APP ?= "" | |||
| 7 | # Use local.conf to specify the application(s) to install | 7 | # Use local.conf to specify the application(s) to install |
| 8 | IMAGE_INSTALL += "${SYSTEMD_CONTAINER_APP}" | 8 | IMAGE_INSTALL += "${SYSTEMD_CONTAINER_APP}" |
| 9 | 9 | ||
| 10 | # Use local.conf to specify additional systemd services to disable. To overwrite | 10 | # To mask additional systemd services, use: |
| 11 | # the default list use SERVICES_TO_DISABLE:pn-systemd-container in local.conf | 11 | # CONTAINER_SYSTEMD_MASK:pn-container-systemd-config:append = " extra.service" |
| 12 | SERVICES_TO_DISABLE:append = " ${SYSTEMD_CONTAINER_DISABLE_SERVICES}" | 12 | # in local.conf or your image recipe. |
| 13 | |||
| 14 | # Use local.conf to enable systemd services | ||
| 15 | SERVICES_TO_ENABLE += "${SYSTEMD_CONTAINER_ENABLE_SERVICES}" | ||
| 16 | 13 | ||
| 17 | require container-systemd-base.inc | 14 | require container-systemd-base.inc |
diff --git a/recipes-extended/images/container-systemd-base.inc b/recipes-extended/images/container-systemd-base.inc index 0b856e83..ea933390 100644 --- a/recipes-extended/images/container-systemd-base.inc +++ b/recipes-extended/images/container-systemd-base.inc | |||
| @@ -26,47 +26,8 @@ IMAGE_INSTALL:append = " systemd" | |||
| 26 | IMAGE_INSTALL:append = " packagegroup-core-base-utils" | 26 | IMAGE_INSTALL:append = " packagegroup-core-base-utils" |
| 27 | IMAGE_INSTALL:append = " packagegroup-core-ssh-openssh" | 27 | IMAGE_INSTALL:append = " packagegroup-core-ssh-openssh" |
| 28 | IMAGE_INSTALL:append = " busybox" | 28 | IMAGE_INSTALL:append = " busybox" |
| 29 | IMAGE_INSTALL:append = " container-systemd-config" | ||
| 29 | 30 | ||
| 30 | IMAGE_FEATURES ?= "" | 31 | IMAGE_FEATURES ?= "" |
| 31 | 32 | ||
| 32 | NO_RECOMMENDATIONS = "1" | 33 | NO_RECOMMENDATIONS = "1" |
| 33 | |||
| 34 | SERVICES_TO_DISABLE ?= " \ | ||
| 35 | systemd-udevd.service \ | ||
| 36 | systemd-udevd-control.socket \ | ||
| 37 | systemd-udevd-kernel.socket \ | ||
| 38 | proc-sys-fs-binfmt_misc.automount \ | ||
| 39 | sys-fs-fuse-connections.mount \ | ||
| 40 | sys-kernel-debug.mount \ | ||
| 41 | systemd-hwdb-update.service \ | ||
| 42 | serial-getty@ttyS0.service \ | ||
| 43 | dev-ttyS0.device \ | ||
| 44 | console-getty.service \ | ||
| 45 | serial-getty@.service \ | ||
| 46 | " | ||
| 47 | |||
| 48 | SERVICES_TO_ENABLE ?= "" | ||
| 49 | |||
| 50 | disable_systemd_services () { | ||
| 51 | SERVICES_TO_DISABLE="${SERVICES_TO_DISABLE}" | ||
| 52 | if [ -n "$SERVICES_TO_DISABLE" ]; then | ||
| 53 | echo "Disabling systemd services:" | ||
| 54 | for service in $SERVICES_TO_DISABLE; do | ||
| 55 | echo " $service" | ||
| 56 | systemctl --root="${IMAGE_ROOTFS}" mask $service > /dev/null >1 | ||
| 57 | done | ||
| 58 | fi | ||
| 59 | } | ||
| 60 | |||
| 61 | enable_systemd_services () { | ||
| 62 | SERVICES_TO_ENABLE="${SERVICES_TO_ENABLE}" | ||
| 63 | if [ -n "$SERVICES_TO_ENABLE" ]; then | ||
| 64 | echo "Enabling additional systemd services:" | ||
| 65 | for service in $SERVICES_TO_ENABLE; do | ||
| 66 | echo " $service" | ||
| 67 | systemctl --root="${IMAGE_ROOTFS}" enable $service > /dev/null >1 | ||
| 68 | done | ||
| 69 | fi | ||
| 70 | } | ||
| 71 | |||
| 72 | ROOTFS_POSTPROCESS_COMMAND += "disable_systemd_services; enable_systemd_services;" | ||
