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 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
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdumpctl | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kdumpctl b/kdumpctl
index 2979e1d..5249244 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1564,6 +1564,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
@@ -1573,6 +1578,11 @@ reset_crashkernel_for_installed_kernel()
exit 1
fi
+ if _is_osbuild && ! grep crashkernel= /etc/kernel/cmdline &> /dev/null ;
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
--
2.31.1