Skip to contentSkip to conversation

systemd-systemctl-native: Install systemd-sysv-install

PATCH Superseded Peter Kjellerstedt 3 participants 4 messages Aug 22, 2025 – Sep 8, 2025

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/2 systemd-systemctl-native: Install systemd-sysv-install

It is needed when support for both systemd and sysvinit are enabled.

This also adds a patch for systemctl to call systemd-sysv-install without a hardcoded path and instead relies on finding it in $PATH. This is needed when calling systemctl from a recipe sysroot.

---

PATCHv2: New.
PATCHv3: Change the Upstream-Status to Denied.
PATCHv4: Add a Signed-off-by to the new patch.
PATCHv5: Always install systemd-sysv-install.
PATCHv6: Completely reworked the patch for systemctl.

 .../systemd/systemd-systemctl-native_257.8.bb | 11 ++++++
 ...ll-systemd-sysv-install-without-path.patch | 37 +++++++++++++++++++
 ...implment-systemd-sysv-install-for-OE.patch | 13 +++----
 3 files changed, 53 insertions(+), 8 deletions(-)
 create mode 100644 meta/recipes-core/systemd/systemd/0001-systemctl-Call-systemd-sysv-install-without-path.patch
meta/recipes-core/systemd/systemd-systemctl-native_257.8.bb +11 -0
index 041a040a26..4486edf651 100644
@@ -1,9 +1,14 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/systemd:"
+
 SUMMARY = "Systemctl executable from systemd"
 
 require systemd.inc
 
 DEPENDS = "gperf-native libcap-native util-linux-native python3-jinja2-native"
 
+SRC_URI += "file://0001-systemctl-Call-systemd-sysv-install-without-path.patch"
+SRC_URI += "file://0002-implment-systemd-sysv-install-for-OE.patch"
+
 inherit pkgconfig meson native
 
 MESON_TARGET = "systemctl:executable"
@@ -14,3 +19,9 @@ EXTRA_OEMESON += "-Dlink-systemctl-shared=false"
 # determined at run-time, but rather set during configure
 # More details are here https://github.com/systemd/systemd/issues/35897#issuecomment-2665405887
 EXTRA_OEMESON += "--sysconfdir ${sysconfdir_native}"
+
+do_install:append() {
+	# Install systemd-sysv-install in /usr/bin rather than /usr/lib/systemd
+	# (where it is normally installed) so systemctl can find it in $PATH.
+	install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON ${D}${bindir}/systemd-sysv-install
+}
meta/recipes-core/systemd/systemd/0001-systemctl-Call-systemd-sysv-install-without-path.patch new file +37 -0
new file mode 100644
index 0000000000..bf08dbe9b0
@@ -0,0 +1,37 @@
+From 34c8551a8b16bf235a1ebe8d9cb1a3474a7c975e Mon Sep 17 00:00:00 2001
+From: Peter Kjellerstedt <[email protected]>
+Date: Fri, 22 Aug 2025 18:07:28 +0200
+Subject: [PATCH] systemctl: Call systemd-sysv-install without path
+
+Expect to find systemd-sysv-install in $PATH instead of hardcoding the
+path to it, as the latter does not work when running systemctl from a
+recipe sysroot.
+
+Signed-off-by: Peter Kjellerstedt <[email protected]>
+Upstream-Status: Inappropriate [OE specific]
+---
+ src/systemctl/systemctl-sysv-compat.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/systemctl/systemctl-sysv-compat.c b/src/systemctl/systemctl-sysv-compat.c
+index cb9c43e3dc..e44ef9f64e 100644
+--- a/src/systemctl/systemctl-sysv-compat.c
++++ b/src/systemctl/systemctl-sysv-compat.c
+@@ -140,7 +140,7 @@ int enable_sysv_units(const char *verb, char **args) {
+         while (args[f]) {
+ 
+                 const char *argv[] = {
+-                        LIBEXECDIR "/systemd-sysv-install",
++                        "systemd-sysv-install",
+                         NULL, /* --root= */
+                         NULL, /* verb */
+                         NULL, /* service */
+@@ -218,7 +218,7 @@ int enable_sysv_units(const char *verb, char **args) {
+                         return j;
+                 if (j == 0) {
+                         /* Child */
+-                        execv(argv[0], (char**) argv);
++                        execvp(argv[0], (char**) argv);
+                         log_error_errno(errno, "Failed to execute %s: %m", argv[0]);
+                         _exit(EXIT_FAILURE);
+                 }
meta/recipes-core/systemd/systemd/0002-implment-systemd-sysv-install-for-OE.patch +5 -8
index d8bb572261..98d050ceae 100644
@@ -1,7 +1,7 @@
-From fab8c573d06340868f070446118673b1c23584c5 Mon Sep 17 00:00:00 2001
+From 4a5602ede9881fd8e578a3c8bc40dd5df7c4d802 Mon Sep 17 00:00:00 2001
 From: Khem Raj <[email protected]>
 Date: Sat, 5 Sep 2015 06:31:47 +0000
-Subject: [PATCH 02/26] implment systemd-sysv-install for OE
+Subject: [PATCH] implement systemd-sysv-install for OE
 
 Use update-rc.d for enabling/disabling and status command
 to check the status of the sysv service
@@ -14,7 +14,7 @@ Signed-off-by: Khem Raj <[email protected]>
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/src/systemctl/systemd-sysv-install.SKELETON b/src/systemctl/systemd-sysv-install.SKELETON
-index cb58d8243b..000bdf6165 100755
+index cb58d8243b..eff3f5f579 100755
 --- a/src/systemctl/systemd-sysv-install.SKELETON
 +++ b/src/systemctl/systemd-sysv-install.SKELETON
 @@ -34,17 +34,17 @@ case "$1" in
@@ -22,13 +22,13 @@ index cb58d8243b..000bdf6165 100755
          # call the command to enable SysV init script $NAME here
          # (consider optional $ROOT)
 -        echo "IMPLEMENT ME: enabling SysV init.d script $NAME"
-+        update-rc.d -f $NAME defaults
++        update-rc.d ${ROOT:+-r $ROOT} -f $NAME defaults
          ;;
      disable)
          # call the command to disable SysV init script $NAME here
          # (consider optional $ROOT)
 -        echo "IMPLEMENT ME: disabling SysV init.d script $NAME"
-+        update-rc.d -f $NAME remove
++        update-rc.d ${ROOT:+-r $ROOT} -f $NAME remove
          ;;
      is-enabled)
          # exit with 0 if $NAME is enabled, non-zero if it is disabled
@@ -38,6 +38,3 @@ index cb58d8243b..000bdf6165 100755
          ;;
      *)
          usage ;;
--- 
-2.34.1
-
#1 lore raw

PATCH v6 2/2 systemd.bbclass: Make systemd_postinst run as intended

After the switch from using a systemctl written in Python to using the official version of systemctl from the systemd project, the systemd_postinst function has effectively not been executed during the rootfs creation. The reason is that systemctl provided by systemctl-native fails if run without arguments (as systemd_postinst does):

Failed to connect to system scope bus via local transport: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)

This is not seen in the logs since stderr is sent to /dev/null, and the only way to tell that there is a problem is because systemd services that are expected to be enabled aren't running.

The reason this has gone unnoticed is because systemd_handle_machine_id in rootfs-postcommands.bbclass will call systemctl preset-all, which in most cases will create the missing links to enable the systemd services.

This change effectively reverts commit a52e66762c0c51918b1ba3d4622759637b6e920a (systemd.bbclass: update command to check systemctl available) and instead only runs systemctl without arguments (to determine that it can communicate with systemd) when executed on target.

---

PATCHv2: Add --sysv-install= to $OPTS to instruct systemctl where to
look for systemd-sysv-install.
PATCHv3: No changes.
PATCHv4: No changes.
PATCHv5: No changes.
PATCHv6: Removed the --sysv-install= parameter again.

 meta/classes-recipe/systemd.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes-recipe/systemd.bbclass +4 -4
index 0e9f7cfa33..4e687135f1 100644
@@ -29,7 +29,7 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if systemctl >/dev/null 2>/dev/null; then
+if type systemctl >/dev/null 2>/dev/null; then
 	OPTS=""
 
 	if [ -n "$D" ]; then
@@ -46,7 +46,7 @@ if systemctl >/dev/null 2>/dev/null; then
 		done
 	fi
 
-	if [ -z "$D" ]; then
+	if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then
 		# Reload only system service manager
 		# --global for daemon-reload is not supported: https://github.com/systemd/systemd/issues/19284
 		systemctl daemon-reload
@@ -66,8 +66,8 @@ fi
 }
 
 systemd_prerm() {
-if systemctl >/dev/null 2>/dev/null; then
-	if [ -z "$D" ]; then
+if type systemctl >/dev/null 2>/dev/null; then
+	if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then
 		if [ -n "${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}" ]; then
 			systemctl stop ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
 			systemctl disable ${@systemd_filter_services("${SYSTEMD_SERVICE_ESCAPED}", False, d)}
#2 lore raw
In reply to Peter Kjellerstedt

meta/recipes-core/systemd/systemd-systemctl-native_257.8.bb EXTRA_OEMESON += "-Dlink-systemctl-shared=false" · line 27

Quoted 5 lines · Peter Kjellerstedt via lists.openembedded.org
meta/recipes-core/systemd/systemd-systemctl-native_257.8.bb +5 -0
+do_install:append() {
+ # Install systemd-sysv-install in /usr/bin rather than /usr/lib/systemd
+ # (where it is normally installed) so systemctl can find it in $PATH.
+ install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON ${D}${bindir}/systemd-sysv-install
+}

To save future maintainers, I feel like this should have a comment saying that it’s expected that this patch will need to be reverted when systemd is upgraded to v259, as that will remove this functionality.

Ross

#3 lore raw
Quoted 17 lines

-----Original Message-----
From: [email protected] <openembedded- [email protected]> On Behalf Of Ross Burton via lists.openembedded.org
Sent: den 1 september 2025 19:08
To: Peter Kjellerstedt <[email protected]>
Cc: [email protected]
Subject: Re: [OE-core] [PATCHv6 1/2] systemd-systemctl-native: Install systemd-sysv-install

Quoted 2 lines · Peter Kjellerstedt via lists.openembedded.org

+do_install:append() {
+ # Install systemd-sysv-install in /usr/bin rather than

/usr/lib/systemd

Quoted 2 lines

+ # (where it is normally installed) so systemctl can find it in $PATH.
+ install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON

Quoted 8 lines

${D}${bindir}/systemd-sysv-install

Quoted 1 line

+}

To save future maintainers, I feel like this should have a comment saying that it’s expected that this patch will need to be reverted when systemd is upgraded to v259, as that will remove this functionality.

Ross

Ok, I have sent an updated version with an added comment.

//Peter