Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bsdinstall/scripts/bootconfig
Show All 21 Lines | |||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
# SUCH DAMAGE. | # SUCH DAMAGE. | ||||
# | # | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
BSDCFG_SHARE="/usr/share/bsdconfig" | |||||
. $BSDCFG_SHARE/common.subr || exit 1 | |||||
die() { | die() { | ||||
echo $* | echo $* | ||||
exit 1 | exit 1 | ||||
} | } | ||||
if [ `uname -m` == powerpc ]; then | 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 | ||||
# Update the ESP (EFI System Partition) with the new bootloader | # Update the ESP (EFI System Partition) with the new bootloader | ||||
if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "i386" ]; then | if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "i386" ]; then | ||||
X86_BOOTMETHOD=$(sysctl -n machdep.bootmethod) | X86_BOOTMETHOD=$(sysctl -n machdep.bootmethod) | ||||
fi | fi | ||||
if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then | 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 | num_esps=0 | ||||
if [ -n "$ZFSBOOT_DISKS" ]; then | if [ -n "$ZFSBOOT_DISKS" ]; then | ||||
# We're in a ZFS install environment | # We're in a ZFS install environment | ||||
for disk in $ZFSBOOT_DISKS; do | for disk in $ZFSBOOT_DISKS; do | ||||
index=$(gpart show "$disk" | cut -w -f 4,5 | grep "efi" | cut -w -f 1) | index=$(gpart show "$disk" | cut -w -f 4,5 | grep "efi" | cut -w -f 1) | ||||
# Check that $index is an integer | # Check that $index is an integer | ||||
[ -n "$index" ] && [ "$index" -eq "$index" ] && [ "$index" -ge 0 ] 2> /dev/null | [ -n "$index" ] && [ "$index" -eq "$index" ] && [ "$index" -ge 0 ] 2> /dev/null | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | for geom in $(gpart status -sg | awk '{print $1}'); do | ||||
umount "${mntpt}" | umount "${mntpt}" | ||||
fi | fi | ||||
rmdir "${mntpt}" | rmdir "${mntpt}" | ||||
fi | fi | ||||
done | done | ||||
fi | fi | ||||
for esp in $ESPS; do | 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 | newfs_msdos -F 32 -c 1 -L EFISYS "/dev/$esp" > /dev/null 2>&1 | ||||
if [ $? -ne 0 ]; then | if [ $? -ne 0 ]; then | ||||
die "Failed to format ESP $esp as FAT32" | die "Failed to format ESP $esp as FAT32" | ||||
fi | fi | ||||
mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) | mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) | ||||
echo "Mounting ESP /dev/${esp}" | f_dprintf "Mounting ESP /dev/${esp}" | ||||
mount -t msdosfs "/dev/${esp}" "${mntpt}" | mount -t msdosfs "/dev/${esp}" "${mntpt}" | ||||
if [ $? -ne 0 ]; then | if [ $? -ne 0 ]; then | ||||
die "Failed to mount ESP ${dev} on ${mntpt}" | die "Failed to mount ESP ${dev} on ${mntpt}" | ||||
fi | fi | ||||
echo "Installing loader.efi onto ESP" | f_dprintf "Installing loader.efi onto ESP" | ||||
mkdir -p "$mntpt/EFI/freebsd" | mkdir -p "$mntpt/EFI/freebsd" | ||||
cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/EFI/freebsd/loader.efi" | cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/EFI/freebsd/loader.efi" | ||||
if [ "$num_esps" -gt 1 ]; then | if [ "$num_esps" -gt 1 ]; then | ||||
bootlabel="FreeBSD (${esp})" | bootlabel="FreeBSD (${esp})" | ||||
else | else | ||||
bootlabel="FreeBSD" | bootlabel="FreeBSD" | ||||
fi | 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 | efibootmgr --create --activate --label "$bootlabel" --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null | ||||
echo "Unmounting ESP" | f_dprintf "Unmounting ESP" | ||||
umount "${mntpt}" | umount "${mntpt}" | ||||
rmdir "${mntpt}" | rmdir "${mntpt}" | ||||
echo "Finished configuring /dev/${esp} as ESP" | f_dprintf "Finished configuring /dev/${esp} as ESP" | ||||
done | done | ||||
fi | fi | ||||
# Add boot0cfg for MBR BIOS booting? | # Add boot0cfg for MBR BIOS booting? |