Skip to content

Commit

Permalink
refactor: delay compressor detection
Browse files Browse the repository at this point in the history
No function change, decide which compressor to use right before
compressing the initramfs.

This may delay the print of this message:
"dracut: no compression tool available. Initramfs image is going to be big."
but should be OK, this message is not an error.
  • Loading branch information
ryncsn authored and johannbg committed Mar 9, 2021
1 parent 90f269f commit a9345f6
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -905,53 +905,6 @@ if [[ $_no_compress_l = "$DRACUT_COMPRESS_CAT" ]]; then
compress="$DRACUT_COMPRESS_CAT"
fi
if ! [[ $compress ]]; then
# check all known compressors, if none specified
for i in $DRACUT_COMPRESS_PIGZ $DRACUT_COMPRESS_GZIP $DRACUT_COMPRESS_LZ4 $DRACUT_COMPRESS_LZOP $ $DRACUT_COMPRESS_ZSTD $DRACUT_COMPRESS_LZMA $DRACUT_COMPRESS_XZ $DRACUT_COMPRESS_LBZIP2 $OMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
command -v "$i" &>/dev/null || continue
compress="$i"
break
done
if [[ $compress = cat ]]; then
printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
fi
fi
# choose the right arguments for the compressor
case $compress in
bzip2|lbzip2)
if [[ "$compress" = lbzip2 ]] || command -v "$DRACUT_COMPRESS_LBZIP2" &>/dev/null; then
compress="$DRACUT_COMPRESS_LBZIP2 -9"
else
compress="$DRACUT_COMPRESS_BZIP2 -9"
fi
;;
lzma)
compress="$DRACUT_COMPRESS_LZMA -9 -T0"
;;
xz)
compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
;;
gzip|pigz)
if [[ "$compress" = pigz ]] || command -v "$DRACUT_COMPRESS_PIGZ" &>/dev/null; then
compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
elif command -v gzip &>/dev/null && $DRACUT_COMPRESS_GZIP --help 2>&1 | grep -q rsyncable; then
compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
else
compress="$DRACUT_COMPRESS_GZIP -n -9"
fi
;;
lzo|lzop)
compress="$DRACUT_COMPRESS_LZOP -9"
;;
lz4)
compress="$DRACUT_COMPRESS_LZ4 -l -9"
;;
zstd)
compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
;;
esac
[[ $hostonly = yes ]] && hostonly="-h"
[[ $hostonly != "-h" ]] && unset hostonly
Expand Down Expand Up @@ -2132,6 +2085,53 @@ if [[ $create_early_cpio = yes ]]; then
fi
fi
if ! [[ $compress ]]; then
# check all known compressors, if none specified
for i in $DRACUT_COMPRESS_PIGZ $DRACUT_COMPRESS_GZIP $DRACUT_COMPRESS_LZ4 $DRACUT_COMPRESS_LZOP $ $DRACUT_COMPRESS_ZSTD $DRACUT_COMPRESS_LZMA $DRACUT_COMPRESS_XZ $DRACUT_COMPRESS_LBZIP2 $OMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
command -v "$i" &>/dev/null || continue
compress="$i"
break
done
if [[ $compress = cat ]]; then
printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
fi
fi
# choose the right arguments for the compressor
case $compress in
bzip2|lbzip2)
if [[ "$compress" = lbzip2 ]] || command -v "$DRACUT_COMPRESS_LBZIP2" &>/dev/null; then
compress="$DRACUT_COMPRESS_LBZIP2 -9"
else
compress="$DRACUT_COMPRESS_BZIP2 -9"
fi
;;
lzma)
compress="$DRACUT_COMPRESS_LZMA -9 -T0"
;;
xz)
compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
;;
gzip|pigz)
if [[ "$compress" = pigz ]] || command -v "$DRACUT_COMPRESS_PIGZ" &>/dev/null; then
compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
elif command -v gzip &>/dev/null && $DRACUT_COMPRESS_GZIP --help 2>&1 | grep -q rsyncable; then
compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
else
compress="$DRACUT_COMPRESS_GZIP -n -9"
fi
;;
lzo|lzop)
compress="$DRACUT_COMPRESS_LZOP -9"
;;
lz4)
compress="$DRACUT_COMPRESS_LZ4 -l -9"
;;
zstd)
compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
;;
esac
if ! (
umask 077; cd "$initdir"
find . -print0 | sort -z \
Expand Down

0 comments on commit a9345f6

Please sign in to comment.