]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(squash): decouple the compressor for dracut and dracut-squash
authorTao Liu <ltao@redhat.com>
Mon, 14 Feb 2022 07:11:35 +0000 (15:11 +0800)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Tue, 22 Feb 2022 17:32:29 +0000 (17:32 +0000)
Previously dracut-squash module inherits the compressor
name from dracut, but actually the compressors are totally
different. For dracut, the compressor is zstd/gzip/lzop
cmdline tools, for dracut-squash, the compressor is the
libzstd/libz/liblzo libraries integrated by mksquashfs.

However mksquashfs support less compressors than dracut,
such as bzip2, which is not supported by mksquashfs, so
compressor decoupling seems to be a good idea to handle this.

This patch introduces a new dracut cmdline argument
--squash-compressor, by which the compressor and compressor
specific options can be passed to mksquashfs as
--squash-compressor "lzo -Xalgorithm lzo1x_1_15".

Signed-off-by: Tao Liu <ltao@redhat.com>
dracut.sh

index 0d67c9d41b30f29804b76f5252c5f4a443df36f2..0a3f59741ab92057ffd80fa952277a012f992106 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -228,6 +228,9 @@ Creates initial ramdisk images for preloading modules
                          otherwise you will not be able to boot.
   --no-compress         Do not compress the generated initramfs.  This will
                          override any other compression options.
+  --squash-compressor [COMPRESSION] Specify the compressor and compressor
+                         specific options used by mksquashfs if squash module
+                         is called when building the initramfs.
   --enhanced-cpio       Attempt to reflink cpio file data using dracut-cpio.
   --list-modules        List all available dracut modules.
   -M, --show-modules    Print included module's name to standard output during
@@ -373,6 +376,7 @@ rearrange_params() {
             --long sysroot: \
             --long stdlog: \
             --long compress: \
+            --long squash-compressor: \
             --long prefix: \
             --long rebuild: \
             --long force \
@@ -662,6 +666,11 @@ while :; do
             PARMS_TO_STORE+=" '$2'"
             shift
             ;;
+        --squash-compressor)
+            squash_compress_l="$2"
+            PARMS_TO_STORE+=" '$2'"
+            shift
+            ;;
         --prefix)
             prefix_l="$2"
             PARMS_TO_STORE+=" '$2'"
@@ -996,6 +1005,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $tmpdir ]] || tmpdir="$dracutsysrootdir"/var/tmp
 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
 [[ $compress_l ]] && compress=$compress_l
+[[ $squash_compress_l ]] && squash_compress=$squash_compress_l
 [[ $enhanced_cpio_l ]] && enhanced_cpio=$enhanced_cpio_l
 [[ $show_modules_l ]] && show_modules=$show_modules_l
 [[ $nofscks_l ]] && nofscks="yes"
@@ -2290,11 +2300,11 @@ if dracut_module_included "squash"; then
     dinfo "*** Squashing the files inside the initramfs ***"
     declare squash_compress_arg
     # shellcheck disable=SC2086
-    if [[ $compress ]]; then
-        if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $compress &> /dev/null; then
-            dwarn "mksquashfs doesn't support compressor '$compress', failing back to default compressor."
+    if [[ $squash_compress ]]; then
+        if ! mksquashfs /dev/null "$DRACUT_TMPDIR"/.squash-test.img -no-progress -comp $squash_compress &> /dev/null; then
+            dwarn "mksquashfs doesn't support compressor '$squash_compress', failing back to default compressor."
         else
-            squash_compress_arg="$compress"
+            squash_compress_arg="$squash_compress"
         fi
     fi