From 7de4a0d6c87375d6b980fce323e17e637296c0b0 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 10 Jan 2022 21:51:16 +0800 Subject: [PATCH] Set zstd as recommented for kexec-tools This patch will make zstd as recommended instead of required for kexec-tools. If zstd command/package is unavaliable, it can failback to invoke gzip when making kdump initramfs. Fixes: 0311f6e ("Set zstd as the default compression method for kdump initrd") Signed-off-by: Tao Liu Acked-by: Coiby Xu --- kdump-lib.sh | 5 +++++ kexec-tools.spec | 2 +- mkdumprd | 7 ++++++- mkfadumprd | 5 ++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 1db55fd..ca086d7 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -31,6 +31,11 @@ is_squash_available() done } +is_zstd_command_available() +{ + [[ -x "$(command -v zstd)" ]] +} + perror_exit() { derror "$@" diff --git a/kexec-tools.spec b/kexec-tools.spec index dffcce0..7419723 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -70,7 +70,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool -Requires: zstd +Recommends: zstd Recommends: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel diff --git a/mkdumprd b/mkdumprd index 9c26ecc..593ec77 100644 --- a/mkdumprd +++ b/mkdumprd @@ -432,7 +432,12 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target if ! have_compression_in_dracut_args; then - add_dracut_arg "--compress" "zstd" + # 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 diff --git a/mkfadumprd b/mkfadumprd index 16fdacc..86dfcee 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -62,8 +62,11 @@ if is_squash_available; then _dracut_isolate_args+=(--add squash) fi +# Same as setting zstd in mkdumprd if ! have_compression_in_dracut_args; then - _dracut_isolate_args+=(--compress zstd) + if is_squash_available || is_zstd_command_available; then + _dracut_isolate_args+=(--compress zstd) + fi fi if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then