Skip to content

Commit

Permalink
bsdinstall: fix ESP detection for auto ZFS layout
Browse files Browse the repository at this point in the history
Pass the list of user selected disks from zfsboot to bootconfig so that
the latter doesn't rely on ESP autodetection that apparently fails for
some cases, e.g. memstick installation with nvme (boot) and sata drives.

While here, fix printing of debug messages in bootconfig.

Reviewed by:	bcran, imp, tsoome
Differential Revision:	https://reviews.freebsd.org/D21930
  • Loading branch information
yuripv authored and yuripv committed Oct 9, 2019
1 parent ab9141d commit c9168b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions usr.sbin/bsdinstall/scripts/bootconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#
# $FreeBSD$

BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1

die() {
echo $*
exit 1
Expand All @@ -47,7 +50,8 @@ if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "i386" ]; then
fi

if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
UFSBOOT_ESPS=$(cat /tmp/bsdinstall-esps)
UFSBOOT_ESPS=$(cat /tmp/bsdinstall-esps 2>/dev/null)
ZFSBOOT_DISKS=$(cat /tmp/bsdinstall-zfsboot 2>/dev/null)
num_esps=0

if [ -n "$ZFSBOOT_DISKS" ]; then
Expand Down Expand Up @@ -119,20 +123,20 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
fi

for esp in $ESPS; do
echo "Formatting /dev/${esp} as FAT32"
f_dprintf "Formatting /dev/${esp} as FAT32"
newfs_msdos -F 32 -c 1 -L EFISYS "/dev/$esp" > /dev/null 2>&1
if [ $? -ne 0 ]; then
die "Failed to format ESP $esp as FAT32"
fi

mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
echo "Mounting ESP /dev/${esp}"
f_dprintf "Mounting ESP /dev/${esp}"
mount -t msdosfs "/dev/${esp}" "${mntpt}"
if [ $? -ne 0 ]; then
die "Failed to mount ESP ${dev} on ${mntpt}"
fi

echo "Installing loader.efi onto ESP"
f_dprintf "Installing loader.efi onto ESP"
mkdir -p "$mntpt/EFI/freebsd"
cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/EFI/freebsd/loader.efi"

Expand All @@ -142,14 +146,14 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
bootlabel="FreeBSD"
fi

echo "Creating UEFI boot entry"
f_dprintf "Creating UEFI boot entry"
efibootmgr --create --activate --label "$bootlabel" --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null

echo "Unmounting ESP"
f_dprintf "Unmounting ESP"
umount "${mntpt}"
rmdir "${mntpt}"

echo "Finished configuring /dev/${esp} as ESP"
f_dprintf "Finished configuring /dev/${esp} as ESP"
done
fi

Expand Down
3 changes: 3 additions & 0 deletions usr.sbin/bsdinstall/scripts/zfsboot
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,9 @@ while :; do
zfs_create_boot "$ZFSBOOT_POOL_NAME" \
"$vdev_type" $ZFSBOOT_DISKS || continue

# To be reused by bootconfig
echo "$ZFSBOOT_DISKS" > /tmp/bsdinstall-zfsboot

break # to success
;;
?" $msg_pool_type_disks")
Expand Down

0 comments on commit c9168b7

Please sign in to comment.