On Tue, Dec 28, 2021 at 08:49:23AM +0800, Coiby Xu wrote:
grubby --info=kernel-path or --add-kernel=kernel-path accepts a kernel path (e.g. /boot/vmlinuz-5.14.14-200.fc34.x86_64) instead of kernel release (e.g 5.14.14-200.fc34.x86_64). So we need to know the kernel path given a kernel release. Although for Fedora/RHEL, the kernel path is "/boot/vmlinuz-<KERNEL_RELEASE>", a path kernel could also be /boot/<machine-id>/<KERNEL_RELEASE>/vmlinuz. So the most reliable way to find the kernel path given a kernel release is to use "grubby --info".
For osbuild, a kernel path may not yet exist but it's valid for "grubby --update-kernel=KERNEL_PATH". For example, "grubby -info" may output something as follows,
index=0 kernel="/var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/vmlinuz-5.15.10-100.fc34.x86_64" args="ro no_timer_check net.ifnames=0 console=tty1 console=ttyS0,115200n8" root="UUID=76a22bf4-f153-4541-b6c7-0332c0dfaeac" initrd="/var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/initramfs-5.15.10-100.fc34.x86_64.img"
There is no need to check if path like /var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/vmlinuz-5.15.10-100.fc34.x86_64 physically exists.
Note these helper functions doesn't support CoreOS/Atomic/Silverblue since grubby isn't used by them.
Out of the topic, what is the boot loader on them?
For this patch, Reviewed-by: Pingfan Liu piliu@redhat.com
Signed-off-by: Coiby Xu coxu@redhat.com
kdumpctl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/kdumpctl b/kdumpctl index 7eb8e9d3..ea6f481b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1351,6 +1351,36 @@ get_dump_mode_by_kernel() fi }
+_filter_grubby_kernel_str() +{
- local _grubby_kernel_str=$1
- echo -n "$_grubby_kernel_str" | sed -n -e 's/^kernel="(.*)"/\1/p'
+}
+_find_kernel_path_by_release() +{
- local _release="$1" _grubby_kernel_str _kernel_path
- _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release")
- _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str")
- if [[ -z $_kernel_path ]]; then
derror "kernel $_release doesn't exist"
return 1
- fi
- echo -n "$_kernel_path"
+}
+_get_current_running_kernel_path() +{
- local _release _path
- _release=$(uname -r)
- if _path=$(_find_kernel_path_by_release "$_release"); then
echo -n "$_path"
- else
return 1
- fi
+}
reset_crashkernel() { local kernel=$1 entry crashkernel_default -- 2.31.1