From dc4e6b964c462a3d57a96a32462170d557723eb3 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Thu, 19 Jan 2023 10:47:43 -0300 Subject: [PATCH] initramfs/dracut: Enable zstd compression for kernels 5.9+ Way fast to compress/decompress and produce smaller archives (compared to deflate/gzip in general), but only supported in kernels 5.9+. Notice we fallback to the default "--compress=gzip" in case kernel does not support zstd. Special thanks to Clayton (craftyguy) for the kernel version test. Signed-off-by: Guilherme G. Piccoli --- initramfs/dracut/dracut-common.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/initramfs/dracut/dracut-common.sh b/initramfs/dracut/dracut-common.sh index 72e78af..03996d5 100644 --- a/initramfs/dracut/dracut-common.sh +++ b/initramfs/dracut/dracut-common.sh @@ -8,7 +8,16 @@ create_initramfs_dracut() { rm -f "${MOUNT_FOLDER}/kdump-initrd-$1.img" - DRACUT_NO_XATTR=1 dracut --no-early-microcode --host-only -q -m\ + COMPRESS="--compress=gzip" + MAJOR="$(echo "$1" | cut -f1 -d\.)" + MINOR="$(echo "$1" | cut -f2 -d\.)" + + # Zstd is FAST, but only supported in kernels 5.9+. + if [ "${MAJOR}" -gt 5 ] || ([ "${MAJOR}" -eq 5 ] && [ "${MINOR}" -ge 9 ]); then + COMPRESS="--compress=zstd" + fi + + DRACUT_NO_XATTR=1 dracut "${COMPRESS}" --no-early-microcode --host-only -q -m\ "bash systemd systemd-initrd systemd-sysusers modsign dbus-daemon kdump dbus udev-rules dracut-systemd base fs-lib shutdown"\ --kver "$1" "${MOUNT_FOLDER}/kdump-initrd-$1.img"