From fc136290bfe768eb7471e260bf6e63a3cf1f0f5c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 5 Jan 2022 11:53:22 +0800 Subject: [PATCH] set up kernel crashkernel for osbuild in kernel hook Resolves: bz1895258 Resolves: bz2024976 Upstream: Fedora Conflict: None commit ddd428a1d0d72bee2a8459b1a81541bcd0676873 Author: Coiby Xu Date: Wed Dec 15 21:45:18 2021 +0800 set up kernel crashkernel for osbuild in kernel hook osbuild is a tool to build OS images. It uses bwrap to install packages inside a sandbox/container. Since the kernel package recommends kexec-tools which in turn recommends grubby, the installation order would be grubby -> kexec-tools -> kernel. So we can use the kernel hook 92-crashkernel.install provided by kexec-tools to set up kernel crashkernel for the target OS image. But in osbuild's case, there is no current running kernel and running `uname -r` in the container/sandbox actually returns the host kernel release. To set up kernel crashkernel for the OS image built by osbuild, a different logic is needed. We will check if kernel hook is running inside the osbuild container then set up kernel crashkernel only if osbuild hasn't specified a custome value. osbuild exposes [1] the container=bwrap-osbuild environment variable. According to [2], the environment variable is not inherited down the process tree, so we need to check /proc/1/environ to detect this environment variable to tell if the kernel hook is running inside a bwrap-osbuild container. After that we need to know if osbuild wants to use custom crashkernel value. This is done by checking if /etc/kernel/cmdline has crashkernel set [3]. /etc/kernel/cmdline is written before packages are installed. [1] https://github.com/osbuild/osbuild/pull/926 [2] https://systemd.io/CONTAINER_INTERFACE/ [3] https://bugzilla.redhat.com/show_bug.cgi?id=2024976#c5 Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu Signed-off-by: Coiby Xu --- kdumpctl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kdumpctl b/kdumpctl index 9bb831a..6e243a8 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1602,6 +1602,11 @@ reset_crashkernel_after_update() done } +_is_osbuild() +{ + [[ $(sed -n -E 's/.*(^|\s)container=(\S*).*/\2/p' < /proc/1/environ) == bwrap-osbuild ]] +} + reset_crashkernel_for_installed_kernel() { local _installed_kernel _running_kernel _crashkernel _crashkernel_running @@ -1611,6 +1616,11 @@ reset_crashkernel_for_installed_kernel() exit 1 fi + if _is_osbuild && ! grep -q crashkernel= /etc/kernel/cmdline; then + reset_crashkernel "--kernel=$_installed_kernel" + return + fi + if ! _running_kernel=$(_get_current_running_kernel_path); then derror "Couldn't find current running kernel" exit