kdump-lib: attempt to fix BOOT_IMAGE detection

Resolves: bz2174836
Upstream: Fedora
Conflict: None

commit f9c32372d2
Author: Dusty Mabe <dusty@dustymabe.com>
Date:   Wed Jun 22 12:34:12 2022 -0400

    kdump-lib: attempt to fix BOOT_IMAGE detection

    Currently $boot_img can get bad data if running on a platform
    that doesn't set BOOT_IMAGE in the kernel command line. For
    example, currently:

    - s390x Fedora CoreOS machine:

    ```
    [root@cosa-devsh ~]# sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline
    mitigations=auto,nosmt ignition.platform.id=qemu ostree=/ostree/boot.0/fedora-coreos/2a72567ac8f7ed678c3ac89408f795e6ccd4e97b41e14af5f471b6a807e858b9/0 root=UUID=2a88436a-3b6b-4706-b33a-b8270bd87cde rw rootflags=prjquota boot=UUID=f4b2eaa5-9317-4798-85cf-308c477fee4c crashkernel=600M
    ```

    where on a platform that uses GRUB we get:

    - x86_64 Fedora CoreOS machine:

    ```
    [root@cosa-devsh ~]# sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline
    /ostree/fedora-coreos-af4f6cc7b9ff486cfa647680b180e989c72c8eed03a34a42e7328e49332bd20e/vmlinuz-5.18.5-200.fc36.x86_64
    ```

    We should change the setting of the boot_img variable such that it will
    be empty if BOOT_IMAGE doesn't exist.

    With this change on the s390x machine:

    ```
    [root@cosa-devsh ~]# grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/"
    [root@cosa-devsh ~]#
    ```

    This change mattered much more before the change in c5bdd2d which changed
    the following line from [[ -n $boot_img ]] to [[ "$boot_img" == *"$kdump_kernelver" ]].
    Still I think this change has merit.

    Signed-off-by: Dusty Mabe <dusty@dustymabe.com>
    Acked-by: Coiby Xu <coxu@redhat.com>

Signed-off-by: Lichen Liu <lichliu@redhat.com>
This commit is contained in:
Lichen Liu 2023-03-07 10:38:13 +08:00
parent 0cecfa7d45
commit 1eb996d08f

View File

@ -650,7 +650,7 @@ prepare_kdump_kernel()
boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT $machine_id/$kdump_kernelver/$KDUMP_IMG"
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format
boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)"
boot_img="$(grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/")"
if [[ "$boot_img" == *"$kdump_kernelver" ]]; then
boot_imglist="$boot_img $boot_imglist"
fi