Fix install-boot.sh and rootgen.sh UEFI bugs
tools/boot/install-boot.sh was assuming that if a device was passed in, it should operate on the current system and run efibootmgr etc. to update the boot manager. However, rootgen.sh passes a md(4) device and not a fixed disk. Add a -u option to install-boot.sh to tell it to update the system in-place and run efibootmgr etc. Also, source install-boot.sh in rootgen.sh to allow it to find and call make_esp_file etc. And pass the loader file to make_esp_file instead of a directory name. Reported by: ian Reviewed by: ian,imp,tsoome Differential Revision: https://reviews.freebsd.org/D19992
This commit is contained in:
parent
6dbde879b1
commit
75fcc582d3
@ -134,29 +134,37 @@ make_esp_device() {
|
||||
echo "Copying loader to /EFI/freebsd on ESP"
|
||||
cp "${file}" "${mntpt}/EFI/freebsd/loader.efi"
|
||||
|
||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi")
|
||||
if [ -n "${updatesystem}" ]; then
|
||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi")
|
||||
|
||||
if [ -z "$existingbootentryloaderfile" ]; then
|
||||
# Try again without the double forward-slash in the path
|
||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi")
|
||||
fi
|
||||
|
||||
if [ -z "$existingbootentryloaderfile" ]; then
|
||||
echo "Creating UEFI boot entry for FreeBSD"
|
||||
efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Failed to create new boot entry"
|
||||
if [ -z "$existingbootentryloaderfile" ]; then
|
||||
# Try again without the double forward-slash in the path
|
||||
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi")
|
||||
fi
|
||||
|
||||
# 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
|
||||
# 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)
|
||||
bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo "${bootorder}" | cut -w -f 2)
|
||||
echo "Marking UEFI boot entry ${bootentry} active"
|
||||
efibootmgr --activate "${bootentry}" > /dev/null
|
||||
if [ -z "$existingbootentryloaderfile" ]; then
|
||||
echo "Creating UEFI boot entry for FreeBSD"
|
||||
efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die "Failed to create new boot entry"
|
||||
fi
|
||||
|
||||
# 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
|
||||
# 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)
|
||||
bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo "${bootorder}" | cut -w -f 2)
|
||||
echo "Marking UEFI boot entry ${bootentry} active"
|
||||
efibootmgr --activate "${bootentry}" > /dev/null
|
||||
else
|
||||
echo "Existing UEFI FreeBSD boot entry found: not creating a new one"
|
||||
fi
|
||||
else
|
||||
echo "Existing UEFI FreeBSD boot entry found: not creating a new one"
|
||||
# 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}"
|
||||
@ -362,6 +370,8 @@ usage() {
|
||||
printf ' -f fs filesystem type: ufs or zfs\n'
|
||||
printf ' -g geli yes or no\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 ' -s scheme mbr or gpt\n'
|
||||
exit 0
|
||||
@ -372,7 +382,7 @@ srcroot=/
|
||||
# Note: we really don't support geli boot in this script yet.
|
||||
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
|
||||
b)
|
||||
bios=${OPTARG}
|
||||
@ -389,6 +399,9 @@ while getopts "b:d:f:g:ho:s:" opt; do
|
||||
*) geli=nogeli ;;
|
||||
esac
|
||||
;;
|
||||
u)
|
||||
updatesystem=1
|
||||
;;
|
||||
o)
|
||||
opts=${OPTARG}
|
||||
;;
|
||||
|
@ -27,6 +27,8 @@ espsize=33292
|
||||
# vars should likely be conditionally set to allow better automation.
|
||||
#
|
||||
|
||||
. $(dirname $0)/install-boot.sh
|
||||
|
||||
cpsys() {
|
||||
src=$1
|
||||
dst=$2
|
||||
@ -56,7 +58,7 @@ mk_nogeli_gpt_ufs_uefi() {
|
||||
cat > ${src}/etc/fstab <<EOF
|
||||
/dev/ada0p2 / ufs rw 1 1
|
||||
EOF
|
||||
make_esp_file ${img}.p1 ${espsize} ${src}
|
||||
make_esp_file ${img}.p1 ${espsize} ${src}/boot/loader.efi
|
||||
makefs -t ffs -B little -s 200m ${img}.p2 ${src}
|
||||
mkimg -s gpt \
|
||||
-p efi:=${img}.p1 \
|
||||
@ -71,7 +73,7 @@ mk_nogeli_gpt_ufs_both() {
|
||||
cat > ${src}/etc/fstab <<EOF
|
||||
/dev/ada0p3 / ufs rw 1 1
|
||||
EOF
|
||||
make_esp_file ${img}.p1 ${espsize} ${src}
|
||||
make_esp_file ${img}.p1 ${espsize} ${src}/boot/loader.efi
|
||||
makefs -t ffs -B little -s 200m ${img}.p3 ${src}
|
||||
# p1 is boot for uefi, p2 is boot for gpt, p3 is /
|
||||
mkimg -b ${src}/boot/pmbr -s gpt \
|
||||
@ -217,7 +219,7 @@ mk_nogeli_mbr_ufs_uefi() {
|
||||
cat > ${src}/etc/fstab <<EOF
|
||||
/dev/ada0s2a / ufs rw 1 1
|
||||
EOF
|
||||
make_esp_file ${img}.s1 ${espsize} ${src}
|
||||
make_esp_file ${img}.s1 ${espsize} ${src}/boot/loader.efi
|
||||
makefs -t ffs -B little -s 200m ${img}.s2a ${src}
|
||||
mkimg -s bsd -p freebsd-ufs:=${img}.s2a -o ${img}.s2
|
||||
mkimg -a 1 -s mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img}
|
||||
@ -231,7 +233,7 @@ mk_nogeli_mbr_ufs_both() {
|
||||
cat > ${src}/etc/fstab <<EOF
|
||||
/dev/ada0s2a / ufs rw 1 1
|
||||
EOF
|
||||
make_esp_file ${img}.s1 ${espsize} ${src}
|
||||
make_esp_file ${img}.s1 ${espsize} ${src}/boot/loader.efi
|
||||
makefs -t ffs -B little -s 200m ${img}.s2a ${src}
|
||||
mkimg -s bsd -b ${src}/boot/boot -p freebsd-ufs:=${img}.s2a -o ${img}.s2
|
||||
mkimg -a 2 -s mbr -b ${src}/boot/mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img}
|
||||
|
Loading…
x
Reference in New Issue
Block a user