Index: tools/boot/install-boot.sh =================================================================== --- tools/boot/install-boot.sh +++ tools/boot/install-boot.sh @@ -134,29 +134,31 @@ 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 [ -z "${offline}" ]; 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 - else - echo "Existing UEFI FreeBSD boot entry found: not creating a new one" + 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 fi umount "${mntpt}" @@ -362,6 +364,7 @@ printf ' -f fs filesystem type: ufs or zfs\n' printf ' -g geli yes or no\n' printf ' -h this help/usage text\n' + printf ' -n Operate offline: do not run efibootmgr etc.\n' printf ' -o optargs optional arguments\n' printf ' -s scheme mbr or gpt\n' exit 0 @@ -372,7 +375,7 @@ # 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:hno:s:" opt; do case "$opt" in b) bios=${OPTARG} @@ -389,6 +392,9 @@ *) geli=nogeli ;; esac ;; + n) + offline=1 + ;; o) opts=${OPTARG} ;; Index: tools/boot/rootgen.sh =================================================================== --- tools/boot/rootgen.sh +++ tools/boot/rootgen.sh @@ -27,6 +27,8 @@ # vars should likely be conditionally set to allow better automation. # +. $(dirname $0)/install-boot.sh + cpsys() { src=$1 dst=$2 @@ -116,7 +118,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -154,7 +156,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -193,7 +195,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -274,7 +276,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -315,7 +317,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -356,7 +358,7 @@ zpool set bootfs=${pool}/ROOT/default ${pool} zpool set autoexpand=on ${pool} zpool export ${pool} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -392,7 +394,7 @@ # end tweaks umount -f ${mntpt} geli detach ${md}p2 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -428,7 +430,7 @@ # end tweaks umount -f ${mntpt} geli detach ${md}p2 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -465,7 +467,7 @@ # end tweaks umount -f ${mntpt} geli detach ${md}p3 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -508,7 +510,7 @@ zpool set autoexpand=on ${pool} zpool export ${pool} geli detach ${md}p2 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -551,7 +553,7 @@ zpool set autoexpand=on ${pool} zpool export ${pool} geli detach ${md}p2 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -595,7 +597,7 @@ zpool set autoexpand=on ${pool} zpool export ${pool} geli detach ${md}p3 - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} } @@ -641,7 +643,7 @@ kldload geom_part_vtoc8.ko gpart create -s VTOC8 ${md} gpart add -t freebsd-ufs ${md} - ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} + ${SRCTOP}/tools/boot/install-boot.sh -n -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} mdconfig -d -u ${md} rm -f ${src}/etc/fstab }