@@ -226,6 +226,7 @@ Creates initial ramdisk images for preloading modules
226226 otherwise you will not be able to boot.
227227 --no-compress Do not compress the generated initramfs. This will
228228 override any other compression options.
229+ --cpio-reflink Attempt to reflink cpio file data using dracut-cpio.
229230 --list-modules List all available dracut modules.
230231 -M, --show-modules Print included module's name to standard output during
231232 build.
@@ -412,6 +413,7 @@ rearrange_params() {
412413 --long zstd \
413414 --long no-compress \
414415 --long gzip \
416+ --long cpio-reflink \
415417 --long list-modules \
416418 --long show-modules \
417419 --long keep \
@@ -770,6 +772,7 @@ while :; do
770772 --zstd) compress_l=" zstd" ;;
771773 --no-compress) _no_compress_l=" cat" ;;
772774 --gzip) compress_l=" gzip" ;;
775+ --cpio-reflink) cpio_reflink=" yes" ;;
773776 --list-modules) do_list=" yes" ;;
774777 -M | --show-modules)
775778 show_modules_l=" yes"
@@ -1151,6 +1154,17 @@ trap 'exit 1;' SIGINT
11511154readonly initdir=" ${DRACUT_TMPDIR} /initramfs"
11521155mkdir -p " $initdir "
11531156
1157+ if [[ $cpio_reflink == " yes" ]]; then
1158+ dracut_cpio=" $dracutbasedir /dracut-cpio"
1159+ if [[ -x $dracut_cpio ]]; then
1160+ # align based on statfs optimal transfer size
1161+ cpio_align=$( stat --file-system -c " %s" -- " $initdir " )
1162+ else
1163+ dinfo " cpio-reflink ignored due to lack of dracut-cpio"
1164+ unset cpio_reflink
1165+ fi
1166+ fi
1167+
11541168# shellcheck disable=SC2154
11551169if [[ $early_microcode == yes ]] || { [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
11561170 readonly early_cpio_dir=" ${DRACUT_TMPDIR} /earlycpio"
@@ -2252,6 +2266,8 @@ if dracut_module_included "squash"; then
22522266fi
22532267
22542268if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2269+ # warn that stripping files negates (dedup) benefits of using reflink
2270+ [ -n " $cpio_reflink " ] && dinfo " inefficient: strip is enabled alongside cpio reflink"
22552271 dinfo " *** Stripping files ***"
22562272 find " $initdir " -type f \
22572273 -executable -not -path ' */lib/modules/*.ko' -print0 \
@@ -2322,15 +2338,29 @@ if [[ $create_early_cpio == yes ]]; then
23222338 fi
23232339
23242340 # The microcode blob is _before_ the initramfs blob, not after
2325- if ! (
2326- umask 077
2327- cd " $early_cpio_dir /d"
2328- find . -print0 | sort -z \
2329- | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2330- ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet > " ${DRACUT_TMPDIR} /initramfs.img"
2331- ); then
2332- dfatal " dracut: creation of $outfile failed"
2333- exit 1
2341+ if [[ -n $cpio_reflink ]]; then
2342+ if ! (
2343+ umask 077
2344+ cd " $early_cpio_dir /d"
2345+ find . -print0 | sort -z \
2346+ | $dracut_cpio --null ${cpio_owner: +--owner " $cpio_owner " } \
2347+ --mtime 0 --data-align " $cpio_align " --truncate-existing \
2348+ " ${DRACUT_TMPDIR} /initramfs.img"
2349+ ); then
2350+ dfatal " dracut: creation of reflinked $outfile failed"
2351+ exit 1
2352+ fi
2353+ else
2354+ if ! (
2355+ umask 077
2356+ cd " $early_cpio_dir /d"
2357+ find . -print0 | sort -z \
2358+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2359+ ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet > " ${DRACUT_TMPDIR} /initramfs.img"
2360+ ); then
2361+ dfatal " dracut: creation of $outfile failed"
2362+ exit 1
2363+ fi
23342364 fi
23352365fi
23362366
@@ -2381,15 +2411,31 @@ case $compress in
23812411 ;;
23822412esac
23832413
2384- if ! (
2385- umask 077
2386- cd " $initdir "
2387- find . -print0 | sort -z \
2388- | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2389- | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2390- ); then
2391- dfatal " dracut: creation of $outfile failed"
2392- exit 1
2414+ if [[ -n $cpio_reflink && $compress == " cat" ]]; then
2415+ # dracut-cpio appends by default, so any ucode remains
2416+ if ! (
2417+ umask 077
2418+ cd " $initdir "
2419+ find . -print0 | sort -z \
2420+ | $dracut_cpio --null ${cpio_owner: +--owner " $cpio_owner " } \
2421+ --mtime 0 --data-align " $cpio_align " \
2422+ " ${DRACUT_TMPDIR} /initramfs.img"
2423+ ); then
2424+ dfatal " dracut: creation of reflinked $outfile failed"
2425+ exit 1
2426+ fi
2427+ else
2428+ [ -n " $cpio_reflink " ] && dinfo " cpio-reflink ignored due to compression"
2429+ if ! (
2430+ umask 077
2431+ cd " $initdir "
2432+ find . -print0 | sort -z \
2433+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2434+ | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2435+ ); then
2436+ dfatal " dracut: creation of $outfile failed"
2437+ exit 1
2438+ fi
23932439fi
23942440
23952441# shellcheck disable=SC2154
0 commit comments