From ad794fcc9c8e24592f1cca2580ff73b0b115900f Mon Sep 17 00:00:00 2001
From: Anakin Zhang <benjamin93@163.com>
Date: Tue, 17 Jan 2023 14:34:40 +0800
Subject: [PATCH] add option to include file metadata in initramfs

Signed-off-by: Anakin Zhang <benjamin93@163.com>
---
 dracut.sh | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/dracut.sh b/dracut.sh
index bbb3469..d708cbf 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -277,6 +277,9 @@ Creates initial ramdisk images for preloading modules
   -p, --parallel        Use parallel processing if possible (currently only
                         supported --regenerate-all)
                         images simultaneously.
+  -e, --file-metadata [TYPE]
+                        Include file metadata in the initramfs. Specify "xattr"
+                        to include file extended attributes.
   --version             Display version.
 
 If [LIST] has multiple arguments, then you have to put these in quotes.
@@ -372,7 +375,7 @@ rearrange_params() {
     TEMP=$(
         unset POSIXLY_CORRECT
         getopt \
-            -o "a:m:o:d:I:k:c:r:L:fvqlHhMNp" \
+            -o "a:m:o:d:I:k:c:r:L:fvqlHhMNpe:" \
             --long kver: \
             --long add: \
             --long force-add: \
@@ -467,6 +470,7 @@ rearrange_params() {
             --long hostonly-i18n \
             --long hostonly-nics: \
             --long no-machineid \
+            --long file-metadata: \
             --long version \
             -- "$@"
     )
@@ -843,6 +847,11 @@ while :; do
         --no-machineid)
             machine_id_l="no"
             ;;
+        -e | --file-metadata)
+            file_metadata_l="$2";
+            PARMS_TO_STORE+=" '$2'"
+            shift
+            ;;
         --version)
             long_version
             exit 1
@@ -1079,6 +1088,7 @@ drivers_dir="${drivers_dir%%+(/)}"
 [[ $uefi_splash_image_l ]] && uefi_splash_image="$uefi_splash_image_l"
 [[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
 [[ $machine_id_l ]] && machine_id="$machine_id_l"
+[[ $file_metadata_l ]] && file_metadata_opt="-e $file_metadata_l"
 
 if ! [[ $outfile ]]; then
     if [[ $machine_id != "no" ]]; then
@@ -2479,7 +2489,7 @@ if [[ $create_early_cpio == yes ]]; then
             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"
+                    ${cpio_owner:+-R "$cpio_owner"} -H newc $file_metadata_opt -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
         ); then
             dfatal "Creation of $outfile failed"
             exit 1
@@ -2584,7 +2594,7 @@ else
         umask 077
         cd "$initdir"
         find . -print0 | sort -z \
-            | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc -o --quiet \
+            | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc $file_metadata_opt -o --quiet \
             | $compress >> "${DRACUT_TMPDIR}/initramfs.img"
     ); then
         dfatal "Creation of $outfile failed"
-- 
2.33.0