From nobody Tue Sep 30 02:57:18 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cbN5C0TJQz69GjH; Tue, 30 Sep 2025 02:57:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cbN5B74b0z3fmt; Tue, 30 Sep 2025 02:57:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759201039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6i7h6wo+21GJJiEsJtQcyFcsEMyBjUhC3ErJwJc/bnU=; b=UM4DxWxSA34OxKVafEvqQVb7+D+53vj46mSqE88rH3V1Monwz+2p7wCYfNomAN/sEqEVRq K5KhJN1KStTq5DlJKhJNzjAICXkfBufdhHbxMIzZjlfGC6RxhKaAcgq9Ao7Etnci8ilipR iiF2/ycfS/eviI/i3xe7h6MJpVsCrMymBkBliSa0+IpBUDdF+IQ+0M+oehTLZKG/Zd7RjK 4Cf4YdOEmeNku+fR6UGOi5rqV5OpXimHuGc0TDRTaHPN+sCFYKiG/8dmrz8dZcVJpUfUBW U2QEDJtQMyx562L9XX5a9KBGkGyIPWkQPV/HSR6KEndyLGRCL0WhIOJInOA4hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759201039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6i7h6wo+21GJJiEsJtQcyFcsEMyBjUhC3ErJwJc/bnU=; b=PWbf9CEWPoO4fvPDDRRhrHJ2xb9APHGCgqQm00IG4dz/FkGcuqDhKdTf1PmcLS3c3Uxsb6 o+SeY7KJ6c8Xy22IgPneDByTm6zXhtklH79nsYxqRjNK7C7LpoTrTUV/0jNTxfKnNJwnmu uhEgzLkGuVBg7l4rgK4Kg7O/HGRy0f8wkZIIh+PJ8gLR/WtlHN2Ihb3cf3JM69MGWy6+yO AcsCKOluDIGvcpSZ7KQIAtCOLEkzRr2ForgZhuj5RtmxawyeCM02Apyoktu+4Q3IO1HclA LV7hdgKXteAwYXAo2AqLu8vxANAFXVmhRQlEpRhGVH7a+VFxLIojkij3+l9SPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759201039; a=rsa-sha256; cv=none; b=FCYgTtHvCOiXi25WFoYVlU3nK891Lbcrvkw5ljxiC/4ljA82ksE1a/XIRvNTtIX66rOrzp fbdBKhnb8XzQDRHvXiYFRIFZvVtH6GdODQa7GHIvBwx4+uMiP/YYDYTQoBBOyVhGeEfCkG je1rwbx9VT3mdRKlL8iv2pm5qBYfE59WNXgSFX4CXrGuDDD+zIBcXDMT3J9eZK4XWDXogY fDlGpIWwMtuyZiOOfHP7uc9yfA8hsyNbI5Ux4btzQeQ9jac1J9nsM1mS3gO8wDrkRzoRzp 1/T+yRiev8fBUxd74kfzB6JYFS6oyqZ0ynDH3VoLeGqdWpD0mzbfV/hluxB5OA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cbN5B6JGNz2q8; Tue, 30 Sep 2025 02:57:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58U2vIpf017507; Tue, 30 Sep 2025 02:57:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58U2vIWI017504; Tue, 30 Sep 2025 02:57:18 GMT (envelope-from git) Date: Tue, 30 Sep 2025 02:57:18 GMT Message-Id: <202509300257.58U2vIWI017504@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 494de51bc007 - main - bsdinstall: Add loader.efi to all ESPs we create List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 494de51bc0074472d1b01604f085daea0844f240 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=494de51bc0074472d1b01604f085daea0844f240 commit 494de51bc0074472d1b01604f085daea0844f240 Author: Warner Losh AuthorDate: 2025-09-30 02:46:57 +0000 Commit: Warner Losh CommitDate: 2025-09-30 02:55:46 +0000 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 --- usr.sbin/bsdinstall/scripts/auto | 3 ++ usr.sbin/bsdinstall/scripts/bootconfig | 61 ++++++++++++++++++++++------------ usr.sbin/bsdinstall/scripts/zfsboot | 28 +++++++++------- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index 0b47d496fdbd..61d52065af2a 100755 --- a/usr.sbin/bsdinstall/scripts/auto +++ b/usr.sbin/bsdinstall/scripts/auto @@ -178,6 +178,9 @@ environment_save rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC +# Reset the ESP list +: > ${TMPDIR:-"/tmp"}/bsdinstall-esps + # With pkgbase, pkg OOM has been observed with QEMU-default 128 MiB memory size. # Ensure we have at least about 256 MiB (with an allowance for rounding etc.). physmem=$(($(sysctl -n hw.physmem) / 1048576)) diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig index 41243ad14b9b..6736e78b450a 100755 --- a/usr.sbin/bsdinstall/scripts/bootconfig +++ b/usr.sbin/bsdinstall/scripts/bootconfig @@ -63,6 +63,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}$") @@ -113,6 +131,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 @@ -120,31 +139,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 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}" + uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \ + "${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \ + boot${ARCHBOOTNAME}.efi + + # 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 diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot index 5fbf56ea59ac..95cbba3fa131 100755 --- a/usr.sbin/bsdinstall/scripts/zfsboot +++ b/usr.sbin/bsdinstall/scripts/zfsboot @@ -760,6 +760,7 @@ zfs_create_diskpart() { local funcname=zfs_create_diskpart local disk="$1" index="$2" + local efibootpart # Check arguments if [ ! "$disk" ]; then @@ -867,18 +868,22 @@ zfs_create_diskpart() $disk || return $FAILURE # We'll configure the ESP in bootconfig - if [ -z "$efibootpart" ]; then - efibootpart="/dev/gpt/efiboot$index" - f_dprintf "$funcname: configuring ESP at [%s]" \ - "${efibootpart}" - - f_eval_catch $funcname newfs_msdos "$NEWFS_ESP"\ - "$efibootpart" \ - || return $FAILURE + # Note: This will always be p1 + efibootpart="/dev/gpt/efiboot$index" + f_dprintf "$funcname: configuring ESP at [%s]" \ + "${efibootpart}" + + f_eval_catch $funcname newfs_msdos "$NEWFS_ESP"\ + "$efibootpart" \ + || return $FAILURE + if [ $index -eq 0 ]; then f_eval_catch $funcname printf "$PRINTF_FSTAB" \ - $efibootpart /boot/efi msdosfs \ - rw 2 2 "$BSDINSTALL_TMPETC/fstab" \ - || return $FAILURE + $efibootpart /boot/efi msdosfs \ + rw 2 2 "$BSDINSTALL_TMPETC/fstab" \ + || return $FAILURE + else + # Record the extra ones + echo "${efibootpart}" >> ${TMPDIR:-"/tmp"}/bsdinstall-esps fi fi @@ -1021,7 +1026,6 @@ zfs_create_boot() local isswapmirror local bootpart targetpart swappart # Set by zfs_create_diskpart() below local create_options - local efibootpart # # Pedantic checks; should never be seen