[RESEND PATCH v2 1/4] update kernel crashkernel in posttrans RPM scriptlet when updating kexec-tools
by Coiby Xu
When doing in-place upgrading using leapp on x86_64, kdumpcl can't
acquire instance lock when running in %post RPM scriplet on x86_64,
localhost upgrade[1306]: /bin/kdumpctl: line 49: /var/lock/kdump: No such file or directory
localhost upgrade[1306]: kdump: Create file lock failed
and running "touch /var/lock/dkump" also fails with
"No such file or directory". Thus kdumpctl can't be run in %post
scriptlet. But kdumpctl can be run in %posttrans RPM scriplet.
Besides, it's better to update crashkernel after the kernel has been
updated. So let's update kernel crashkernel in the %posttrans
scriptlet which will be run in the end of a transaction i.e. after
the kernel has been updated.
Note for %posttrans scriptlet, "$1 == 1" means both installing a new
package and upgrading a package.
[1] https://github.com/apptainer/singularity/issues/2386#issuecomment-474747054
Reported-by: Jie Li <jieli(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kexec-tools.spec | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/kexec-tools.spec b/kexec-tools.spec
index ac134da..6b7ef14 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -305,19 +305,6 @@ then
mv /etc/sysconfig/kdump.new /etc/sysconfig/kdump
fi
-# try to reset kernel crashkernel value to new default value when upgrading
-# the package
-if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ]; then
- kdumpctl reset-crashkernel-after-update
- rm /tmp/old_default_crashkernel 2>/dev/null
-%ifarch ppc64 ppc64le
- rm /tmp/old_default_crashkernel_fadump 2>/dev/null
-%endif
- # dnf would complain about the exit code not being 0. To keep it happy,
- # always return 0
- :
-fi
-
%postun
%systemd_postun_with_restart kdump.service
@@ -350,6 +337,21 @@ do
fi
done
+%posttrans
+# try to reset kernel crashkernel value to new default value when upgrading
+# the package
+if ! grep -qs "ostree" /proc/cmdline && [ $1 == 1 ]; then
+ kdumpctl reset-crashkernel-after-update
+ rm /tmp/old_default_crashkernel 2>/dev/null
+%ifarch ppc64 ppc64le
+ rm /tmp/old_default_crashkernel_fadump 2>/dev/null
+%endif
+ # dnf would complain about the exit code not being 0. To keep it happy,
+ # always return 0
+ :
+fi
+
+
%files
/usr/sbin/kexec
%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64
--
2.34.1
2 years, 2 months
[PATCH v2] kdump-lib.sh: Check the output of blkid with sed instead of eval
by Tao Liu
Previously the output of blkid is not checked. If the output
is empty, the eval will report the following error message:
/lib/kdump/kdump-lib.sh: eval: line 925: syntax error near unexpected token `;'
/lib/kdump/kdump-lib.sh: eval: line 925: `; echo $TYPE'
For example, we can observe such a failing when blkid is invoked
against a lvm thinpool block device:
$ blkid -u filesystem,crypto -o export -- "/dev/block/253\:2"
$ echo $?
2
$ udevadm info /dev/block/253\:2|grep S\:
S: mapper/vg00-thinpoll_tmeta
In this patch, we will use sed instead of eval, to output the
fstype of block device if any.
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
kdump-lib.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 3e912cc..4ed5035 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -885,7 +885,8 @@ get_luks_crypt_dev()
[[ -b /dev/block/$1 ]] || return 1
- _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE")
+ _type=$(blkid -u filesystem,crypto -o export -- "/dev/block/$1" | \
+ sed -n -E "s/^TYPE=(.*)$/\1/p")
[[ $_type == "crypto_LUKS" ]] && echo "$1"
for _x in "/sys/dev/block/$1/slaves/"*; do
--
2.33.1
2 years, 2 months
[PATCH v2 1/3] simplify updating GRUB_CMDLINE_LINUX in GRUB_ETC_DEFAULT
by Coiby Xu
Use sed command group and conditional control to get rid of grep.
Suggested-by: Philipp Rudo <prudo(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdumpctl | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 9fd76ac..998ac6e 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1405,19 +1405,22 @@ GRUB_ETC_DEFAULT="/etc/default/grub"
# $2: new value. If empty, the parameter would be removed
_update_kernel_cmdline_in_grub_etc_default()
{
- local _para=$1 _val=$2 _para_val _regex
+ local _para=$1 _val=$2 _para_val
if [[ -n $_val ]]; then
_para_val="$_para=$_val"
fi
- _regex='^(GRUB_CMDLINE_LINUX=.*)([[:space:]"])'"$_para"'=[^[:space:]"]*(.*)$'
- if grep -q -E "$_regex" "$GRUB_ETC_DEFAULT"; then
- sed -i -E 's/'"$_regex"'/\1\2'"$_para_val"'\3/' "$GRUB_ETC_DEFAULT"
- elif [[ -n $_para_val ]]; then
- # If the kernel parameter doesn't exist, put it in the first
- sed -i -E 's/^(GRUB_CMDLINE_LINUX=")/\1'"$_para_val"' /' "$GRUB_ETC_DEFAULT"
- fi
+ # If the parameter already exists, replace it with new value.
+ # Otherwise insert it to the end.
+ sed -i -E "/^GRUB_CMDLINE_LINUX=/ {
+ s/([[:space:]\"])crashkernel=[^[:space:]\"]*(.*)$/\1${_para_val}\2/;
+ # t: jump to a label only if a s/// command has succeeded.
+ # Since there is no label, it would jump to the end i.e.
+ # skip the last command if the parameter already exist
+ t;
+ s/\"$/ ${_para_val}\"/
+ }" "$GRUB_ETC_DEFAULT"
}
reset_crashkernel()
--
2.34.1
2 years, 2 months
[PATCH] kdump-lib.sh: Check the output of blkid before eval
by Tao Liu
Previously the output of blkid is not checked. If the output
is empty, the eval will report the following error message:
/lib/kdump/kdump-lib.sh: eval: line 925: syntax error near unexpected token `;'
/lib/kdump/kdump-lib.sh: eval: line 925: `; echo $TYPE'
For example, we can observe such a failing when blkid is invoked
against a lvm thinpool block device:
$ blkid -u filesystem,crypto -o export -- "/dev/block/253\:2"
$ echo $?
2
$ udevadm info /dev/block/253\:2|grep S\:
S: mapper/vg00-thinpoll_tmeta
In this patch, we will first check whether the output of blkid is
empty, then decide if eval will be invoked later.
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
kdump-lib.sh | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 3e912cc..63e0b1f 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -881,12 +881,16 @@ kdump_get_arch_recommend_size()
# $1: the block device to be checked in maj:min format
get_luks_crypt_dev()
{
- local _type
+ local _type _blk_info
[[ -b /dev/block/$1 ]] || return 1
- _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE")
- [[ $_type == "crypto_LUKS" ]] && echo "$1"
+ _blk_info=$(blkid -u filesystem,crypto -o export -- "/dev/block/$1")
+
+ if [[ -n $_blk_info ]]; then
+ _type=$(eval "$_blk_info; echo \$TYPE")
+ [[ $_type == "crypto_LUKS" ]] && echo "$1"
+ fi
for _x in "/sys/dev/block/$1/slaves/"*; do
[[ -f $_x/dev ]] || continue
--
2.33.1
2 years, 2 months
[PATCH v2] Failback to default compression method if zstd fails
by Tao Liu
Previously if users have not specified the compress method for
kdump initramfs, "--compress zstd" will be appended to dracut cmdline.
It will make dracut to decide: a) if dracut module squash is added,
libzstd will be used, b) otherwise cmd zstd will be used. However in
kexec-tools we cannot guarantee dracut module squash is added, for
example users can set omit_dracutmodules in dracut.conf and etc, so
is_squash_available is not able to check is libzstd or cmd zstd
been used at runtime.
This patch will give "--compress zstd" a try first, if fails, it will
just proceed the default compression method, in order to avoid the
error prone zstd/libzstd dependence check.
Fixes: 7de4a0d ("Set zstd as recommented for kexec-tools")
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
v1 -> v2:
Modified the commit message
Notify user through ddebug if zstd-try fails, and redirect the error
message to ddebug as well.
---
kdump-lib.sh | 5 -----
mkdumprd | 23 ++++++++++++++---------
mkfadumprd | 9 +++++++--
3 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 2ea51be..6415dda 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -31,11 +31,6 @@ is_squash_available()
done
}
-is_zstd_command_available()
-{
- [[ -x "$(command -v zstd)" ]]
-}
-
perror_exit()
{
derror "$@"
diff --git a/mkdumprd b/mkdumprd
index 593ec77..0a81dc7 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -431,15 +431,6 @@ done <<< "$(kdump_read_conf)"
handle_default_dump_target
-if ! have_compression_in_dracut_args; then
- # Here zstd is set as the default compression method. If squash module
- # is available for dracut, libzstd will be used by mksquashfs. If
- # squash module is unavailable, command zstd will be used instead.
- if is_squash_available || is_zstd_command_available; then
- add_dracut_arg "--compress" "zstd"
- fi
-fi
-
if [[ -n $extra_modules ]]; then
add_dracut_arg "--add-drivers" "$extra_modules"
fi
@@ -457,6 +448,20 @@ if ! is_fadump_capable; then
add_dracut_arg "--no-hostonly-default-device"
fi
+if ! have_compression_in_dracut_args; then
+ # Here we will first try to compress in zstd, if fails we will proceed
+ # the default compress method.
+ dracut "${dracut_args[@]}" "--compress" "zstd" "$@" 2> >(ddebug)
+ _rc=$?
+
+ if [[ $_rc -eq 0 ]]; then
+ sync
+ exit $_rc
+ else
+ ddebug "Failback to default compress method"
+ fi
+fi
+
dracut "${dracut_args[@]}" "$@"
_rc=$?
diff --git a/mkfadumprd b/mkfadumprd
index 86dfcee..0d40975 100644
--- a/mkfadumprd
+++ b/mkfadumprd
@@ -64,8 +64,13 @@ fi
# Same as setting zstd in mkdumprd
if ! have_compression_in_dracut_args; then
- if is_squash_available || is_zstd_command_available; then
- _dracut_isolate_args+=(--compress zstd)
+ dracut --force --quiet "${_dracut_isolate_args[@]}" "--compress" "zstd" "$@" "$TARGET_INITRD" 2> >(ddebug)
+ _rc=$?
+
+ if [[ $_rc -eq 0 ]]; then
+ exit $_rc
+ else
+ ddebug "Failback to default compress method for fadump"
fi
fi
--
2.33.1
2 years, 2 months
[PATCH] fix incorrect usage of _get_all_kernels_from_grubby
by Coiby Xu
It's found that the kernel crashkernel doesn't get updated when in-place
upgrading from rhel8 to rhel9. This happens because _get_all_kernels_from_grubby
is called with no argument by reset_crashkernel_after_update. When retrieving all
kernel paths on the system, "grubby --info ALL" should be used. Fix this
error by passing "ALL" argument.
Fixes: 0adb0f4 ("try to reset kernel crashkernel when kexec-tools updates the default crashkernel value")
Reported-by: Jie Li <jieli(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdumpctl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kdumpctl b/kdumpctl
index bf74c75..9fd76ac 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1382,6 +1382,11 @@ _valid_grubby_kernel_path()
[[ -n "$1" ]] && grubby --info="$1" > /dev/null 2>&1
}
+# return all the kernel paths given a grubby kernel-path
+#
+# $1: kernel path accepted by grubby, e.g. DEFAULT, ALL,
+# /boot/vmlinuz-`uname -r`
+# return: kernel paths separated by space
_get_all_kernels_from_grubby()
{
local _kernels _line _kernel_path _grubby_kernel_path=$1
@@ -1557,7 +1562,7 @@ reset_crashkernel_after_update()
_crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump)
_crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump)
- for _kernel in $(_get_all_kernels_from_grubby); do
+ for _kernel in $(_get_all_kernels_from_grubby ALL); do
_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel)
if [[ $_crashkernel == auto ]]; then
reset_crashkernel "--kernel=$_kernel"
--
2.34.1
2 years, 2 months
[PATCH] fix the mistake of swapping function parameters of read_proc_environ_var
by Coiby Xu
_is_osbuild fails because it expects the 1st and 2nd function parameter
to be the environment variable and environ file path respectively. Fix
it by swapping the parameters in read_proc_environ_var.
Note the osbuild environ file path is defined in _OSBUILD_ENVIRON_PATH
so _is_osbuild can be unit-tested by overwriting _OSBUILD_ENVIRON_PATH.
Fixes: 6a3ce83 ("fix the error of parsing the container environ variable for osbuild")
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdumpctl | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 3ccfa97..bf74c75 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1580,15 +1580,19 @@ reset_crashkernel_after_update()
#
# The environment variable entries in /proc/[pid]/environ are separated
# by null bytes instead of by spaces.
+#
+# $1: environment variable
+# $2: environ file path
read_proc_environ_var()
{
- local _environ_path=$1 _var=$2
+ local _var=$1 _environ_path=$2
sed -n -E "s/.*(^|\x00)${_var}=([^\x00]*).*/\2/p" < "$_environ_path"
}
+_OSBUILD_ENVIRON_PATH='/proc/1/environ'
_is_osbuild()
{
- [[ $(read_proc_environ_var container /proc/1/environ) == bwrap-osbuild ]]
+ [[ $(read_proc_environ_var container "$_OSBUILD_ENVIRON_PATH") == bwrap-osbuild ]]
}
reset_crashkernel_for_installed_kernel()
--
2.34.1
2 years, 2 months