@@ -226,6 +226,7 @@ Creates initial ramdisk images for preloading modules
226
226
otherwise you will not be able to boot.
227
227
--no-compress Do not compress the generated initramfs. This will
228
228
override any other compression options.
229
+ --enhanced-cpio Attempt to reflink cpio file data using dracut-cpio.
229
230
--list-modules List all available dracut modules.
230
231
-M, --show-modules Print included module's name to standard output during
231
232
build.
@@ -412,6 +413,7 @@ rearrange_params() {
412
413
--long zstd \
413
414
--long no-compress \
414
415
--long gzip \
416
+ --long enhanced-cpio \
415
417
--long list-modules \
416
418
--long show-modules \
417
419
--long keep \
@@ -770,6 +772,7 @@ while :; do
770
772
--zstd) compress_l=" zstd" ;;
771
773
--no-compress) _no_compress_l=" cat" ;;
772
774
--gzip) compress_l=" gzip" ;;
775
+ --enhanced-cpio) enhanced_cpio_l=" yes" ;;
773
776
--list-modules) do_list=" yes" ;;
774
777
-M | --show-modules)
775
778
show_modules_l=" yes"
@@ -982,6 +985,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
982
985
[[ $tmpdir ]] || tmpdir=" $dracutsysrootdir " /var/tmp
983
986
[[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
984
987
[[ $compress_l ]] && compress=$compress_l
988
+ [[ $enhanced_cpio_l ]] && enhanced_cpio=$enhanced_cpio_l
985
989
[[ $show_modules_l ]] && show_modules=$show_modules_l
986
990
[[ $nofscks_l ]] && nofscks=" yes"
987
991
[[ $ro_mnt_l ]] && ro_mnt=" yes"
@@ -1188,6 +1192,19 @@ else
1188
1192
exit 1
1189
1193
fi
1190
1194
1195
+ if [[ $enhanced_cpio == " yes" ]]; then
1196
+ enhanced_cpio=" $dracutbasedir /dracut-cpio"
1197
+ if [[ -x $enhanced_cpio ]]; then
1198
+ # align based on statfs optimal transfer size
1199
+ cpio_align=$( stat --file-system -c " %s" -- " $initdir " )
1200
+ else
1201
+ dinfo " --enhanced-cpio ignored due to lack of dracut-cpio"
1202
+ unset enhanced_cpio
1203
+ fi
1204
+ else
1205
+ unset enhanced_cpio
1206
+ fi
1207
+
1191
1208
# shellcheck disable=SC2154
1192
1209
if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1193
1210
printf " %s\n" " dracut: Cannot find module directory $srcmods " >&2
@@ -2252,6 +2269,8 @@ if dracut_module_included "squash"; then
2252
2269
fi
2253
2270
2254
2271
if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2272
+ # stripping files negates (dedup) benefits of using reflink
2273
+ [[ -n $enhanced_cpio ]] && ddebug " strip is enabled alongside cpio reflink"
2255
2274
dinfo " *** Stripping files ***"
2256
2275
find " $initdir " -type f \
2257
2276
-executable -not -path ' */lib/modules/*.ko' -print0 \
@@ -2322,15 +2341,29 @@ if [[ $create_early_cpio == yes ]]; then
2322
2341
fi
2323
2342
2324
2343
# 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
2344
+ if [[ -n $enhanced_cpio ]]; then
2345
+ if ! (
2346
+ umask 077
2347
+ cd " $early_cpio_dir /d"
2348
+ find . -print0 | sort -z \
2349
+ | $enhanced_cpio --null ${cpio_owner: +--owner " $cpio_owner " } \
2350
+ --mtime 0 --data-align " $cpio_align " --truncate-existing \
2351
+ " ${DRACUT_TMPDIR} /initramfs.img"
2352
+ ); then
2353
+ dfatal " dracut-cpio: creation of $outfile failed"
2354
+ exit 1
2355
+ fi
2356
+ else
2357
+ if ! (
2358
+ umask 077
2359
+ cd " $early_cpio_dir /d"
2360
+ find . -print0 | sort -z \
2361
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2362
+ ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet > " ${DRACUT_TMPDIR} /initramfs.img"
2363
+ ); then
2364
+ dfatal " dracut: creation of $outfile failed"
2365
+ exit 1
2366
+ fi
2334
2367
fi
2335
2368
fi
2336
2369
@@ -2386,15 +2419,41 @@ if [[ $compress == $DRACUT_COMPRESS_ZSTD* ]] && ! check_kernel_config CONFIG_RD_
2386
2419
compress=" cat"
2387
2420
fi
2388
2421
2389
- if ! (
2390
- umask 077
2391
- cd " $initdir "
2392
- find . -print0 | sort -z \
2393
- | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2394
- | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2395
- ); then
2396
- dfatal " dracut: creation of $outfile failed"
2397
- exit 1
2422
+ if [[ -n $enhanced_cpio ]]; then
2423
+ if [[ $compress == " cat" ]]; then
2424
+ # dracut-cpio appends by default, so any ucode remains
2425
+ cpio_outfile=" ${DRACUT_TMPDIR} /initramfs.img"
2426
+ else
2427
+ ddebug " $compress compression enabled alongside cpio reflink"
2428
+ # dracut-cpio doesn't output to stdout, so stage for compression
2429
+ cpio_outfile=" ${DRACUT_TMPDIR} /initramfs.img.uncompressed"
2430
+ fi
2431
+
2432
+ if ! (
2433
+ umask 077
2434
+ cd " $initdir "
2435
+ find . -print0 | sort -z \
2436
+ | $enhanced_cpio --null ${cpio_owner: +--owner " $cpio_owner " } \
2437
+ --mtime 0 --data-align " $cpio_align " " $cpio_outfile " || exit 1
2438
+ [[ $compress == " cat" ]] && exit 0
2439
+ $compress < " $cpio_outfile " >> " ${DRACUT_TMPDIR} /initramfs.img" \
2440
+ && rm " $cpio_outfile "
2441
+ ); then
2442
+ dfatal " dracut-cpio: creation of $outfile failed"
2443
+ exit 1
2444
+ fi
2445
+ unset cpio_outfile
2446
+ else
2447
+ if ! (
2448
+ umask 077
2449
+ cd " $initdir "
2450
+ find . -print0 | sort -z \
2451
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2452
+ | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2453
+ ); then
2454
+ dfatal " dracut: creation of $outfile failed"
2455
+ exit 1
2456
+ fi
2398
2457
fi
2399
2458
2400
2459
# shellcheck disable=SC2154
0 commit comments