summaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall
diff options
context:
space:
mode:
authorRebecca Cran <bcran@FreeBSD.org>2018-12-20 19:39:37 +0000
committerRebecca Cran <bcran@FreeBSD.org>2018-12-20 19:39:37 +0000
commitdb8b56134506840832bec2d1ce07b9e00d4d6d71 (patch)
tree242e3d5aea577a1691fc784b6b35da9690e23d5c /usr.sbin/bsdinstall
parentd5cee48f3e65662051e15c85e4fc1841d72977fe (diff)
downloadsrc-test2-db8b56134506840832bec2d1ce07b9e00d4d6d71.tar.gz
src-test2-db8b56134506840832bec2d1ce07b9e00d4d6d71.zip
Notes
Diffstat (limited to 'usr.sbin/bsdinstall')
-rw-r--r--usr.sbin/bsdinstall/partedit/gpart_ops.c18
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_arm64.c8
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_x86.c11
-rwxr-xr-xusr.sbin/bsdinstall/scripts/bootconfig119
-rwxr-xr-xusr.sbin/bsdinstall/scripts/zfsboot39
5 files changed, 139 insertions, 56 deletions
diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c
index d6a2c44c4dd4..87e45e348426 100644
--- a/usr.sbin/bsdinstall/partedit/gpart_ops.c
+++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c
@@ -31,6 +31,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
+#include <fcntl.h>
#include <libutil.h>
#include <inttypes.h>
@@ -192,7 +193,9 @@ newfs_command(const char *fstype, char *command, int use_default)
for (i = 0; i < (int)nitems(items); i++) {
if (items[i].state == 0)
continue;
- if (strcmp(items[i].name, "FAT16") == 0)
+ if (strcmp(items[i].name, "FAT32") == 0)
+ strcat(command, "-F 32 -c 1");
+ else if (strcmp(items[i].name, "FAT16") == 0)
strcat(command, "-F 16 ");
else if (strcmp(items[i].name, "FAT12") == 0)
strcat(command, "-F 12 ");
@@ -400,7 +403,7 @@ gpart_bootcode(struct ggeom *gp)
TRUE);
return;
}
-
+
bootsize = lseek(bootfd, 0, SEEK_END);
boot = malloc(bootsize);
lseek(bootfd, 0, SEEK_SET);
@@ -706,8 +709,17 @@ set_default_part_metadata(const char *name, const char *scheme,
if (strcmp(type, "freebsd-swap") == 0)
mountpoint = "none";
if (strcmp(type, bootpart_type(scheme, &default_bootmount)) == 0) {
- if (default_bootmount == NULL)
+ if (default_bootmount == NULL) {
+
+ int fd = open("/tmp/bsdinstall-esps", O_CREAT | O_WRONLY | O_APPEND,
+ 0600);
+ if (fd > 0) {
+ write(fd, md->name, strlen(md->name));
+ close(fd);
+ }
+
md->bootcode = 1;
+ }
else if (mountpoint == NULL || strlen(mountpoint) == 0)
mountpoint = default_bootmount;
}
diff --git a/usr.sbin/bsdinstall/partedit/partedit_arm64.c b/usr.sbin/bsdinstall/partedit/partedit_arm64.c
index b226c7cc1474..934cd30c72f9 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_arm64.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_arm64.c
@@ -35,8 +35,7 @@
#include "partedit.h"
/* EFI partition size in bytes */
-#define EFI_BOOTPART_SIZE (200 * 1024 * 1024)
-#define EFI_BOOTPART_PATH "/boot/boot1.efifat"
+#define EFI_BOOTPART_SIZE (260 * 1024 * 1024)
const char *
default_scheme(void)
@@ -95,10 +94,7 @@ const char *
partcode_path(const char *part_type, const char *fs_type)
{
- if (strcmp(part_type, "GPT") == 0)
- return (EFI_BOOTPART_PATH);
-
- /* No boot partition data for non-GPT */
+ /* No boot partition data for ARM64 */
return (NULL);
}
diff --git a/usr.sbin/bsdinstall/partedit/partedit_x86.c b/usr.sbin/bsdinstall/partedit/partedit_x86.c
index 7e88f0a1b856..e81adcad5f6b 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_x86.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_x86.c
@@ -35,8 +35,7 @@
#include "partedit.h"
/* EFI partition size in bytes */
-#define EFI_BOOTPART_SIZE (200 * 1024 * 1024)
-#define EFI_BOOTPART_PATH "/boot/boot1.efifat"
+#define EFI_BOOTPART_SIZE (260 * 1024 * 1024)
static const char *
x86_bootmethod(void)
@@ -141,16 +140,14 @@ const char *
partcode_path(const char *part_type, const char *fs_type)
{
- if (strcmp(part_type, "GPT") == 0) {
- if (strcmp(x86_bootmethod(), "UEFI") == 0)
- return (EFI_BOOTPART_PATH);
- else if (strcmp(fs_type, "zfs") == 0)
+ if (strcmp(part_type, "GPT") == 0 && strcmp(x86_bootmethod(), "UEFI") != 0) {
+ if (strcmp(fs_type, "zfs") == 0)
return ("/boot/gptzfsboot");
else
return ("/boot/gptboot");
}
- /* No partcode except for GPT */
+ /* No partcode except for non-UEFI GPT */
return (NULL);
}
diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig
index bc67078951c7..c9b652dcb665 100755
--- a/usr.sbin/bsdinstall/scripts/bootconfig
+++ b/usr.sbin/bsdinstall/scripts/bootconfig
@@ -1,5 +1,6 @@
#!/bin/sh
#-
+# Copyright (c) 2018 Rebecca Cran
# Copyright (c) 2017 Nathan Whitehorn
# All rights reserved.
#
@@ -26,6 +27,11 @@
#
# $FreeBSD$
+die() {
+ echo $*
+ exit 1
+}
+
if [ `uname -m` == powerpc ]; then
platform=`sysctl -n hw.platform`
if [ "$platform" == ps3 -o "$platform" == powernv ]; then
@@ -35,6 +41,115 @@ if [ `uname -m` == powerpc ]; then
fi
fi
-# For new-style EFI booting, add code here
-# Add boot0cfg for MBR BIOS booting?
+# Update the ESP (EFI System Partition) with the new bootloader
+if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "i386" ]; then
+ X86_BOOTMETHOD=$(sysctl -n machdep.bootmethod)
+fi
+
+if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" = "UEFI" ]; then
+ UFSBOOT_ESPS=$(cat /tmp/bsdinstall-esps)
+ num_esps=0
+
+ if [ -n "$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)
+ # Check that $index is an integer
+ [ -n "$index" ] && [ "$index" -eq "$index" ] && [ "$index" -ge 0 ] 2> /dev/null
+ if [ $? -ne 0 ]; then
+ continue
+ fi
+
+ if [ -e "/dev/${disk}p${index}" ]; then
+ ESPS="$ESPS ${disk}p${index}"
+ elif [ -e "/dev/${disk}s${index}" ]; then
+ ESPS="$ESPS ${disk}s${index}"
+ else
+ continue
+ fi
+
+ num_esps=$((num_esps + 1))
+ done
+ fi
+
+ if [ -n "$UFSBOOT_ESPS" ]; then
+ # We're in a UFS install environment
+ for partition in $UFSBOOT_ESPS; do
+ ESPS="$ESPS $partition"
+ num_esps=$((num_esps + 1))
+ done
+ fi
+
+ if [ -z "$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 [ -n "$hasfreebsd" ]; then
+ index=$(gpart show "$disk" | cut -w -f 4,5 | grep "efi" | cut -w -f 1)
+ # Check that $index is a valid integer
+ [ -n "$index" ] && [ "$index" -eq "$index" ] && [ "$index" -ge 0 ] 2> /dev/null
+ if [ $? -ne 0 ]; then
+ continue
+ fi
+
+ mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
+ if [ -e "/dev/${disk}p${index}" ]; then
+ dev=${disk}p${index}
+ elif [ -e "/dev/${disk}s${index}" ]; then
+ dev=/${disk}s${index}
+ else
+ continue
+ 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}"
+ num_esps=$((num_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" > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ die "Failed to format ESP $esp as FAT32"
+ fi
+
+ mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
+ mount -t msdosfs "/dev/${esp}" "${mntpt}"
+ if [ $? -ne 0 ]; then
+ die "Failed to mount ESP ${dev} on ${mntpt}"
+ fi
+
+ mkdir -p "$mntpt/EFI/freebsd"
+ cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/EFI/freebsd/loader.efi"
+
+ if [ "$num_esps" -gt 1 ]; then
+ bootlabel="FreeBSD (${esp})"
+ else
+ bootlabel="FreeBSD"
+ fi
+
+ efibootmgr --create --label "$bootlabel" --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null
+
+ umount "${mntpt}"
+ rmdir "${mntpt}"
+
+ # 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)
+ efibootmgr --activate "$bootentry" > /dev/null
+ done
+fi
+
+# Add boot0cfg for MBR BIOS booting?
diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot
index 48fb3981855d..9175b01f293b 100755
--- a/usr.sbin/bsdinstall/scripts/zfsboot
+++ b/usr.sbin/bsdinstall/scripts/zfsboot
@@ -213,7 +213,6 @@ KLDLOAD='kldload %s'
LN_SF='ln -sf "%s" "%s"'
MKDIR_P='mkdir -p "%s"'
MOUNT_TYPE='mount -t %s "%s" "%s"'
-NEWFS_ESP='newfs_msdos -F %s -L "%s" "%s"'
PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
SHELL_TRUNCATE=':> "%s"'
@@ -851,29 +850,7 @@ zfs_create_diskpart()
"$align_small" efiboot$index efi 200M \
$disk || return $FAILURE
- f_eval_catch $funcname mkdir "$MKDIR_P" \
- "$BSDINSTALL_TMPETC/esp" ||
- return $FAILURE
- f_eval_catch $funcname newfs_msdos "$NEWFS_ESP" "16" \
- "EFISYS" "/dev/${disk}p1" ||
- return $FAILURE
- f_eval_catch $funcname mount "$MOUNT_TYPE" "msdosfs" \
- "/dev/${disk}p1" \
- "$BSDINSTALL_TMPETC/esp" ||
- return $FAILURE
- f_eval_catch $funcname mkdir "$MKDIR_P" \
- "$BSDINSTALL_TMPETC/esp/efi/boot" ||
- return $FAILURE
- f_eval_catch $funcname cp "$COPY" "/boot/loader.efi" \
- "$BSDINSTALL_TMPETC/esp/efi/boot/$ZFSBOOT_ESP_NAME" ||
- return $FAILURE
- f_eval_catch $funcname echo "$ECHO_OVERWRITE" \
- "$ZFSBOOT_ESP_NAME" \
- "$BSDINSTALL_TMPETC/esp/efi/boot/startup.nsh" ||
- return $FAILURE
- f_eval_catch $funcname umount "$UMOUNT" \
- "$BSDINSTALL_TMPETC/esp" ||
- return $FAILURE
+ # We'll configure the ESP in bootconfig
fi
if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o \
@@ -1596,20 +1573,6 @@ arm64)
esac
#
-# The EFI loader installed in the ESP (EFI System Partition) must
-# have the expected name in order to load correctly.
-#
-[ "$ZFSBOOT_ESP_NAME" ] || case "${UNAME_m:-$( uname -m )}" in
- arm64) ZFSBOOT_ESP_NAME=BOOTaa64.efi ;;
- arm) ZFSBOOT_ESP_NAME=BOOTarm.efi ;;
- i386) ZFSBOOT_ESP_NAME=BOOTia32.efi ;;
- amd64) ZFSBOOT_ESP_NAME=BOOTx64.efi ;;
- *)
- f_dprintf "Unsupported architecture: %s" $UNAME_m
- f_die
-esac
-
-#
# Loop over the main menu until we've accomplished what we came here to do
#
while :; do