git: 0fd91c489134 - main - bsdinstall: fix EFI boot entry creation

From: Ahmad Khalifa <vexeduxr_at_FreeBSD.org>
Date: Tue, 24 Feb 2026 20:45:44 UTC
The branch main has been updated by vexeduxr:

URL: https://cgit.FreeBSD.org/src/commit/?id=0fd91c489134643ac9e38c0f55ba7464fe892c5e

commit 0fd91c489134643ac9e38c0f55ba7464fe892c5e
Author:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
AuthorDate: 2026-02-24 20:11:32 +0000
Commit:     Ahmad Khalifa <vexeduxr@FreeBSD.org>
CommitDate: 2026-02-24 20:42:21 +0000

    bsdinstall: fix EFI boot entry creation
    
    update_uefi_bootentry assumes that the caller sets FREEBSD_BOOTNAME and
    mntpt, which isn't the case anymore. The result is that there is no
    "FreeBSD" boot entry created/updated after install. Most machines manage
    to boot from the removable media path (if the loader is installed there
    too), but some don't.
    
    Take the loader's path as an argument and rename the variable used in
    the ZFS mirror loop so mntpt can be reused below.
    
    Also mark nentries as a local variable so it doesn't leak out of the
    function.
    
    PR:             293385
    Fixes:          494de51bc0074472d1b01604f085daea0844f240
    MFC after:      2 days
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D55469
---
 usr.sbin/bsdinstall/scripts/bootconfig | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig
index 9c188c1d8a91..d551d2448611 100755
--- a/usr.sbin/bsdinstall/scripts/bootconfig
+++ b/usr.sbin/bsdinstall/scripts/bootconfig
@@ -83,11 +83,13 @@ uefi_copy_loader()
 
 update_uefi_bootentry()
 {
-	nentries=$(efibootmgr | grep -c "${EFI_LABEL_NAME}$")
+	local nentries=$(efibootmgr | grep -c "${EFI_LABEL_NAME}$")
+	local loader_path=$1
+
 	# No entries so directly create one and return
 	if [ ${nentries} -eq 0 ]; then
 		f_dprintf "Creating UEFI boot entry"
-		efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
+		efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${loader_path}" > /dev/null
 		return
 	fi
 
@@ -97,13 +99,13 @@ update_uefi_bootentry()
 		for entry in $(efibootmgr | awk "\$NF == \"$EFI_LABEL_NAME\" { sub(/.*Boot/,\"\", \$1); sub(/\*/,\"\", \$1); print \$1 }"); do
 			efibootmgr -B -b ${entry}
 		done
-		efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
+		efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${loader_path}" > /dev/null
 		return
 	fi
 
 	FREEBSD_BOOTLABEL=$(dialog_uefi_entryname "${EFI_LABEL_NAME}")
 	[ $? -eq $DIALOG_CANCEL ] && exit 1
-	efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
+	efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${loader_path}" > /dev/null
 }
 
 f_dialog_title "Boot Configuration"
@@ -151,21 +153,22 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
 	# over gmirror, so we only do this for ZFS.
 	esps=${TMPDIR:-"/tmp"}/bsdinstall-esps
 	if [ -f "$esps" ]; then
-		mntpt=$(mktemp -d -t bsdinstall-esp)
+		tmpmnt=$(mktemp -d -t bsdinstall-esp)
 		for dev in $(cat $esps); do
 			f_dprintf "Installing ${file} onto redundant ESP ${dev}"
-			mount -t msdos "$dev" "$mntpt"
+			mount -t msdos "$dev" "$tmpmnt"
 			uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \
-				"${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \
+				"${tmpmnt}/efi/freebsd" "${tmpmnt}/efi/boot" \
 				boot${ARCHBOOTNAME}.efi
-			umount "$mntpt"
+			umount "$tmpmnt"
 		done
-		rmdir "${mntpt}"
+		rmdir "${tmpmnt}"
 	fi
 
-	# Try to set the UEFI NV BootXXXX variables to record the boot location
+	# Try to set the UEFI NV BootXXXX variables to record the boot location.
+	# Note that the ESP is mounted at ${mntpt}/efi.
 	if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then
-		update_uefi_bootentry
+		update_uefi_bootentry "${mntpt}/efi/freebsd/${file}"
 	fi
 
 	f_dprintf "Finished configuring ESP"