2018-01-02 00:27:24 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
#-
|
2018-12-20 14:39:37 -05:00
|
|
|
# Copyright (c) 2018 Rebecca Cran
|
2018-01-02 00:27:24 -05:00
|
|
|
# Copyright (c) 2017 Nathan Whitehorn
|
|
|
|
|
# All rights reserved.
|
|
|
|
|
#
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
|
# are met:
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
#
|
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
|
#
|
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
2019-10-09 01:28:10 -04:00
|
|
|
BSDCFG_SHARE="/usr/share/bsdconfig"
|
|
|
|
|
. $BSDCFG_SHARE/common.subr || exit 1
|
|
|
|
|
|
2020-01-14 19:45:05 -05:00
|
|
|
: ${TMPDIR:="/tmp"}
|
|
|
|
|
|
2018-12-20 14:39:37 -05:00
|
|
|
die() {
|
|
|
|
|
echo $*
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 00:27:24 -05:00
|
|
|
if [ `uname -m` == powerpc ]; then
|
|
|
|
|
platform=`sysctl -n hw.platform`
|
|
|
|
|
if [ "$platform" == ps3 -o "$platform" == powernv ]; then
|
|
|
|
|
rootpart=$(awk '{ if($2 == "/") printf("%s:%s\n", $3, $1); }' $PATH_FSTAB)
|
|
|
|
|
mkdir -p $BSDINSTALL_CHROOT/boot/etc/
|
2018-06-04 10:42:13 -04:00
|
|
|
echo FreeBSD=\'/kernel/kernel kernelname=/boot/kernel/kernel vfs.root.mountfrom=${rootpart}\' > $BSDINSTALL_CHROOT/boot/etc/kboot.conf
|
2018-01-02 00:27:24 -05:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2021-02-23 16:16:52 -05:00
|
|
|
# Update the ESP (EFI System Partition) with the new bootloader if we have an ESP
|
2021-03-05 20:57:50 -05:00
|
|
|
if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
|
Initial support for implementing the bootXXX.efi workaround
Too many version of UEFI firmware (so far only confirmed on amd64)
don't really support efibootmgr selection of boot. That's the most
reliable, when it works, since there's no guesswork. However, many do
not save, unmolested, the variables that efibootmgr sets, so as a
fallback we also install loader.efi as bootXXX.efi (where XXX is
either aa64 or x64) if it doesn't already exist in /efi/boot on the
ESP. The standard only defines this for removable devices, but it's
almost ubiquitously used as a fallback. Many BIOSes implement a drive
selection feature that takes over the efibootmgr protocol, rendinering
it useless (either generally, or for those vendors not on the short
list). bootxxx.efi works around this. However, we don't install it
unconditionally there, as that breaks some popular multi-boot setups.
MFC After: 1 week
Differential Revision: https://reviews.freebsd.org/D26428
2020-10-08 20:16:26 -04:00
|
|
|
case $(uname -m) in
|
|
|
|
|
arm64) ARCHBOOTNAME=aa64 ;;
|
|
|
|
|
amd64) ARCHBOOTNAME=x64 ;;
|
2021-01-15 11:34:54 -05:00
|
|
|
riscv) ARCHBOOTNAME=riscv64 ;;
|
Initial support for implementing the bootXXX.efi workaround
Too many version of UEFI firmware (so far only confirmed on amd64)
don't really support efibootmgr selection of boot. That's the most
reliable, when it works, since there's no guesswork. However, many do
not save, unmolested, the variables that efibootmgr sets, so as a
fallback we also install loader.efi as bootXXX.efi (where XXX is
either aa64 or x64) if it doesn't already exist in /efi/boot on the
ESP. The standard only defines this for removable devices, but it's
almost ubiquitously used as a fallback. Many BIOSes implement a drive
selection feature that takes over the efibootmgr protocol, rendinering
it useless (either generally, or for those vendors not on the short
list). bootxxx.efi works around this. However, we don't install it
unconditionally there, as that breaks some popular multi-boot setups.
MFC After: 1 week
Differential Revision: https://reviews.freebsd.org/D26428
2020-10-08 20:16:26 -04:00
|
|
|
# arm) ARCHBOOTNAME=arm ;; # No other support for arm install
|
|
|
|
|
# i386) ARCHBOOTNAME=ia32 ;; # no support for this in i386 kernels, rare machines
|
|
|
|
|
*) die "Unsupported arch $(uname -m) for UEFI install"
|
|
|
|
|
esac
|
2021-01-15 11:14:27 -05:00
|
|
|
BOOTDIR="/efi/boot"
|
|
|
|
|
BOOTNAME="${BOOTDIR}/boot${ARCHBOOTNAME}.efi"
|
|
|
|
|
FREEBSD_BOOTDIR="/efi/freebsd"
|
|
|
|
|
FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/loader.efi"
|
2021-02-23 16:16:52 -05:00
|
|
|
mntpt="$BSDINSTALL_CHROOT/boot/efi"
|
|
|
|
|
|
|
|
|
|
f_dprintf "Installing loader.efi onto ESP"
|
|
|
|
|
mkdir -p "${mntpt}/${FREEBSD_BOOTDIR}" "${mntpt}/${BOOTDIR}"
|
|
|
|
|
cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/${FREEBSD_BOOTNAME}"
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# The following shouldn't be necessary. UEFI defines a way to
|
|
|
|
|
# specifically select what to boot (which we do via
|
|
|
|
|
# efibootmgr). However, virtual environments often times lack
|
|
|
|
|
# support for the NV variables efibootmgr sets. In addition,
|
|
|
|
|
# some UEFI implementations have features that interfere with
|
|
|
|
|
# the setting of these variables. To combat that, we install the
|
|
|
|
|
# default removable media boot file as a fallback 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/loader.efi" "${mntpt}/${BOOTNAME}"
|
|
|
|
|
fi
|
Initial support for implementing the bootXXX.efi workaround
Too many version of UEFI firmware (so far only confirmed on amd64)
don't really support efibootmgr selection of boot. That's the most
reliable, when it works, since there's no guesswork. However, many do
not save, unmolested, the variables that efibootmgr sets, so as a
fallback we also install loader.efi as bootXXX.efi (where XXX is
either aa64 or x64) if it doesn't already exist in /efi/boot on the
ESP. The standard only defines this for removable devices, but it's
almost ubiquitously used as a fallback. Many BIOSes implement a drive
selection feature that takes over the efibootmgr protocol, rendinering
it useless (either generally, or for those vendors not on the short
list). bootxxx.efi works around this. However, we don't install it
unconditionally there, as that breaks some popular multi-boot setups.
MFC After: 1 week
Differential Revision: https://reviews.freebsd.org/D26428
2020-10-08 20:16:26 -04:00
|
|
|
|
2021-02-23 16:16:52 -05:00
|
|
|
bootlabel="FreeBSD"
|
2018-12-20 14:39:37 -05:00
|
|
|
|
2021-05-28 09:53:42 -04:00
|
|
|
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
|
|
|
|
|
f_dprintf "Creating UEFI boot entry"
|
|
|
|
|
efibootmgr --create --activate --label "$bootlabel" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
|
|
|
|
|
fi
|
2018-12-20 14:39:37 -05:00
|
|
|
|
2021-02-23 16:16:52 -05:00
|
|
|
f_dprintf "Finished configuring ESP"
|
2018-12-20 14:39:37 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Add boot0cfg for MBR BIOS booting?
|