@@ -790,4 +790,22 @@ unset (the default), `Rules-Requires-Root` will not be added. Otherwise,
Set `Rules-Requires-Root: no` in `debian/control` files to prevent unnecessary
invocation of fakeroot during package builds. This follows Debian guidelines
recommending not to use fakeroot when no privileged operations (e.g., `chown`,
-root file modifications) are required.
+root file modifications) are required.
+
+### Populate systemd units based on presets during image postprocessing
+
+By default population of the presets is automatically done by systemd
+on first-boot.
+
+There were several issues with that:
+
+1. The rootfs we get as a build artifact does not reflect the actual
+system running in the field.
+
+2. For setups without writeable /etc this fails. With that addition
+it happens already at build time.
+
+**Note**: Additional services are enabled only. Services already enabled
+during the package installation won't be changed.
+
+Opt-out: `ROOTFS_FEATURES:remove = "populate-systemd-preset"`
@@ -73,6 +73,7 @@ ROOTFS_FEATURES += "\
export-dpkg-status \
clean-log-files \
clean-debconf-cache \
+ populate-systemd-preset \
"
# when using a custom initrd, do not generate one as part of the image rootfs
ROOTFS_FEATURES += "${@ '' if d.getVar('INITRD_IMAGE') == '' else 'no-generate-initrd'}"
@@ -15,6 +15,7 @@ ROOTFS_BASE_DISTRO ?= "${BASE_DISTRO}"
# 'export-dpkg-status' - exports /var/lib/dpkg/status file to ${ROOTFS_DPKGSTATUS_DEPLOY_DIR}
# 'clean-log-files' - delete log files that are not owned by packages
# 'no-generate-initrd' - do not generate debian default initrd
+# 'populate-systemd-preset' - enable systemd units according to systemd presets
ROOTFS_FEATURES ?= ""
ROOTFS_APT_ARGS="install --yes -o Debug::pkgProblemResolver=yes"
@@ -520,6 +521,17 @@ rootfs_cleanup_base_apt() {
EOSUDO
}
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'populate-systemd-preset', 'image_postprocess_populate_systemd_preset', '', d)}"
+image_postprocess_populate_systemd_preset() {
+ SYSTEMD_INSTALLED=$(sudo chroot '${ROOTFSDIR}' dpkg-query \
+ --showformat='${db:Status-Status}' \
+ --show systemd || echo "" )
+
+ if (test "$SYSTEMD_INSTALLED" = "installed"); then
+ sudo chroot '${ROOTFSDIR}' systemctl preset-all --preset-mode="enable-only"
+ fi
+}
+
do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
do_rootfs_postprocess[network] = "${TASK_USE_SUDO}"
python do_rootfs_postprocess() {