From 48c298a2eae7602a9b71877db12175ca1f3d60df Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Thu, 25 Jan 2024 16:07:16 +0100 Subject: [PATCH] fix(dracut.sh): use `$BOOT` to set the `outfile` path Use the new functions `get_dollar_boot`, `get_machine_id` and `get_default_initramfs_image` to get the `outfile` path. Fixes #1995 --- dracut.sh | 112 +++++++++++++++++------------------------------------- 1 file changed, 35 insertions(+), 77 deletions(-) diff --git a/dracut.sh b/dracut.sh index 3b292910f3..f43e84f377 100755 --- a/dracut.sh +++ b/dracut.sh @@ -1092,83 +1092,6 @@ drivers_dir="${drivers_dir%"${drivers_dir##*[!/]}"}" [[ $sbat_l ]] && sbat="$sbat_l" [[ $machine_id_l ]] && machine_id="$machine_id_l" -if ! [[ $outfile ]]; then - if [[ $machine_id != "no" ]]; then - if [[ -d "$dracutsysrootdir"/efi/Default ]] \ - || [[ -d "$dracutsysrootdir"/boot/Default ]] \ - || [[ -d "$dracutsysrootdir"/boot/efi/Default ]]; then - MACHINE_ID="Default" - elif [[ -s "$dracutsysrootdir"/etc/machine-id ]]; then - read -r MACHINE_ID < "$dracutsysrootdir"/etc/machine-id - [[ $MACHINE_ID == "uninitialized" ]] && MACHINE_ID="Default" - else - MACHINE_ID="Default" - fi - fi - - if [[ $uefi == "yes" ]]; then - if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] || [[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then - printf "%s\n" "dracut[F]: Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set." >&2 - exit 1 - fi - - if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign &> /dev/null; then - printf "%s\n" "dracut[F]: Need 'sbsign' to create a signed UEFI executable." >&2 - exit 1 - fi - - BUILD_ID=$(cat "$dracutsysrootdir"/etc/os-release "$dracutsysrootdir"/usr/lib/os-release \ - | while read -r line || [[ $line ]]; do - [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break - done) - if [[ -z $dracutsysrootdir ]]; then - if [[ -d /efi ]] && mountpoint -q /efi; then - efidir=/efi/EFI - else - efidir=/boot/EFI - if [[ -d /boot/efi/EFI ]]; then - efidir=/boot/efi/EFI - fi - fi - else - efidir=/boot/EFI - if [[ -d $dracutsysrootdir/boot/efi/EFI ]]; then - efidir=/boot/efi/EFI - fi - fi - mkdir -p "$dracutsysrootdir$efidir/Linux" - outfile="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi" - else - if [[ -d "$dracutsysrootdir"/efi/loader/entries || -L "$dracutsysrootdir"/efi/loader/entries ]] \ - && [[ $MACHINE_ID ]] \ - && [[ -d "$dracutsysrootdir"/efi/${MACHINE_ID} || -L "$dracutsysrootdir"/efi/${MACHINE_ID} ]]; then - outfile="$dracutsysrootdir/efi/${MACHINE_ID}/${kernel}/initrd" - elif [[ -d "$dracutsysrootdir"/boot/loader/entries || -L "$dracutsysrootdir"/boot/loader/entries ]] \ - && [[ $MACHINE_ID ]] \ - && [[ -d "$dracutsysrootdir"/boot/${MACHINE_ID} || -L "$dracutsysrootdir"/boot/${MACHINE_ID} ]]; then - outfile="$dracutsysrootdir/boot/${MACHINE_ID}/${kernel}/initrd" - elif [[ -d "$dracutsysrootdir"/boot/efi/loader/entries || -L "$dracutsysrootdir"/boot/efi/loader/entries ]] \ - && [[ $MACHINE_ID ]] \ - && [[ -d "$dracutsysrootdir"/boot/efi/${MACHINE_ID} || -L "$dracutsysrootdir"/boot/efi/${MACHINE_ID} ]]; then - outfile="$dracutsysrootdir/boot/efi/${MACHINE_ID}/${kernel}/initrd" - elif [[ -f "$dracutsysrootdir"/lib/modules/${kernel}/initrd ]]; then - outfile="$dracutsysrootdir/lib/modules/${kernel}/initrd" - elif [[ -e $dracutsysrootdir/boot/vmlinuz-${kernel} ]]; then - outfile="$dracutsysrootdir/boot/initramfs-${kernel}.img" - elif [[ -z $dracutsysrootdir ]] \ - && [[ $MACHINE_ID ]] \ - && mountpoint -q /efi; then - outfile="/efi/${MACHINE_ID}/${kernel}/initrd" - elif [[ -z $dracutsysrootdir ]] \ - && [[ $MACHINE_ID ]] \ - && mountpoint -q /boot/efi; then - outfile="/boot/efi/${MACHINE_ID}/${kernel}/initrd" - else - outfile="$dracutsysrootdir/boot/initramfs-${kernel}.img" - fi - fi -fi - # eliminate IFS hackery when messing with fw_dir export DRACUT_FIRMWARE_PATH=${fw_dir// /:} fw_dir=${fw_dir//:/ } @@ -1313,6 +1236,41 @@ else exit 1 fi +if ! [[ $outfile ]]; then + DOLLAR_BOOT="$(get_dollar_boot)" + [[ $DOLLAR_BOOT ]] && ddebug "\$BOOT set to $DOLLAR_BOOT" + + if [[ $machine_id != "no" ]]; then + MACHINE_ID="$(get_machine_id "${DOLLAR_BOOT:-no}")" + fi + + if [[ $uefi == "yes" ]]; then + if ! [[ $DOLLAR_BOOT ]]; then + dfatal '$BOOT (ESP and XBOOTLDR) partition not found.' + exit 1 + fi + + if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] || [[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then + dfatal "Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set." + exit 1 + fi + + if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign &> /dev/null; then + dfatal "Need 'sbsign' to create a signed UEFI executable." + exit 1 + fi + + BUILD_ID=$(cat "$dracutsysrootdir"/etc/os-release "$dracutsysrootdir"/usr/lib/os-release \ + | while read -r line || [[ $line ]]; do + [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break + done) + mkdir -p "${DOLLAR_BOOT}/EFI/Linux" + outfile="${DOLLAR_BOOT}/EFI/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi" + else + outfile="$(get_default_initramfs_image "$kernel" "${DOLLAR_BOOT:-no}" "${MACHINE_ID:-no}")" + fi +fi + if [[ $persistent_policy == "mapper" ]]; then unset persistent_policy elif [[ -n $persistent_policy && ! -d "/dev/disk/${persistent_policy}" ]]; then