From 3ed184d53c1a28614584b0e19b7a29ae6f13e5e9 Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Tue, 10 Oct 2023 17:37:15 +0100 Subject: [PATCH] factory: handle properly snapd_recovery_mode based on modeenv value The real source of true for the current mode is stored in /var/lib/snapd/modeenv this value might be altered after /usr/lib/systemd/system-generators/journald-console was already run. Or /var/lib/snapd/modeenv did not even exist at that time. This happens in install/factory-reset/recovery modes which might be handled within the initrd. If this is detected, update journald-console generator and remove already created journald.conf.d/core-override.conf overlay. Signed-off-by: Ondrej Kubik --- factory/usr/lib/systemd/system-generators/journald-console | 2 +- factory/usr/lib/the-modeenv | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/factory/usr/lib/systemd/system-generators/journald-console b/factory/usr/lib/systemd/system-generators/journald-console index 9602f549..47b81c96 100755 --- a/factory/usr/lib/systemd/system-generators/journald-console +++ b/factory/usr/lib/systemd/system-generators/journald-console @@ -1,5 +1,5 @@ #!/bin/sh -if ! grep -q 'snapd_recovery_mode=install' /proc/cmdline +if grep -q 'snapd_recovery_mode=run' /proc/cmdline then exit 0 fi diff --git a/factory/usr/lib/the-modeenv b/factory/usr/lib/the-modeenv index 84bdbc8d..19c878ef 100755 --- a/factory/usr/lib/the-modeenv +++ b/factory/usr/lib/the-modeenv @@ -19,6 +19,13 @@ if [ "${mode}" = "run" ]; then elif [ -f /run/mnt/ubuntu-boot/uboot/ubuntu/boot.sel ]; then echo '/run/mnt/ubuntu-boot/uboot/ubuntu /boot/uboot none bind 0 0' >> /run/image.fstab fi + # if there is override for journald.conf, remove it, it has ForwardToConsole=true + # also modify generator, as current mode is now new run mode + if [ -f /run/systemd/journald.conf.d/core-override.conf ]; then + rm /run/systemd/journald.conf.d/core-override.conf + cmdline_mode="$(/usr/libexec/core/get-arg snapd_recovery_mode) + sed -i 's/snapd_recovery_mode=run/snapd_recovery_mode='"${cmdline_mode}"'/g' /usr/lib/systemd/system-generators/journald-console + fi fi mount -o bind /run/image.fstab /sysroot/etc/fstab umount -lf /sysroot/run