set up kernel crashkernel for osbuild in kernel hook

Resolves: bz1895258
Resolves: bz2024976
Upstream: Fedora
Conflict: None

commit ddd428a1d0
Author: Coiby Xu <coxu@redhat.com>
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 <piliu@redhat.com>
    Reviewed-by: Philipp Rudo <prudo@redhat.com>
    Signed-off-by: Coiby Xu <coxu@redhat.com>

Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Coiby Xu 2022-01-05 11:53:22 +08:00 committed by Tao Liu
parent 2589c40c4e
commit fc136290bf
1 changed files with 10 additions and 0 deletions

View File

@ -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