@@ -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
+ --cpio-reflink 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 cpio-reflink \
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
+ --cpio-reflink) cpio_reflink=" yes" ;;
773
776
--list-modules) do_list=" yes" ;;
774
777
-M | --show-modules)
775
778
show_modules_l=" yes"
@@ -1151,6 +1154,17 @@ trap 'exit 1;' SIGINT
1151
1154
readonly initdir=" ${DRACUT_TMPDIR} /initramfs"
1152
1155
mkdir -p " $initdir "
1153
1156
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
+
1154
1168
# shellcheck disable=SC2154
1155
1169
if [[ $early_microcode == yes ]] || { [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
1156
1170
readonly early_cpio_dir=" ${DRACUT_TMPDIR} /earlycpio"
@@ -2252,6 +2266,8 @@ if dracut_module_included "squash"; then
2252
2266
fi
2253
2267
2254
2268
if [[ $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"
2255
2271
dinfo " *** Stripping files ***"
2256
2272
find " $initdir " -type f \
2257
2273
-executable -not -path ' */lib/modules/*.ko' -print0 \
@@ -2322,15 +2338,29 @@ if [[ $create_early_cpio == yes ]]; then
2322
2338
fi
2323
2339
2324
2340
# 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
2334
2364
fi
2335
2365
fi
2336
2366
@@ -2381,15 +2411,31 @@ case $compress in
2381
2411
;;
2382
2412
esac
2383
2413
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
2393
2439
fi
2394
2440
2395
2441
# shellcheck disable=SC2154
0 commit comments