Commit b8f0a0ff authored by Mike Hibler's avatar Mike Hibler
Browse files

EFI support.

Also add menu items for forcing disk or MFS boot.
parent 7bca0e19
#
# Console device. One of vga, sio1, or sio2
# Disk drivers. Either bios or native
# Console device: one of vga, sio1, or sio2
# Disk drivers: one of bios, efi, or native
# Net drivers: either efi or pxe
#
# For a legacy BIOS based system, you will most likely want diskdrivers=bios
# and netdrivers=pxe. The native disk driver option is for our one-off Intel
# NUC nodes which, if booted via PXE, do not load the BIOS disk drivers.
# Hence we have to use native ahci (sata) drivers.
#
# For a UEFI based system, you will want diskdrivers=efi and netdrivers=efi.
#
set console=sio1
set diskdrivers=bios
set diskdrivers=efi
set netdrivers=efi
if [ $console = vga ]; then
true
......@@ -28,6 +37,9 @@ insmod part_msdos
if [ $diskdrivers = bios ]; then
insmod biosdisk
set hdprefix=hd
elif [ $diskdrivers = efi ]; then
insmod efidisk
set hdprefix=hd
elif [ $diskdrivers = native ]; then
#insmod pata
insmod ahci
......@@ -41,6 +53,12 @@ else
insmod biosdisk
fi
if [ $netdrivers = efi ]; then
insmod efinet
else
true
fi
function display_root_device_info {
echo "Device info for $bootinfo_root"
echo "=========================="
......@@ -60,6 +78,32 @@ function display_root_device_info {
fi
}
#
# Handle maintenance of on-disk grubenv file w.r.t. next_entry and
# saved_entry.
#
function handle_grubenv {
set bootme="0"
set envfile=($diskroot)$grubdir/grubenv
if [ -s $envfile ]; then
load_env -f $envfile
if [ "${next_entry}" ]; then
set bootme="${next_entry}"
set next_entry=
save_env -f $envfile next_entry
else
set bootme="${saved_entry}"
fi
fi
echo "Grub default: '$bootme'"
# XXX these will cause the 00_header code to set default to $bootme
set next_entry=
set saved_entry="$bootme"
set prev_saved_entry=
}
function freebsd_boot {
echo "Booting FreeBSD on ($bootinfo_root)..."
......@@ -76,7 +120,41 @@ function freebsd_boot {
unset bootinfo_kernel
if kfreebsd /boot/emuloader $bootinfo_kernel_args; then
if [ $diskdrivers = efi ]; then
if chainloader /boot/loader.efi; then
echo "Loaded /boot/loader.efi"
else
#
# XXX this is all awesome in theory, but it
# doesn't work. Cannot specify a UUID for the path
# and cannot get bootfile passed through.
#
set bootfile=/boot/kernel/kernel
probe -s fstype -f $root
if [ -z $fstype ]; then
set fstype=ufs
elif [ $fstype = ufs2 ]; then
set fstype=ufs
fi
probe -s fsid -u $root
if [ -n $fsid ]; then
set fstype=${fstype}id
else
set fsid=/dev/da0s1a
fi
echo "Unable to find FreeBSD bootloader."
echo "Attempting a direct boot from ($root)..."
set kFreeBSD.bootfile=$bootfile
set kFreeBSD.vfs.root.mountfrom=${fstype}:${fsid}
set kFreeBSD.vfs.root.mountfrom.options=rw
kfreebsd $bootfile $bootinfo_kernel_args
kfreebsd_loadenv /boot/defaults/loader.conf
kfreebsd_loadenv /boot/device.hints
kfreebsd_loadenv /boot/loader.conf
fi
elif kfreebsd /boot/emuloader $bootinfo_kernel_args; then
echo "Loaded /boot/emuloader"
elif kfreebsd /boot/loader $bootinfo_kernel_args; then
echo "Loaded /boot/loader"
......@@ -90,6 +168,7 @@ function freebsd_boot {
function linux_boot {
echo "Booting Linux on ($bootinfo_root)..."
set oroot=$root
set root=$bootinfo_root
if [ -z "$bootinfo_kernel" ]; then
......@@ -119,6 +198,33 @@ function linux_boot {
set grubdir=/boot/grub
set cfgfile=grub.cfg
fi
#
# If we are using EFI, then we also cannot chain boot
# because the installed grub might be configured for
# BIOS. So just load up the configfile and let er rip.
#
# XXX here we don't set $prefix because we don't want
# to be loading any modules from the on-disk grub
# (again, since it is probably for BIOS). However,
# config files sometimes use $prefix and expect rational
# things to happen, bummer. Stock grub config files only
# use it for grubenv and custom.cfg. We support the former
# by loading the on-disk version before we load the
# config file. The latter we don't bother with right now.
#
elif [ $diskdrivers = efi ]; then
if [ -f /boot/grub2/grub.cfg ]; then
set grubdir=/boot/grub2
set cfgfile=grub.cfg
elif [ -f /boot/grub/grub.cfg ]; then
set grubdir=/boot/grub
set cfgfile=grub.cfg
fi
set diskroot=$root
set root=$oroot
handle_grubenv
echo "Grub config file: '($diskroot)$grubdir/$cfgfile'"
configfile ($diskroot)$grubdir/$cfgfile
fi
if [ -n "$cfgfile" ]; then
echo "Found $cfgfile on disk. Loading it..."
......@@ -269,9 +375,27 @@ if sleep --interruptible $menu_wait_timeout --verbose; then
set timeout=0
fi
menuentry "Emulab Boot" {
menuentry "Emulab Auto Boot" {
unset timeout
bootinfo -p $hdprefix
bootinfo_magic
}
menuentry "Force Disk (partition 1) Boot" {
unset timeout
bootinfo -p $hdprefix
set bootinfo_orig_root=${hdprefix}0,1
unset bootinfo_netboot_server
unset bootinfo_netboot_path
bootinfo_magic
}
menuentry "Force Admin MFS (FreeBSD) Boot" {
unset timeout
bootinfo -p $hdprefix
set bootinfo_netboot_server=$pxe_default_server
set bootinfo_orig_root=tftp,$bootinfo_netboot_server
set bootinfo_netboot_path=/tftpboot/admin_freebsd
bootinfo_magic
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment