From e6922ac3346f91469a5e6e60fdb1e1741a05f424 Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Fri, 20 Dec 2024 14:28:36 +0100 Subject: [PATCH 1/4] man/debug-generator: replace "main system" with "host" --- man/systemd-debug-generator.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/man/systemd-debug-generator.xml b/man/systemd-debug-generator.xml index 529d834b83b..e93ee174606 100644 --- a/man/systemd-debug-generator.xml +++ b/man/systemd-debug-generator.xml @@ -56,7 +56,7 @@ mask command. This is useful to boot with certain units removed from the initial boot transaction for debugging system startup. May be specified more than once. The option prefixed with rd. is honored only in the initrd, while the one without prefix is only - honored in the main system. + honored on the host. @@ -68,7 +68,7 @@ These options take a unit name as argument. A start job for this unit is added to the initial transaction. This is useful to start one or more additional units at boot. May be specified more than once. The option prefixed with rd. is honored only in the initrd, while - the one that is not prefixed only in the main system. + the one that is not prefixed only on the host. @@ -89,7 +89,7 @@ shell may also be turned on persistently by enabling it with systemctl1's enable command. The options prefixed with rd. are honored only - in the initrd, while the ones without prefix are only honored in the main system. + in the initrd, while the ones without prefix are only honored on the host. @@ -103,8 +103,8 @@ rd. option). It also accepts multiple values separated by comma (,). These options allow to pause the boot process at a certain point and spawn a debug shell. After exiting this shell, the system will resume booting. The option prefixed with - rd. is honored only in the initrd, while the one without prefix is only honored in - the main system. + rd. is honored only in the initrd, while the one without prefix is only honored on + the host. Available breakpoints @@ -113,13 +113,13 @@ - + Breakpoints Description Can be used in the initrd - Can be used in the main system + Can be used on the host From b70ba82241cb7ded3b07f98045181df4ce4e8518 Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Fri, 20 Dec 2024 14:29:05 +0100 Subject: [PATCH 2/4] units/breakpoint-pre-basic.service: explicitly order it before sysroot.mount If `rd.systemd.break=pre-mount` is not set during boot, there is no unit that prevents sysroot.mount from being activated. --- units/breakpoint-pre-basic.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/units/breakpoint-pre-basic.service.in b/units/breakpoint-pre-basic.service.in index 69a406149d9..08c014a0736 100644 --- a/units/breakpoint-pre-basic.service.in +++ b/units/breakpoint-pre-basic.service.in @@ -13,7 +13,7 @@ Documentation=man:systemd-debug-generator(8) DefaultDependencies=no Conflicts=shutdown.target emergency.target After=sysinit.target sockets.target paths.target slices.target tmp.mount systemd-vconsole-setup.service -Before=basic.target +Before=basic.target initrd-root-fs.target sysroot.mount [Service] Environment=SHELL_PROMPT_PREFIX="pre-basic " From aeb97a49c3618f831d2dc07818210ee7d91686f3 Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Fri, 3 Jan 2025 08:32:27 +0100 Subject: [PATCH 3/4] debug-generator: use helper to check breakpoint validity --- src/debug-generator/debug-generator.c | 41 ++++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index edc8e5f5f49..098e06ca5db 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -66,10 +66,23 @@ static const struct BreakpointInfo breakpoint_info_table[_BREAKPOINT_TYPE_MAX] = { BREAKPOINT_PRE_SWITCH_ROOT, "pre-switch-root", "breakpoint-pre-switch-root.service", BREAKPOINT_IN_INITRD | BREAKPOINT_DEFAULT }, }; +static bool breakpoint_applies(const BreakpointInfo *info, int log_level) { + assert(info); + + if (in_initrd() && !FLAGS_SET(info->validity, BREAKPOINT_IN_INITRD)) + log_full(log_level, "Breakpoint '%s' not valid in the initrd, ignoring.", info->name); + else if (!in_initrd() && !FLAGS_SET(info->validity, BREAKPOINT_ON_HOST)) + log_full(log_level, "Breakpoint '%s' not valid on the host, ignoring.", info->name); + else + return true; + + return false; +} + static BreakpointType parse_breakpoint_from_string_one(const char *s) { assert(s); - FOREACH_ARRAY(i, breakpoint_info_table, ELEMENTSOF(breakpoint_info_table)) + FOREACH_ELEMENT(i, breakpoint_info_table) if (streq(i->name, s)) return i->type; @@ -84,14 +97,18 @@ static int parse_breakpoint_from_string(const char *s, uint32_t *ret_breakpoints /* Empty value? set default breakpoint */ if (isempty(s)) { - if (in_initrd()) { - FOREACH_ARRAY(i, breakpoint_info_table, ELEMENTSOF(breakpoint_info_table)) - if (i->validity & BREAKPOINT_DEFAULT) { - breakpoints |= 1 << i->type; - break; - } - } else - log_warning("No default breakpoint defined on the host, ignoring breakpoint request from kernel command line."); + bool found_default = false; + + FOREACH_ELEMENT(i, breakpoint_info_table) + if (FLAGS_SET(i->validity, BREAKPOINT_DEFAULT) && breakpoint_applies(i, INT_MAX)) { + breakpoints |= 1 << i->type; + found_default = true; + break; + } + + if (!found_default) + log_warning("No default breakpoint defined %s, ignoring.", + in_initrd() ? "in the initrd" : "on the host"); } else for (;;) { _cleanup_free_ char *t = NULL; @@ -109,11 +126,7 @@ static int parse_breakpoint_from_string(const char *s, uint32_t *ret_breakpoints continue; } - if (in_initrd() && !FLAGS_SET(breakpoint_info_table[tt].validity, BREAKPOINT_IN_INITRD)) - log_warning("Breakpoint '%s' not valid in the initrd, ignoring.", t); - else if (!in_initrd() && !FLAGS_SET(breakpoint_info_table[tt].validity, BREAKPOINT_ON_HOST)) - log_warning("Breakpoint '%s' not valid on the host, ignoring.", t); - else + if (breakpoint_applies(&breakpoint_info_table[tt], LOG_WARNING)) breakpoints |= 1 << tt; } From 5c79396def28b512c7ade2be6fca28f0d152fb5f Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Fri, 3 Jan 2025 08:32:43 +0100 Subject: [PATCH 4/4] units: some improvements in breakpoint-* units. - Set `RefuseManualStart=yes`. - Order before shutdown.target and emergency.target. - Remove wrong `Wants=remote-fs.target` dependency from breakpoint-pre-switch-root.service. - Remove unneeded `After=sysroot.mount` from breakpoint-pre-switch-root.service (implied by initrd.target). --- units/breakpoint-pre-basic.service.in | 5 +++-- units/breakpoint-pre-mount.service.in | 5 +++-- units/breakpoint-pre-switch-root.service.in | 6 +++--- units/breakpoint-pre-udev.service.in | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/units/breakpoint-pre-basic.service.in b/units/breakpoint-pre-basic.service.in index 08c014a0736..e9df12c9939 100644 --- a/units/breakpoint-pre-basic.service.in +++ b/units/breakpoint-pre-basic.service.in @@ -8,12 +8,13 @@ # (at your option) any later version. [Unit] -Description=Breakpoint Before Basic System +Description=Breakpoint Before basic.target Documentation=man:systemd-debug-generator(8) DefaultDependencies=no +RefuseManualStart=yes Conflicts=shutdown.target emergency.target After=sysinit.target sockets.target paths.target slices.target tmp.mount systemd-vconsole-setup.service -Before=basic.target initrd-root-fs.target sysroot.mount +Before=basic.target initrd-root-fs.target sysroot.mount shutdown.target emergency.target [Service] Environment=SHELL_PROMPT_PREFIX="pre-basic " diff --git a/units/breakpoint-pre-mount.service.in b/units/breakpoint-pre-mount.service.in index b50c780f01c..55551dbbf2d 100644 --- a/units/breakpoint-pre-mount.service.in +++ b/units/breakpoint-pre-mount.service.in @@ -8,13 +8,14 @@ # (at your option) any later version. [Unit] -Description=Breakpoint Before Mounting the Root Filesystem on /sysroot +Description=Breakpoint Before Mounting the Root Filesystem on /sysroot/ Documentation=man:systemd-debug-generator(8) AssertPathExists=/etc/initrd-release DefaultDependencies=no +RefuseManualStart=yes Conflicts=shutdown.target emergency.target After=basic.target systemd-vconsole-setup.service -Before=initrd-root-fs.target sysroot.mount systemd-fsck-root.service +Before=initrd-root-fs.target sysroot.mount systemd-fsck-root.service shutdown.target emergency.target [Service] Environment=SHELL_PROMPT_PREFIX="pre-mount " diff --git a/units/breakpoint-pre-switch-root.service.in b/units/breakpoint-pre-switch-root.service.in index 76eaa8039a9..4c6334662c9 100644 --- a/units/breakpoint-pre-switch-root.service.in +++ b/units/breakpoint-pre-switch-root.service.in @@ -12,10 +12,10 @@ Description=Breakpoint Before Switching Root Documentation=man:systemd-debug-generator(8) AssertPathExists=/etc/initrd-release DefaultDependencies=no +RefuseManualStart=yes Conflicts=shutdown.target emergency.target -Wants=remote-fs.target -After=initrd.target initrd-parse-etc.service sysroot.mount remote-fs.target systemd-vconsole-setup.service -Before=initrd-cleanup.service +After=initrd.target initrd-parse-etc.service remote-fs.target systemd-vconsole-setup.service +Before=initrd-cleanup.service shutdown.target emergency.target [Service] Environment=SHELL_PROMPT_PREFIX="pre-switch-root " diff --git a/units/breakpoint-pre-udev.service.in b/units/breakpoint-pre-udev.service.in index baf0e033515..6ef41e7ff93 100644 --- a/units/breakpoint-pre-udev.service.in +++ b/units/breakpoint-pre-udev.service.in @@ -11,10 +11,11 @@ Description=Breakpoint Before Starting to Process Kernel uevents Documentation=man:systemd-debug-generator(8) DefaultDependencies=no +RefuseManualStart=yes Conflicts=shutdown.target emergency.target Wants=systemd-journald.socket After=systemd-journald.socket systemd-vconsole-setup.service -Before=systemd-udevd.service systemd-udev-trigger.service +Before=systemd-udevd.service systemd-udev-trigger.service shutdown.target emergency.target [Service] Environment=SHELL_PROMPT_PREFIX="pre-udev "