package: fai
version: 5.2
tags: patch
severity: wishlist

This patch adds EFI support to the simple configuration space.  I've
tested in my configuration space but it's possible I mangled something
transforming to the default config space.

to test,  set up a disk_config with an ESP say in the EFI_DISK class and
run something like

fai-diskimage -c DEBIAN,EFI_DISK,GRUB_EFI,AMD64  /tmp/image.raw

Then to boot
apt-get install ovmf #from non-free:-(
kvm -drive file=/usr/share/ovmf/OVMF.fd,readonly,if=pflash -snapshot -m
1024 -hda /tmp/image.raw


>From 62a518ac2cf6a6911483c55aa2a4961911fa93da Mon Sep 17 00:00:00 2001
From: Sam Hartman <hartm...@debian.org>
Date: Tue, 8 Nov 2016 08:42:01 -0500
Subject: [PATCH] Add GRUB_EFI class

Add a class to install an EFI boot loader on a GPT-partitioned system
with an ESP.

Change the class misc logic not to assert GRUB_PC if GRUB_EFI is
defined.  For now, though, prefer GRUB_PC to GRUB_EFI.
---
 examples/simple/class/60-misc             |  4 +-
 examples/simple/package_config/DEBIAN     |  3 ++
 examples/simple/scripts/GRUB_EFI/10-setup | 67 +++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100755 examples/simple/scripts/GRUB_EFI/10-setup

diff --git a/examples/simple/class/60-misc b/examples/simple/class/60-misc
index 22a30c0..9733dcb 100755
--- a/examples/simple/class/60-misc
+++ b/examples/simple/class/60-misc
@@ -1,4 +1,6 @@
 #! /bin/bash
 
 ifclass -o CENTOS SLC && exit 0
-ifclass -o I386 AMD64 && echo GRUB_PC
+if ifclass -o I386 AMD64 ; then
+    ifclass -o GRUB_PC GRUB_EFI ||echo GRUB_PC
+fi
diff --git a/examples/simple/package_config/DEBIAN 
b/examples/simple/package_config/DEBIAN
index d5730e9..bdec0d6 100644
--- a/examples/simple/package_config/DEBIAN
+++ b/examples/simple/package_config/DEBIAN
@@ -16,6 +16,9 @@ isc-dhcp-client
 PACKAGES install GRUB_PC
 grub-pc
 
+PACKAGES install GRUB_EFI
+grub-efi
+
 PACKAGES install LVM
 lvm2
 
diff --git a/examples/simple/scripts/GRUB_EFI/10-setup 
b/examples/simple/scripts/GRUB_EFI/10-setup
new file mode 100755
index 0000000..0f8d9e6
--- /dev/null
+++ b/examples/simple/scripts/GRUB_EFI/10-setup
@@ -0,0 +1,67 @@
+#! /bin/bash
+# support for GRUB version 2
+
+error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
+
+# This script assumes that fthe disk has a GPT partition table and
+# that the extended system partition (ESP) is mounted on /boot/esp.
+# When building a disk image, we don't change the NVRAM to point at
+# the boot image we made available, because the disk image is likely
+# not installed on the current system.  As a result, we force
+# installation into the removable media paths as well as the standard
+# debian path.
+
+set -a
+
+# do not set up grub during dirinstall
+if [ "$FAI_ACTION" = "dirinstall" ] ; then
+    exit 0
+fi
+# during softupdate use this file
+[ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh
+
+if [ -z "$BOOT_DEVICE" ]; then
+    exit 189
+fi
+
+# disable os-prober because of #788062
+ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true'
+
+# skip the rest, if not an initial installation
+if [ $FAI_ACTION != "install" ]; then
+    $ROOTCMD update-grub
+    exit $error
+fi
+
+$ROOTCMD grub-mkdevicemap --no-floppy
+GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE)
+
+
+# Check if RAID is used for the boot device
+if [[ $BOOT_DEVICE =~ '/dev/md' ]]; then
+    raiddev=${BOOT_DEVICE#/dev/}
+    # install grub on all members of RAID
+    for device in `LC_ALL=C perl -ne 'if(/^'$raiddev'\s.+raid\d+\s(.+)/){ 
$_=$1; s/\d+\[\d+\]//g; print }' /proc/mdstat`; do
+       echo Install grub on /dev/$device
+       $ROOTCMD grub-install --no-floppy --force-extra-removable "/dev/$device"
+    done
+
+elif [[ $GROOT =~ 'hostdisk' ]]; then
+    cat > $target/boot/grub/device.map <<EOF
+(hd0)   $BOOT_DEVICE
+EOF
+    $ROOTCMD grub-install --no-floppy --force-extra-removable 
--modules=part_gpt --no-nvram $BOOT_DEVICE
+    if [ $? -eq 0 ]; then
+        echo "Grub installed on hostdisk $BOOT_DEVICE"
+    fi
+    rm $target/boot/grub/device.map
+
+else
+    $ROOTCMD grub-install --no-floppy --modules=part_gpt "$GROOT"
+    if [ $? -eq 0 ]; then
+        echo "Grub installed on $BOOT_DEVICE = $GROOT"
+    fi
+fi
+$ROOTCMD update-grub
+
+exit $error
-- 
2.9.3

Reply via email to