From 3b34804a552df4771c2f61cd96f3a49bd7c61a66 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 30 Aug 2021 22:00:53 +0200 Subject: [PATCH 1/2] fix: dracut: check reflink feature after loading dracut-init.sh dinfo() requires dracut-init.sh to be loaded. --- dracut.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dracut.sh b/dracut.sh index 092b7b426d..a88e13f855 100755 --- a/dracut.sh +++ b/dracut.sh @@ -1168,17 +1168,6 @@ trap 'exit 1;' SIGINT readonly initdir="${DRACUT_TMPDIR}/initramfs" mkdir -p "$initdir" -if [[ $cpio_reflink == "yes" ]]; then - dracut_cpio="$dracutbasedir/dracut-cpio" - if [[ -x $dracut_cpio ]]; then - # align based on statfs optimal transfer size - cpio_align=$(stat --file-system -c "%s" -- "$initdir") - else - dinfo "cpio-reflink ignored due to lack of dracut-cpio" - unset cpio_reflink - fi -fi - # shellcheck disable=SC2154 if [[ $early_microcode == yes ]] || { [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio" @@ -1216,6 +1205,17 @@ else exit 1 fi +if [[ $cpio_reflink == "yes" ]]; then + dracut_cpio="$dracutbasedir/dracut-cpio" + if [[ -x $dracut_cpio ]]; then + # align based on statfs optimal transfer size + cpio_align=$(stat --file-system -c "%s" -- "$initdir") + else + dinfo "cpio-reflink ignored due to lack of dracut-cpio" + unset cpio_reflink + fi +fi + # shellcheck disable=SC2154 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2 From ace2d78cde8df3c95b0a6c6e49c8ad74665f5a49 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 30 Aug 2021 21:26:26 +0200 Subject: [PATCH 2/2] feat: dracut: determine support for cpio-reflink The cpio-reflink feature requires certain features of the file system and system configuratino and is incompatible with certain other options. Make sure settings are consistent. --- dracut.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/dracut.sh b/dracut.sh index a88e13f855..d04e0dd4b1 100755 --- a/dracut.sh +++ b/dracut.sh @@ -1205,13 +1205,44 @@ else exit 1 fi -if [[ $cpio_reflink == "yes" ]]; then +is_reflink_supported() { dracut_cpio="$dracutbasedir/dracut-cpio" - if [[ -x $dracut_cpio ]]; then + [ -x $dracut_cpio ] || { + dinfo "cpio-reflink ignored due to lack of dracut-cpio" + return 1 + } + local fstype=$(find_mp_fstype $dracutsysrootdir/boot) + case $fstype in + xfs|btrfs) ;; + *) + dinfo "cpio-reflink is unsupported on $fstype" + return 1;; + esac + # reflinking doesn't work across mount points + if mountpoint -q $dracutsysrootdir/boot; then + dinfo "cpio-reflink ignored because /boot is a separate mountpoint" + return 1; + elif [[ $(stat -f -c %i $dracutsysrootdir/) != $(stat -f -c %i "$TMPDIR") ]]; then + dinfo "cpio-reflink ignored because tmpdir=\"$TMPDIR\" is on a separate file system" + return 1 + else + return 0 + fi +} + +if [[ $cpio_reflink == "yes" ]]; then + if [[ ! $compress_l && $do_strip_l != "yes" ]] && is_reflink_supported; then + if [[ $do_strip == "yes" ]]; then + dinfo "ignoring --strip because of cpio-reflink" + do_strip="no" + fi + if [[ $compress != "$DRACUT_COMPRESS_CAT" ]]; then + dinfo "setting compress=\"$DRACUT_COMPRESS_CAT\" because of cpio-reflink" + compress="$DRACUT_COMPRESS_CAT" + fi # align based on statfs optimal transfer size cpio_align=$(stat --file-system -c "%s" -- "$initdir") else - dinfo "cpio-reflink ignored due to lack of dracut-cpio" unset cpio_reflink fi fi