Commit f716996b authored by David Johnson's avatar David Johnson
Browse files

Add EFI chainload: emulates firmware fallback to EFI sys part default loader.

This is only for Linux for now.  And we take the shortcut of assuming that the
"root" we are given is perhaps an EFI sys part, and if it is, and if the default
loader exists, we chainload it.
parent 0defd544
Pipeline #3437 passed with stages
in 4 minutes and 27 seconds
......@@ -43,6 +43,7 @@ insmod ufs1
insmod ufs2
insmod part_bsd
insmod part_msdos
insmod part_gpt
if [ $diskdrivers = bios ]; then
insmod biosdisk
......@@ -223,22 +224,35 @@ function linux_boot {
# 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
set defaultefiloader=
probe -s fslabel -l $root
echo "Probed for EFI System Partition: $fslabel"
if [ "$fslabel" = "EFI System" ]; then
if chainloader ($root)/efi/boot/bootx64.efi ; then
set defaultefiloader="($root)/efi/boot/bootx64.efi"
else
echo "Failed to chainload ($root)/efi/boot/bootx64.efi; falling back to BIOS"
fi
fi
set diskroot=$root
set root=$oroot
handle_grubenv
# XXX needed to boot Xen
fakebios
if [ -z "$defaultefiloader" ]; 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
# XXX needed to boot Xen
fakebios
echo "Grub config file: '($diskroot)$grubdir/$cfgfile'"
configfile ($diskroot)$grubdir/$cfgfile
fi
fi
if [ -n "$cfgfile" ]; then
echo "Found $cfgfile on disk. Loading it..."
......@@ -246,6 +260,8 @@ function linux_boot {
insmod configfile
set prefix=($root)$grubdir
configfile $grubdir/$cfgfile
elif [ -n "$defaultefiloader" ]; then
echo "Booting via EFI System Partition default loader ($defaultefiloader) ..."
else
echo "No kernel specified. Falling back to chain boot from ($root) ..."
chainloader +1
......
Supports Markdown
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