@@ -228,6 +228,7 @@ Creates initial ramdisk images for preloading modules
228
228
otherwise you will not be able to boot.
229
229
--no-compress Do not compress the generated initramfs. This will
230
230
override any other compression options.
231
+ --cpio-reflink Request that cpio perform reflinks for file data.
231
232
--list-modules List all available dracut modules.
232
233
-M, --show-modules Print included module's name to standard output during
233
234
build.
@@ -414,6 +415,7 @@ rearrange_params() {
414
415
--long zstd \
415
416
--long no-compress \
416
417
--long gzip \
418
+ --long cpio-reflink \
417
419
--long list-modules \
418
420
--long show-modules \
419
421
--long keep \
@@ -772,6 +774,7 @@ while :; do
772
774
--zstd) compress_l=" zstd" ;;
773
775
--no-compress) _no_compress_l=" cat" ;;
774
776
--gzip) compress_l=" gzip" ;;
777
+ --cpio-reflink) cpio_reflink=" yes" ;;
775
778
--list-modules) do_list=" yes" ;;
776
779
-M | --show-modules)
777
780
show_modules_l=" yes"
@@ -1147,6 +1150,28 @@ trap 'exit 1;' SIGINT
1147
1150
readonly initdir=" ${DRACUT_TMPDIR} /initramfs"
1148
1151
mkdir -p " $initdir "
1149
1152
1153
+ if [[ $cpio_reflink == " yes" ]]; then
1154
+ if [[ " $( cpio --help) " == * --reflink* ]]; then
1155
+ # both XFS and Btrfs require data to be FS block-size aligned for proper
1156
+ # extent sharing / reflinks. padcpio ensures this.
1157
+ if [[ -d " $dracutbasedir /skipcpio" ]]; then
1158
+ padcpio=" $dracutbasedir /skipcpio/padcpio"
1159
+ else
1160
+ padcpio=" $dracutbasedir /padcpio"
1161
+ fi
1162
+ if [[ -x " $padcpio " ]]; then
1163
+ # align based on statfs optimal transfer size
1164
+ padcpio_align=$( stat --file-system -c " %s" -- " $initdir " )
1165
+ else
1166
+ dinfo " cpio-reflink ignored due to lack of padcpio"
1167
+ unset cpio_reflink
1168
+ fi
1169
+ else
1170
+ dinfo " cpio-reflink ignored due to lack of support in $( which cpio) "
1171
+ unset cpio_reflink
1172
+ fi
1173
+ fi
1174
+
1150
1175
# shellcheck disable=SC2154
1151
1176
if [[ $early_microcode == yes ]] || { [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
1152
1177
readonly early_cpio_dir=" ${DRACUT_TMPDIR} /earlycpio"
@@ -2196,6 +2221,8 @@ if dracut_module_included "squash"; then
2196
2221
fi
2197
2222
2198
2223
if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2224
+ # warn that stripping files negates (dedup) benefits of using reflink
2225
+ [ -n " $cpio_reflink " ] && dinfo " inefficient: strip is enabled alongside cpio reflink"
2199
2226
dinfo " *** Stripping files ***"
2200
2227
find " $initdir " -type f \
2201
2228
-executable -not -path ' */lib/modules/*.ko' -print0 \
@@ -2266,15 +2293,28 @@ if [[ $create_early_cpio == yes ]]; then
2266
2293
fi
2267
2294
2268
2295
# The microcode blob is _before_ the initramfs blob, not after
2269
- if ! (
2270
- umask 077
2271
- cd " $early_cpio_dir /d"
2272
- find . -print0 | sort -z \
2273
- | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2274
- ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet > " ${DRACUT_TMPDIR} /initramfs.img"
2275
- ); then
2276
- dfatal " dracut: creation of $outfile failed"
2277
- exit 1
2296
+ if [[ -n " $cpio_reflink " ]]; then
2297
+ if ! (
2298
+ umask 077
2299
+ cd " $early_cpio_dir /d"
2300
+ find . -print0 | sort -z | " $padcpio " --min " $padcpio_align " --align " $padcpio_align " \
2301
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2302
+ ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet --reflink -O " ${DRACUT_TMPDIR} /initramfs.img"
2303
+ ); then
2304
+ dfatal " dracut: creation of reflinked $outfile failed"
2305
+ exit 1
2306
+ fi
2307
+ else
2308
+ if ! (
2309
+ umask 077
2310
+ cd " $early_cpio_dir /d"
2311
+ find . -print0 | sort -z \
2312
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2313
+ ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet > " ${DRACUT_TMPDIR} /initramfs.img"
2314
+ ); then
2315
+ dfatal " dracut: creation of $outfile failed"
2316
+ exit 1
2317
+ fi
2278
2318
fi
2279
2319
fi
2280
2320
@@ -2325,15 +2365,33 @@ case $compress in
2325
2365
;;
2326
2366
esac
2327
2367
2328
- if ! (
2329
- umask 077
2330
- cd " $initdir "
2331
- find . -print0 | sort -z \
2332
- | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2333
- | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2334
- ); then
2335
- dfatal " dracut: creation of $outfile failed"
2336
- exit 1
2368
+ if [[ -n " $cpio_reflink " && " $compress " == " cat" ]]; then
2369
+ # determine padding offset if we're appending to microcode
2370
+ i=$( stat -c " %s" -- " ${DRACUT_TMPDIR} /initramfs.img" 2> /dev/null)
2371
+ if ! (
2372
+ umask 077
2373
+ cd " $initdir "
2374
+ find . -print0 | sort -z \
2375
+ | " $padcpio " --min " $padcpio_align " --align " $padcpio_align " ${i: +--offset " $i " } \
2376
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null \
2377
+ ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet --reflink ${i: +--chain} \
2378
+ -O " ${DRACUT_TMPDIR} /initramfs.img"
2379
+ ); then
2380
+ dfatal " dracut: creation of reflinked $outfile failed"
2381
+ exit 1
2382
+ fi
2383
+ else
2384
+ [ -n " $cpio_reflink " ] && dinfo " cpio-reflink ignored due to compression"
2385
+ if ! (
2386
+ umask 077
2387
+ cd " $initdir "
2388
+ find . -print0 | sort -z \
2389
+ | cpio ${CPIO_REPRODUCIBLE: +--reproducible} --null ${cpio_owner: +-R " $cpio_owner " } -H newc -o --quiet \
2390
+ | $compress >> " ${DRACUT_TMPDIR} /initramfs.img"
2391
+ ); then
2392
+ dfatal " dracut: creation of $outfile failed"
2393
+ exit 1
2394
+ fi
2337
2395
fi
2338
2396
2339
2397
# shellcheck disable=SC2154
0 commit comments