Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bsdinstall/scripts/bootconfig
#!/bin/sh | #!/bin/sh | ||||
#- | #- | ||||
# Copyright (c) 2018 Rebecca Cran | |||||
# Copyright (c) 2017 Nathan Whitehorn | # Copyright (c) 2017 Nathan Whitehorn | ||||
# All rights reserved. | # All rights reserved. | ||||
# | # | ||||
# Redistribution and use in source and binary forms, with or without | # Redistribution and use in source and binary forms, with or without | ||||
# modification, are permitted provided that the following conditions | # modification, are permitted provided that the following conditions | ||||
# are met: | # are met: | ||||
# 1. Redistributions of source code must retain the above copyright | # 1. Redistributions of source code must retain the above copyright | ||||
# notice, this list of conditions and the following disclaimer. | # notice, this list of conditions and the following disclaimer. | ||||
Show All 19 Lines | if [ `uname -m` == powerpc ]; then | ||||
platform=`sysctl -n hw.platform` | platform=`sysctl -n hw.platform` | ||||
if [ "$platform" == ps3 -o "$platform" == powernv ]; then | if [ "$platform" == ps3 -o "$platform" == powernv ]; then | ||||
rootpart=$(awk '{ if($2 == "/") printf("%s:%s\n", $3, $1); }' $PATH_FSTAB) | rootpart=$(awk '{ if($2 == "/") printf("%s:%s\n", $3, $1); }' $PATH_FSTAB) | ||||
mkdir -p $BSDINSTALL_CHROOT/boot/etc/ | mkdir -p $BSDINSTALL_CHROOT/boot/etc/ | ||||
echo FreeBSD=\'/kernel/kernel kernelname=/boot/kernel/kernel vfs.root.mountfrom=${rootpart}\' > $BSDINSTALL_CHROOT/boot/etc/kboot.conf | echo FreeBSD=\'/kernel/kernel kernelname=/boot/kernel/kernel vfs.root.mountfrom=${rootpart}\' > $BSDINSTALL_CHROOT/boot/etc/kboot.conf | ||||
fi | fi | ||||
fi | fi | ||||
# For new-style EFI booting, add code here | # Update the ESP (EFI System Partition) with the new bootloader | ||||
# Add boot0cfg for MBR BIOS booting? | if [ $(uname -m) == amd64 -o $(uname -m) == i386 ]; then | ||||
X86_BOOTMETHOD=$(sysctl -n machdep.bootmethod) | |||||
fi | |||||
if [ $(uname -m) == arm64 -o "$X86_BOOTMETHOD" == "UEFI" ]; then | |||||
imp: how can this ever be true? We only ever set X86_BOOTMETHOD foor amd64 and i386. | |||||
bcranAuthorUnsubmitted Done Inline ActionsI'm checking if the machine is arm64 _or_ the x86 bootmethod is UEFI. bcran: I'm checking if the machine is arm64 _or_ the x86 bootmethod is UEFI.
So it's going to be true… | |||||
mkdir $BSDINSTALL_TMPETC/esp | |||||
UFSBOOT_ESPS=$(cat /tmp/bsdinstall-esps) | |||||
esps=0 | |||||
if [ "$ZFSBOOT_DISKS" ]; then | |||||
# We're in a ZFS install environment | |||||
for disk in $ZFSBOOT_DISKS; do | |||||
index=$(gpart show $disk | cut -w -f 4,5 | grep "efi" | cut -w -f 1) | |||||
if [ -e /dev/${disk}p${index} ]; then | |||||
ESPS="$ESPS ${disk}p${index}" | |||||
else | |||||
ESPS="$ESPS ${disk}s${index}" | |||||
fi | |||||
let esps= $esps + 1 | |||||
done | |||||
fi | |||||
if [ "$UFSBOOT_ESPS" ]; then | |||||
# We're in a UFS install environment | |||||
for partition in $UFSBOOT_ESPS; do | |||||
ESPS="$ESPS $partition" | |||||
let esps= $esps + 1 | |||||
done | |||||
fi | |||||
if [ "$ESPS" == "" ]; then | |||||
# The installer hasn't given us any ESPs to use. | |||||
# Try and figure out which to use by looking for an | |||||
# unformatted efi partition | |||||
for disk in $(sysctl -n kern.disks); do | |||||
hasfreebsd=$(gpart show $disk | cut -w -f 4,5 | grep "freebsd") | |||||
if [ "$hasfreebsd" != "" ]; then | |||||
index=$(gpart show $disk | cut -w -f 4,5 | grep "efi" | cut -w -f 1) | |||||
mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) | |||||
if [ -e /dev/${disk}p${index} ]; then | |||||
dev=${disk}p${index} | |||||
else | |||||
dev=/${disk}s${index} | |||||
fi | |||||
# Try and mount it. If it fails, assume it's | |||||
# unformatted and should be used. | |||||
mount -t msdosfs /dev/${dev} ${mntpt} | |||||
if [ $? -ne 0 ]; then | |||||
ESPS="$ESPS ${dev}" | |||||
let esps= $esps + 1 | |||||
else | |||||
umount ${mntpt} | |||||
fi | |||||
rmdir ${mntpt} | |||||
fi | |||||
done | |||||
fi | |||||
for esp in $ESPS; do | |||||
newfs_msdos -F 32 -c 1 -L EFISYS /dev/$esp | |||||
mount -t msdosfs /dev/$esp $BSDINSTALL_TMPETC/esp | |||||
mkdir -p $BSDINSTALL_TMPETC/esp/EFI/freebsd | |||||
cp $BSDINSTALL_CHROOT/boot/loader.efi $BSDINSTALL_TMPETC/esp/EFI/freebsd/loader.efi | |||||
if [ $esps -gt 1 ]; then | |||||
bootlabel="FreeBSD (${esp})" | |||||
else | |||||
bootlabel="FreeBSD" | |||||
fi | |||||
efibootmgr --create --label "$bootlabel" --loader $BSDINSTALL_TMPETC/esp/EFI/freebsd/loader.efi | |||||
umount $BSDINSTALL_TMPETC/esp | |||||
# 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. | |||||
Done Inline Actionsif we know the path to the kernel, it would be good to include that here. imp: if we know the path to the kernel, it would be good to include that here.
| |||||
Done Inline ActionsI've taken a note to add the kernel path in a follow-up changeset. bcran: I've taken a note to add the kernel path in a follow-up changeset. | |||||
bootorder=$(efivar --name 8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex) | |||||
bootentry=$(echo $bootorder | cut -w -f 3)$(echo $bootorder | cut -w -f 2) | |||||
efibootmgr --activate $bootentry | |||||
done | |||||
rmdir $BSDINSTALL_TMPETC/esp | |||||
fi | |||||
# Add boot0cfg for MBR BIOS booting? |
how can this ever be true? We only ever set X86_BOOTMETHOD foor amd64 and i386.