From d233b7660dacc22787bd6c294b62caa39be75d7f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 25 Aug 2020 13:01:26 +0200 Subject: [PATCH 1/2] busybox: add systemd generator to override default.target libreelec-target-generator replaces the logic previously used in the initramfs init script and dynamically redirects default.target if needed. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/package.mk | 3 ++ .../scripts/libreelec-target-generator | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 packages/sysutils/busybox/scripts/libreelec-target-generator diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index 7249376e7b..8ddccee366 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -144,6 +144,9 @@ makeinstall_target() { cp $PKG_DIR/scripts/rpi-flash-firmware $INSTALL/usr/lib/libreelec fi + mkdir -p $INSTALL/usr/lib/systemd/system-generators/ + cp $PKG_DIR/scripts/libreelec-target-generator $INSTALL/usr/lib/systemd/system-generators/ + mkdir -p $INSTALL/etc cp $PKG_DIR/config/profile $INSTALL/etc cp $PKG_DIR/config/inputrc $INSTALL/etc diff --git a/packages/sysutils/busybox/scripts/libreelec-target-generator b/packages/sysutils/busybox/scripts/libreelec-target-generator new file mode 100755 index 0000000000..7cb2f32e78 --- /dev/null +++ b/packages/sysutils/busybox/scripts/libreelec-target-generator @@ -0,0 +1,44 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2020-present Matthias Reichl + +EARLY_DIR="$2" + +log() { + echo "libreelec-target-generator: $@" > /dev/kmsg +} + +if [ -z "$EARLY_DIR" ]; then + log "error: generator directory missing" + exit 1 +fi + +TARGET="" + +for arg in $(cat /proc/cmdline); do + case "$arg" in + textmode) + TARGET="textmode.target" + ;; + installer) + TARGET="installer.target" + ;; + esac +done + +BACKUP_FILE=$(ls -1 /storage/.restore/*.tar 2>/dev/null | head -n 1) + +if [ -f /storage/.please_resize_me ]; then + TARGET="fs-resize.target" +elif [ -f /storage/.cache/reset_oe -o -f /storage/.cache/reset_xbmc ]; then + TARGET="factory-reset.target" +elif [ -f "$BACKUP_FILE" ]; then + TARGET="backup-restore.target" +elif [ -f /storage/.rpi_flash_firmware ]; then + TARGET="rpi-flash-firmware.target" +fi + +if [ -n "$TARGET" ]; then + ln -sT "/usr/lib/systemd/system/$TARGET" "$EARLY_DIR/default.target" 2>/dev/kmsg || log "error creating symlink to $TARGET: $?" +fi From 2da7a9f3514dc61d16c2ea9a5375f8bba212c245 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 25 Aug 2020 13:32:23 +0200 Subject: [PATCH 2/2] init: drop INIT_UNIT logic This is now handled by the libreelec-target-generator systemd generator. Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/scripts/init | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 983a85e11c..b747a53e88 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -1005,11 +1005,7 @@ for arg in $(cat /proc/cmdline); do wol_wait=*) wol_wait="${arg#*=}" ;; - textmode) - INIT_UNIT="--unit=textmode.target" - ;; installer) - INIT_UNIT="--unit=installer.target" SYSLINUX_DEFAULT="installer" ;; debugging) @@ -1134,19 +1130,7 @@ if [ "$STORAGE_NETBOOT" = "yes" ]; then echo "" > /sysroot/dev/.storage_netboot fi -BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/*.tar 2>/dev/null | head -n 1) - -if [ -f /sysroot/storage/.please_resize_me ]; then - INIT_UNIT="--unit=fs-resize.target" -elif [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ]; then - INIT_UNIT="--unit=factory-reset.target" -elif [ -f "$BACKUP_FILE" ]; then - INIT_UNIT="--unit=backup-restore.target" -elif [ -f /sysroot/storage/.rpi_flash_firmware ]; then - INIT_UNIT="--unit=rpi-flash-firmware.target" -fi - # switch to new sysroot and start real init -exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT +exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS error "switch_root" "Error in initramfs. Could not switch to new root"