aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall/scripts/bootconfig
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2025-09-30 02:46:57 +0000
committerWarner Losh <imp@FreeBSD.org>2025-10-04 23:17:36 +0000
commitd8e73f45fc5fe736ad398d15f547af593cc84e6f (patch)
treeb987cdc0063ec4a8498a94e96e9ab80e3a6f437a /usr.sbin/bsdinstall/scripts/bootconfig
parentf591fd26ca8e4a32048287c880bac1f7e12301e7 (diff)
bsdinstall: Add loader.efi to all ESPs we create
For proper redundancy, add copies of loader.efi to each of the ESPs we create when we create multi-volume ZFS datasets. zfsboot creates a list of secondary ESPs, while bootpart doesn't create any (it's the UFS partitioning tool) because we don't supporg UFS over gmirror. The primary ESP is mounted and is what we use efibootmgr to boot from. The redundant copies allow the system to boot if the primary disks fails. Sponsored by: Netflix MFC After: 2 days PR: 208802 Reviewed by: cperciva Differential Revision: https://reviews.freebsd.org/D52780 (cherry picked from commit 494de51bc0074472d1b01604f085daea0844f240)
Diffstat (limited to 'usr.sbin/bsdinstall/scripts/bootconfig')
-rwxr-xr-xusr.sbin/bsdinstall/scripts/bootconfig59
1 files changed, 39 insertions, 20 deletions
diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig
index 6438f7ef1fca..1d8fb8657135 100755
--- a/usr.sbin/bsdinstall/scripts/bootconfig
+++ b/usr.sbin/bsdinstall/scripts/bootconfig
@@ -60,6 +60,24 @@ dialog_uefi_entryname()
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
}
+# Copy to the normal FreeBSD location. Also copy to the default location if it
+# doesn't exist. This covers setups where UEFI NV variables can't be set and
+# some buggy firmware, while preserving complex UEFI setups for multiple booting
+# (rEFInd, etc).
+uefi_copy_loader()
+{
+ local ldr=$1
+ local freebsd_dir=$2
+ local default_dir=$3
+ local dest=$4
+
+ mkdir -p "${freebsd_dir}" "${default_dir}"
+ cp "${ldr}" "${freebsd_dir}"
+ if [ ! -f "${default_dir}/${dest}" ]; then
+ cp "${ldr}" "${default_dir}/${dest}"
+ fi
+}
+
update_uefi_bootentry()
{
nentries=$(efibootmgr | grep -c "${EFI_LABEL_NAME}$")
@@ -110,6 +128,7 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
*) die "Unsupported arch $(uname -m) for UEFI install"
esac
+ # Support the weird 32-bit firmware loading 64-bit kernels
if [ `sysctl -n machdep.efi_arch` == i386 ]; then
ARCHBOOTNAME=ia32
file=loader_ia32.efi
@@ -117,31 +136,31 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
file=loader.efi
fi
- BOOTDIR="/efi/boot"
- BOOTNAME="${BOOTDIR}/boot${ARCHBOOTNAME}.efi"
- FREEBSD_BOOTDIR="/efi/freebsd"
- FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/${file}"
+ # Copy the boot loader
mntpt="$BSDINSTALL_CHROOT/boot/efi"
-
f_dprintf "Installing ${file} onto ESP"
- mkdir -p "${mntpt}/${FREEBSD_BOOTDIR}" "${mntpt}/${BOOTDIR}"
- cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${FREEBSD_BOOTNAME}"
+ uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \
+ "${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \
+ boot${ARCHBOOTNAME}.efi
- #
- # UEFI defines a way to specifically select what to boot
- # (which we do via efibootmgr). However, if we booted from an ia32
- # UEFI environment, we wouldn't have access to efirt. In addition,
- # virtual environments often times lack support for the NV variables
- # efibootmgr sets, and some UEFI implementations have features that
- # interfere with the setting of these variables. To combat that, we
- # install the default removable media boot file if it doesn't exist.
- # We don't install it all the time since that can interfere with other
- # installations on the drive (like rEFInd).
- #
- if [ ! -f "${mntpt}/${BOOTNAME}" ]; then
- cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${BOOTNAME}"
+ # zfsboot records the extra esp partitions it creates to -esps. These
+ # are newfs'd at the time of creation. We don't support installing ufs
+ # over gmirror, so we only do this for ZFS.
+ esps=${TMPDIR:-"/tmp"}/bsdinstall-esps
+ if [ -f "$esps" ]; then
+ mntpt=$(mktemp -d -t bsdinstall-esp)
+ for dev in $(cat $esps); do
+ f_dprintf "Installing ${file} onto redundant ESP ${dev}"
+ mount -t msdos "$dev" "$mntpt"
+ uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \
+ "${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \
+ boot${ARCHBOOTNAME}.efi
+ umount "$mntpt"
+ done
+ rmdir "${mntpt}"
fi
+ # Try to set the UEFI NV BootXXXX variables to recod the boot location
if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then
update_uefi_bootentry
fi