otherwise you will not be able to boot.
--no-compress Do not compress the generated initramfs. This will
override any other compression options.
+ --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
build.
--long zstd \
--long no-compress \
--long gzip \
+ --long enhanced-cpio \
--long list-modules \
--long show-modules \
--long keep \
--zstd) compress_l="zstd" ;;
--no-compress) _no_compress_l="cat" ;;
--gzip) compress_l="gzip" ;;
+ --enhanced-cpio) enhanced_cpio_l="yes" ;;
--list-modules) do_list="yes" ;;
-M | --show-modules)
show_modules_l="yes"
[[ $tmpdir ]] || tmpdir="$dracutsysrootdir"/var/tmp
[[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
[[ $compress_l ]] && compress=$compress_l
+[[ $enhanced_cpio_l ]] && enhanced_cpio=$enhanced_cpio_l
[[ $show_modules_l ]] && show_modules=$show_modules_l
[[ $nofscks_l ]] && nofscks="yes"
[[ $ro_mnt_l ]] && ro_mnt="yes"
exit 1
fi
+if [[ $enhanced_cpio == "yes" ]]; then
+ enhanced_cpio="$dracutbasedir/dracut-cpio"
+ if [[ -x $enhanced_cpio ]]; then
+ # align based on statfs optimal transfer size
+ cpio_align=$(stat --file-system -c "%s" -- "$initdir")
+ else
+ dinfo "--enhanced-cpio ignored due to lack of dracut-cpio"
+ unset enhanced_cpio
+ fi
+else
+ unset enhanced_cpio
+fi
+
# shellcheck disable=SC2154
if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
fi
if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
+ # stripping files negates (dedup) benefits of using reflink
+ [[ -n $enhanced_cpio ]] && ddebug "strip is enabled alongside cpio reflink"
dinfo "*** Stripping files ***"
find "$initdir" -type f \
-executable -not -path '*/lib/modules/*.ko' -print0 \
fi
# The microcode blob is _before_ the initramfs blob, not after
- if ! (
- umask 077
- cd "$early_cpio_dir/d"
- find . -print0 | sort -z \
- | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
- ${cpio_owner:+-R "$cpio_owner"} -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
- ); then
- dfatal "dracut: creation of $outfile failed"
- exit 1
+ if [[ -n $enhanced_cpio ]]; then
+ if ! (
+ umask 077
+ cd "$early_cpio_dir/d"
+ find . -print0 | sort -z \
+ | $enhanced_cpio --null ${cpio_owner:+--owner "$cpio_owner"} \
+ --mtime 0 --data-align "$cpio_align" --truncate-existing \
+ "${DRACUT_TMPDIR}/initramfs.img"
+ ); then
+ dfatal "dracut-cpio: creation of $outfile failed"
+ exit 1
+ fi
+ else
+ if ! (
+ umask 077
+ cd "$early_cpio_dir/d"
+ find . -print0 | sort -z \
+ | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
+ ${cpio_owner:+-R "$cpio_owner"} -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
+ ); then
+ dfatal "dracut: creation of $outfile failed"
+ exit 1
+ fi
fi
fi
compress="cat"
fi
-if ! (
- umask 077
- cd "$initdir"
- find . -print0 | sort -z \
- | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc -o --quiet \
- | $compress >> "${DRACUT_TMPDIR}/initramfs.img"
-); then
- dfatal "dracut: creation of $outfile failed"
- exit 1
+if [[ -n $enhanced_cpio ]]; then
+ if [[ $compress == "cat" ]]; then
+ # dracut-cpio appends by default, so any ucode remains
+ cpio_outfile="${DRACUT_TMPDIR}/initramfs.img"
+ else
+ ddebug "$compress compression enabled alongside cpio reflink"
+ # dracut-cpio doesn't output to stdout, so stage for compression
+ cpio_outfile="${DRACUT_TMPDIR}/initramfs.img.uncompressed"
+ fi
+
+ if ! (
+ umask 077
+ cd "$initdir"
+ find . -print0 | sort -z \
+ | $enhanced_cpio --null ${cpio_owner:+--owner "$cpio_owner"} \
+ --mtime 0 --data-align "$cpio_align" "$cpio_outfile" || exit 1
+ [[ $compress == "cat" ]] && exit 0
+ $compress < "$cpio_outfile" >> "${DRACUT_TMPDIR}/initramfs.img" \
+ && rm "$cpio_outfile"
+ ); then
+ dfatal "dracut-cpio: creation of $outfile failed"
+ exit 1
+ fi
+ unset cpio_outfile
+else
+ if ! (
+ umask 077
+ cd "$initdir"
+ find . -print0 | sort -z \
+ | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc -o --quiet \
+ | $compress >> "${DRACUT_TMPDIR}/initramfs.img"
+ ); then
+ dfatal "dracut: creation of $outfile failed"
+ exit 1
+ fi
fi
# shellcheck disable=SC2154