1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/bin/sh
#-
# Copyright (c) 2018 Rebecca Cran
# Copyright (c) 2017 Nathan Whitehorn
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# 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
# SUCH DAMAGE.
#
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
FREEBSD_BOOTLABEL=$OSNAME
f_dprintf "%s: loading_includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
: ${TMPDIR:="/tmp"}
die() {
echo $*
exit 1
}
dialog_uefi_entryname()
{
local prompt="Please enter a name for the new entry"
local hline=
local value="$*"
local height width
f_dialog_inputbox_size height width \
"$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline"
$DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "Ok" \
--no-cancel \
--inputbox "$prompt" \
$height $width "$value" \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
}
# Copy to the normal FreeBSD location. Also copy to the default location if it
# doesn't exist. This covers setups where UEFI NV variables can't be set and
# some buggy firmware, while preserving complex UEFI setups for multiple booting
# (rEFInd, etc).
uefi_copy_loader()
{
local ldr=$1
local freebsd_dir=$2
local default_dir=$3
local dest=$4
mkdir -p "${freebsd_dir}" "${default_dir}"
cp "${ldr}" "${freebsd_dir}"
if [ ! -f "${default_dir}/${dest}" ]; then
cp "${ldr}" "${default_dir}/${dest}"
fi
}
update_uefi_bootentry()
{
nentries=$(efibootmgr | grep -c "${EFI_LABEL_NAME}$")
# No entries so directly create one and return
if [ ${nentries} -eq 0 ]; then
f_dprintf "Creating UEFI boot entry"
efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
return
fi
$DIALOG --backtitle "$OSNAME Installer" --title 'Boot Configuration' \
--yesno "One or more \"$OSNAME\" EFI boot manager entries already exist. Would you like to remove them all and add a new one?" 0 0
if [ $? -eq $DIALOG_OK ]; then
for entry in $(efibootmgr | awk "\$NF == \"$EFI_LABEL_NAME\" { sub(/.*Boot/,\"\", \$1); sub(/\*/,\"\", \$1); print \$1 }"); do
efibootmgr -B -b ${entry}
done
efibootmgr --create --activate --label "$EFI_LABEL_NAME" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
return
fi
FREEBSD_BOOTLABEL=$(dialog_uefi_entryname "${EFI_LABEL_NAME}")
[ $? -eq $DIALOG_CANCEL ] && exit 1
efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null
}
f_dialog_title "Boot Configuration"
f_dialog_backtitle "$OSNAME Installer"
if [ `uname -m` == powerpc ]; then
platform=`sysctl -n hw.platform`
if [ "$platform" == ps3 -o "$platform" == powernv ]; then
rootpart=$(awk '{ if($2 == "/") printf("%s:%s\n", $3, $1); }' $PATH_FSTAB)
kboot_conf=$BSDINSTALL_CHROOT/boot/etc/kboot.conf
mkdir -p $BSDINSTALL_CHROOT/boot/etc/
echo default=$FREEBSD_BOOTLABEL > $kboot_conf
echo $FREEBSD_BOOTLABEL=\'/kernel/kernel kernelname=/boot/kernel/kernel vfs.root.mountfrom=${rootpart}\' >> $kboot_conf
fi
fi
# Update the ESP (EFI System Partition) with the new bootloader if we have an ESP
if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
case $(uname -m) in
arm64) ARCHBOOTNAME=aa64 ;;
amd64) ARCHBOOTNAME=x64 ;;
riscv) ARCHBOOTNAME=riscv64 ;;
# arm) ARCHBOOTNAME=arm ;; # No other support for arm install
# i386) ARCHBOOTNAME=ia32 ;; # no support for this in i386 kernels, rare machines
*) die "Unsupported arch $(uname -m) for UEFI install"
esac
# Support the weird 32-bit firmware loading 64-bit kernels
if [ `sysctl -n machdep.efi_arch` == i386 ]; then
ARCHBOOTNAME=ia32
file=loader_ia32.efi
else
file=loader.efi
fi
# Copy the boot loader
mntpt="$BSDINSTALL_CHROOT/boot/efi"
f_dprintf "Installing ${file} onto ESP"
uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \
"${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \
boot${ARCHBOOTNAME}.efi
# zfsboot records the extra esp partitions it creates to -esps. These
# are newfs'd at the time of creation. We don't support installing ufs
# over gmirror, so we only do this for ZFS.
esps=${TMPDIR:-"/tmp"}/bsdinstall-esps
if [ -f "$esps" ]; then
mntpt=$(mktemp -d -t bsdinstall-esp)
for dev in $(cat $esps); do
f_dprintf "Installing ${file} onto redundant ESP ${dev}"
mount -t msdos "$dev" "$mntpt"
uefi_copy_loader "$BSDINSTALL_CHROOT/boot/${file}" \
"${mntpt}/efi/freebsd" "${mntpt}/efi/boot" \
boot${ARCHBOOTNAME}.efi
umount "$mntpt"
done
rmdir "${mntpt}"
fi
# Try to set the UEFI NV BootXXXX variables to record the boot location
if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then
update_uefi_bootentry
fi
f_dprintf "Finished configuring ESP"
fi
# Add boot0cfg for MBR BIOS booting?
|