add helper functions to get kernel path by kernel release and the path of current running kernel
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. Reviewed-by: Pingfan Liu <piliu@redhat.com> Reviewed-by: Philipp Rudo <prudo@redhat.com> Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
parent
3d2079c31c
commit
945cbbd59b
30
kdumpctl
30
kdumpctl
@ -1325,6 +1325,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
|
||||
|
Loading…
Reference in New Issue
Block a user