Changeset View
Changeset View
Standalone View
Standalone View
head/tools/boot/install-boot.sh
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | rmdir "${mntpt}" | ||||
# Keep a copy of the existing loader.efi in case there's a problem with the new one | # Keep a copy of the existing loader.efi in case there's a problem with the new one | ||||
if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then | if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then | ||||
cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi" | cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi" | ||||
fi | fi | ||||
echo "Copying loader to /EFI/freebsd on ESP" | echo "Copying loader to /EFI/freebsd on ESP" | ||||
cp "${file}" "${mntpt}/EFI/freebsd/loader.efi" | cp "${file}" "${mntpt}/EFI/freebsd/loader.efi" | ||||
if [ -n "${updatesystem}" ]; then | |||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi") | existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi") | ||||
if [ -z "$existingbootentryloaderfile" ]; then | if [ -z "$existingbootentryloaderfile" ]; then | ||||
# Try again without the double forward-slash in the path | # Try again without the double forward-slash in the path | ||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi") | existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi") | ||||
fi | fi | ||||
if [ -z "$existingbootentryloaderfile" ]; then | if [ -z "$existingbootentryloaderfile" ]; then | ||||
echo "Creating UEFI boot entry for FreeBSD" | echo "Creating UEFI boot entry for FreeBSD" | ||||
efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null | efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null | ||||
if [ $? -ne 0 ]; then | if [ $? -ne 0 ]; then | ||||
die "Failed to create new boot entry" | die "Failed to create new boot entry" | ||||
fi | fi | ||||
# When creating new entries, efibootmgr doesn't mark them active, so we need to | # When creating new entries, efibootmgr doesn't mark them active, so we need to | ||||
# do so. It doesn't make it easy to find which entry it just added, so rely on | # do so. It doesn't make it easy to find which entry it just added, so rely on | ||||
# the fact that it places the new entry first in BootOrder. | # the fact that it places the new entry first in BootOrder. | ||||
bootorder=$(efivar --name 8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head -1) | bootorder=$(efivar --name 8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head -1) | ||||
bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo "${bootorder}" | cut -w -f 2) | bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo "${bootorder}" | cut -w -f 2) | ||||
echo "Marking UEFI boot entry ${bootentry} active" | echo "Marking UEFI boot entry ${bootentry} active" | ||||
efibootmgr --activate "${bootentry}" > /dev/null | efibootmgr --activate "${bootentry}" > /dev/null | ||||
else | else | ||||
echo "Existing UEFI FreeBSD boot entry found: not creating a new one" | echo "Existing UEFI FreeBSD boot entry found: not creating a new one" | ||||
fi | fi | ||||
else | |||||
# Configure for booting from removable media | |||||
if [ ! -d "${mntpt}/EFI/BOOT" ]; then | |||||
mkdir -p "${mntpt}/EFI/BOOT" | |||||
fi | |||||
cp "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi" | |||||
fi | |||||
umount "${mntpt}" | umount "${mntpt}" | ||||
rmdir "${mntpt}" | rmdir "${mntpt}" | ||||
echo "Finished updating ESP" | echo "Finished updating ESP" | ||||
} | } | ||||
make_esp() { | make_esp() { | ||||
local file loaderfile | local file loaderfile | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | usage() { | ||||
printf 'Usage: %s -b bios [-d destdir] -f fs [-g geli] [-h] [-o optargs] -s scheme <bootdev>\n' "$0" | printf 'Usage: %s -b bios [-d destdir] -f fs [-g geli] [-h] [-o optargs] -s scheme <bootdev>\n' "$0" | ||||
printf 'Options:\n' | printf 'Options:\n' | ||||
printf ' bootdev device to install the boot code on\n' | printf ' bootdev device to install the boot code on\n' | ||||
printf ' -b bios bios type: legacy, uefi or both\n' | printf ' -b bios bios type: legacy, uefi or both\n' | ||||
printf ' -d destdir destination filesystem root\n' | printf ' -d destdir destination filesystem root\n' | ||||
printf ' -f fs filesystem type: ufs or zfs\n' | printf ' -f fs filesystem type: ufs or zfs\n' | ||||
printf ' -g geli yes or no\n' | printf ' -g geli yes or no\n' | ||||
printf ' -h this help/usage text\n' | printf ' -h this help/usage text\n' | ||||
printf ' -u Run commands such as efibootmgr to update the\n' | |||||
printf ' currently running system\n' | |||||
printf ' -o optargs optional arguments\n' | printf ' -o optargs optional arguments\n' | ||||
printf ' -s scheme mbr or gpt\n' | printf ' -s scheme mbr or gpt\n' | ||||
exit 0 | exit 0 | ||||
} | } | ||||
srcroot=/ | srcroot=/ | ||||
# Note: we really don't support geli boot in this script yet. | # Note: we really don't support geli boot in this script yet. | ||||
geli=nogeli | geli=nogeli | ||||
while getopts "b:d:f:g:ho:s:" opt; do | while getopts "b:d:f:g:ho:s:u" opt; do | ||||
case "$opt" in | case "$opt" in | ||||
b) | b) | ||||
bios=${OPTARG} | bios=${OPTARG} | ||||
;; | ;; | ||||
d) | d) | ||||
srcroot=${OPTARG} | srcroot=${OPTARG} | ||||
;; | ;; | ||||
f) | f) | ||||
fs=${OPTARG} | fs=${OPTARG} | ||||
;; | ;; | ||||
g) | g) | ||||
case ${OPTARG} in | case ${OPTARG} in | ||||
[Yy][Ee][Ss]|geli) geli=geli ;; | [Yy][Ee][Ss]|geli) geli=geli ;; | ||||
*) geli=nogeli ;; | *) geli=nogeli ;; | ||||
esac | esac | ||||
;; | |||||
u) | |||||
updatesystem=1 | |||||
;; | ;; | ||||
o) | o) | ||||
opts=${OPTARG} | opts=${OPTARG} | ||||
;; | ;; | ||||
s) | s) | ||||
scheme=${OPTARG} | scheme=${OPTARG} | ||||
;; | ;; | ||||
Show All 31 Lines |