[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#731709: grub-efi UEFI support based on debian-cd work complete (repos)



This new update tries to implement actual support for multiple bootloaders. It only enforces grub-legacy not to be an extra bootloader because it's current implementation in binary-iso is not compatible (without hacking) with multiple bootloaders.


* Branch were I added these last improvement / fixes: https://github.com/rescatux/live-build/tree/efi_support_based_on_debian_cd_michal * Final rebased branched: https://github.com/rescatux/live-build/tree/efi_support_based_on_debian_cd_rebased_7


Rescatux 0.40 beta 7 has been built with efi_support_based_on_debian_cd_rebased_7 branch and can be found here: http://www.supergrubdisk.org/2016/07/31/rescatux-0-40-beta-7-released/ .

As always feedback is welcome.

El 22/03/16 a las 07:18, Michal Suchanek escribió:
On 21 March 2016 at 23:06, adrian15 <adrian15sgd@gmail.com> wrote:
El 21/03/16 a las 22:19, Michal Suchanek escribió:
So please consider either

1) fixing your current patch so there is no primary or first
bootloader and all installed bootloaders are equal

2) don't pretend you add support for multiple bootloaders when you are
not wiling to do so and just and some option like --bolt-on-grub-efi
which installs grub-efi if image type and filesystem is compatible
with grub-efi and fails the build otherwise

BTW it has been pointed out already that -eltorito-alt-boot is just
separator that starts new boot entry so there are no special
secondary/extra bootloader options. Any bootloader can be
first/second/third/whatever.

Thanks

Michal


--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/
>From 723661c38b48d0617c5c660ea140edfaef4699ce Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:04:00 +0000
Subject: [PATCH 01/13] functions/default.sh : Define LB_PRIMARY_BOOTLOADER at
 the Set_defaults function which it's the right place where to do it

---
 functions/defaults.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/functions/defaults.sh b/functions/defaults.sh
index ddf4b19..334984f 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -537,6 +537,8 @@ Set_defaults ()
 		esac
 	fi
 
+	LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
+
 	# Setting checksums
 	case "${LB_MODE}" in
 		progress-linux)
@@ -845,9 +847,6 @@ Check_defaults ()
 		fi
 	fi
 
-
-	LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
-
 	if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
 	then
 		# syslinux + fat or ntfs, or extlinux + ext[234] or btrfs
-- 
2.1.4

>From a506c9c03d61f9c09d816a9e24285c599c9bacdf Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Wed, 20 Jan 2016 00:53:53 +0100
Subject: [PATCH 02/13] Remove repeated LB_PRIMARY_BOOTLOADER definition

---
 scripts/build/binary_hdd | 2 --
 scripts/build/binary_iso | 2 --
 2 files changed, 4 deletions(-)

diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index 407901a..b45b2a9 100755
--- a/scripts/build/binary_hdd
+++ b/scripts/build/binary_hdd
@@ -67,8 +67,6 @@ do
 	esac
 done
 
-LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
-
 case ${LB_PRIMARY_BOOTLOADER} in
 		syslinux)
 			case ${LB_BINARY_FILESYSTEM} in
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index d8b1553..67dfc85 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -107,8 +107,6 @@ then
 	XORRISO_OPTIONS="${XORRISO_OPTIONS} -V \"${LB_ISO_VOLUME}\""
 fi
 
-LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
-
 # Handle xorriso architecture specific options
 case "${LB_PRIMARY_BOOTLOADER}" in
 	grub)
-- 
2.1.4

>From 06ad8acdc81e6bc2b460954bae57191ddb7d238a Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:07:48 +0000
Subject: [PATCH 03/13] * Added: functions/bootloaders.sh . It has new
 bootloader functions that are heavily used in efi scenarios where a
 bootloader can act as a primary or a secondary bootloader.

Since the introduction of the new switch:

--bootloaders

you can setup it like this:

--bootloaders=syslinux,grub-efi

.

This means that syslinux is the primary bootloader and grub-efi is the secondary bootloader.

* Added new bootloader functions: Check_Non_Primary_Bootloader and Check_Non_Secondary_Bootloader.

These functions let each one of the bootloaders abort the build because
they cannot perform a role either as a primary bootloader or as a secondary bootloader.

* Added bootloader functions: Check_Primary_Bootloader_Role, Check_Secondary_Bootloader_Role and Check_Any_Bootloader_Role

These functions let bootloaders to force their default role in a single line.
---
 functions/bootloaders.sh | 128 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)
 create mode 100644 functions/bootloaders.sh

diff --git a/functions/bootloaders.sh b/functions/bootloaders.sh
new file mode 100644
index 0000000..0829903
--- /dev/null
+++ b/functions/bootloaders.sh
@@ -0,0 +1,128 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2016 Adrian Gibanel Lopez <adrian15sgd@gmail.com>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+Is_Primary_Bootloader ()
+{
+	EVAL_PRIMARY_BOOTLOADER="${1}"
+
+	if [ "${LB_PRIMARY_BOOTLOADER}" = "${EVAL_PRIMARY_BOOTLOADER}" ]
+	then
+		return 0
+	else
+		return 1
+	fi
+
+}
+
+Is_Bootloader ()
+{
+	EVAL_BOOTLOADER="${1}"
+	OLDIFS="$IFS"
+	IFS=","
+	for BOOTLOADER in ${LB_BOOTLOADERS}
+	do
+		if [ "${BOOTLOADER}" = "${EVAL_BOOTLOADER}" ]
+		then
+			IFS="$OLDIFS"
+			return 0
+		fi
+	done
+	IFS="$OLDIFS"
+	return 1
+}
+
+Is_Secondary_Bootloader ()
+{
+	EVAL_SECONDARY_BOOTLOADER="${1}"
+
+	if Is_Primary_Bootloader "${EVAL_SECONDARY_BOOTLOADER}"
+	then
+		return 1
+	else
+		if Is_Bootloader "${EVAL_SECONDARY_BOOTLOADER}"
+		then
+			return 0
+		fi
+	fi
+	return 1
+
+}
+
+Check_Non_Primary_Bootloader ()
+{
+	NON_PRIMARY_BOOTLOADER="${1}"
+
+	if Is_Primary_Bootloader "${NON_PRIMARY_BOOTLOADER}"
+	then
+		Echo_error "Bootloader: ${NON_PRIMARY_BOOTLOADER} not supported as a primary bootloader."
+		exit 1
+	else
+		return 0
+	fi
+}
+
+
+Check_Non_Secondary_Bootloader ()
+{
+	NON_SECONDARY_BOOTLOADER="${1}"
+
+	if Is_Secondary_Bootloader "${NON_SECONDARY_BOOTLOADER}"
+	then
+		Echo_error "Bootloader: ${NON_SECONDARY_BOOTLOADER} not supported as a secondary bootloader."
+		exit 1
+	else
+		return 0
+	fi
+}
+
+Check_Primary_Bootloader_Role ()
+{
+	PRIMARY_BOOTLOADER_ROLE="${1}"
+	Check_Non_Secondary_Bootloader "${PRIMARY_BOOTLOADER_ROLE}"
+
+	if Is_Primary_Bootloader "${PRIMARY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	else
+		exit 0
+	fi
+
+}
+
+Check_Secondary_Bootloader_Role ()
+{
+	SECONDARY_BOOTLOADER_ROLE="${1}"
+	Check_Non_Primary_Bootloader "${SECONDARY_BOOTLOADER_ROLE}"
+
+	if Is_Secondary_Bootloader "${SECONDARY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	else
+		exit 0
+	fi
+
+}
+
+Check_Any_Bootloader_Role ()
+{
+	ANY_BOOTLOADER_ROLE="${1}"
+
+	if Is_Primary_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	fi
+
+	if Is_Secondary_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	fi
+
+	exit 0
+
+}
\ No newline at end of file
-- 
2.1.4

>From c807d2c3350977661e9478ab84a1ccae1fe849cb Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:15:47 +0000
Subject: [PATCH 04/13] binary_loopback_cfg now renders grub.cfg by default.
 The binary parts of grub-pc are left for the original binary_grub-pc. As a
 consequence both /boot/grub/grub.cfg and /boot/grub/loopback.cfg files will
 be present in any Debian Live CD.

This might be useful to be reused from binary_grub-* bootloaders.
---
 scripts/build/binary_grub-pc      | 129 +-------------------------------------
 scripts/build/binary_loopback_cfg |  10 +--
 2 files changed, 8 insertions(+), 131 deletions(-)

diff --git a/scripts/build/binary_grub-pc b/scripts/build/binary_grub-pc
index 1eae93a..998c3d4 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -70,52 +70,6 @@ Restore_cache cache/packages.binary
 # Installing depends
 Install_package
 
-# Local functions
-Grub_live_entry ()
-{
-	LABEL="${1}"
-	KERNEL="${2}"
-	INITRD="${3}"
-	APPEND="${4}"
-
-	LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
-	LINUX_LIVE="${LINUX_LIVE}\nlinux\t\t/${KERNEL} ${INITFS:+boot=${INITFS} }config LB_BOOTAPPEND_LIVE ${APPEND}"
-	LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
-	LINUX_LIVE="${LINUX_LIVE}\n}"
-}
-
-Grub_install_entry ()
-{
-	LABEL="${1}"
-	KERNEL="${2}"
-	INITRD="${3}"
-	APPEND="${4}"
-
-	if [ "${LABEL}" != "rescue" ] && [ "${LABEL}" != "rescuegui" ]
-	then
-		APPEND="${APPEND} quiet"
-	fi
-
-	LINUX_INSTALL="${LINUX_INSTALL}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
-	LINUX_INSTALL="${LINUX_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
-	LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
-	LINUX_INSTALL="${LINUX_INSTALL}\n}"
-}
-
-if [ -e "config/bootloaders/grub-pc" ]
-then
-	# Internal local copy
-	_SOURCE="config/bootloaders/grub-pc"
-else
-	# Internal system copy
-	if [ -n "${LIVE_BUILD}" ]
-	then
-		_SOURCE="${LIVE_BUILD}/share/bootloaders/grub-pc"
-	else
-		_SOURCE="/usr/share/live/build/bootloaders/grub-pc"
-	fi
-fi
-
 case "${LB_INITRAMFS}" in
 	live-boot)
 		INITFS="live"
@@ -151,84 +105,8 @@ esac
 
 Check_multiarchitectures
 
-# Creating directory
-mkdir -p "${DESTDIR_LIVE}"
-
-# Setting boot parameters
-if [ "${LB_UNION_FILESYSTEM}" != "aufs" ]
-then
-	LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} union=${LB_UNION_FILESYSTEM}"
-fi
-
-if [ -n "${LB_NET_COW_PATH}" ]
-then
-	Echo_error "Net cow not yet supported on grub"
-	exit 1
-fi
-
-LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's|  ||')"
-
-# Assembling kernel configuration
-
-# Default entries
-DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
-DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
-DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
-
-Grub_live_entry "live" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}"
-
-if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
-then
-	Grub_live_entry "live (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_FAILSAFE}"
-fi
-
-for KERNEL in chroot/boot/vmlinuz-*
-do
-	VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
-
-	Grub_live_entry "live, kernel ${VERSION}" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}"
-	Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
-done
-
-LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
-
-# Assembling debian-installer configuration
-if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
-then
-	LINUX_LIVE="#\t \"Live\"\n${LINUX_LIVE}"
-	LINUX_INSTALL="#\t \"Installer\"\n"
-
-	VMLINUZ_DI="install/vmlinuz"
-	INITRD_DI="install/initrd.gz"
-	APPEND_DI="vga=normal"
-
-	VMLINUZ_GI="install/gtk/vmlinuz"
-	INITRD_GI="install/gtk/initrd.gz"
-	APPEND_GI="video=vesa:ywrap,mtrr vga=788"
-
-	Grub_install_entry "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
-	Grub_install_entry "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
-	Grub_install_entry "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
-	Grub_install_entry "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
-	Grub_install_entry "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
-	Grub_install_entry "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
-	Grub_install_entry "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
-	Grub_install_entry "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
-fi
-
-LINUX_INSTALL="$(/bin/echo ${LINUX_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
-
-# Assembling memtest configuration
-if [ -f "${DESTDIR_LIVE}"/memtest ]
-then
-	MEMTEST="#\t \"Other\"\n"
-	MEMTEST="${MEMTEST}\nmenuentry\t\"${LB_MEMTEST}\" {\nlinux16\t$(basename ${DESTDIR_LIVE})/memtest\n}"
-	MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
-fi
-
 # Copying templates
 mkdir -p binary/boot/grub/i386-pc
-cp -r "${_SOURCE}"/* binary/boot/grub
 
 case ${LIVE_IMAGE_TYPE} in
 	iso*)
@@ -245,14 +123,11 @@ then
 	FILES="$(echo ${FILES} | sed -e 's|chroot||g')"
 fi
 
+# We rely on: binary_loopback_cfg to generate grub.cfg and other configuration files
+
 # Copying grub
 cp ${FILES} binary/boot/grub/i386-pc
 
-sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/grub.cfg
-sed -i -e "s#LB_BOOTAPPEND_INSTALL#${LB_BOOTAPPEND_INSTALL}#" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/grub.cfg
-
-sed -i -e 's|\ $||g' binary/boot/grub/grub.cfg
-
 # Saving cache
 Save_cache cache/packages.binary
 
diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg
index 6034ddc..6031a8d 100755
--- a/scripts/build/binary_loopback_cfg
+++ b/scripts/build/binary_loopback_cfg
@@ -330,12 +330,14 @@ fi
 
 # Copying templates
 mkdir -p binary/boot/grub
-cp "${_SOURCE}"/grub.cfg binary/boot/grub/loopback.cfg
+cp "${_SOURCE}"/grub.cfg binary/boot/grub/grub.cfg
 
-sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL||" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/loopback.cfg
-sed -i -e "s#LB_BOOTAPPEND_INSTALL##" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/loopback.cfg
+sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL||" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/grub.cfg
+sed -i -e "s#LB_BOOTAPPEND_INSTALL##" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/grub.cfg
 
-sed -i -e 's|\ $||g' binary/boot/grub/loopback.cfg
+sed -i -e 's|\ $||g' binary/boot/grub/grub.cfg
+
+echo "source /boot/grub/grub.cfg" > binary/boot/grub/loopback.cfg
 
 # Creating stage file
 Create_stagefile .build/binary_loopback_cfg
-- 
2.1.4

>From f62d19f4a640bb633d1ccd6dbe6a18f36bec0d75 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:01:15 +0000
Subject: [PATCH 05/13] Stolen efi-image and grub-cpmodules from
 src:live-installer

These two scripts simplify the creation of efi images based on grub-efi.
I have decided to simply steal them. If I had to include them thanks to a source package that would have mean that an src repo would have to be defined by default.
TODO: Ask in a bug a RFE so that these two scripts are put into a binary that could be consumed by both live-installer and live-build packages.
---
 scripts/build/efi-image      | 85 ++++++++++++++++++++++++++++++++++++++++++++
 scripts/build/grub-cpmodules | 55 ++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
 create mode 100755 scripts/build/efi-image
 create mode 100755 scripts/build/grub-cpmodules

diff --git a/scripts/build/efi-image b/scripts/build/efi-image
new file mode 100755
index 0000000..724095f
--- /dev/null
+++ b/scripts/build/efi-image
@@ -0,0 +1,85 @@
+#! /bin/sh
+set -e
+
+# Copyright (C) 2010, 2011 Canonical Ltd.
+# Author: Colin Watson <cjwatson@ubuntu.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Make an EFI boot image.
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+	echo "usage: $0 OUTPUT-DIRECTORY GRUB-PLATFORM EFI-NAME NETBOOT-PREFIX"
+	exit 1
+fi
+
+outdir="$1"
+platform="$2"
+efi_name="$3"
+netboot_prefix="$4"
+
+memdisk_img=
+workdir=
+
+cleanup () {
+	[ -z "$memdisk_img" ] || rm -f "$memdisk_img"
+	[ -z "$workdir" ] || rm -rf "$workdir"
+}
+trap cleanup EXIT HUP INT QUIT TERM
+
+rm -rf "$outdir"
+mkdir -p "$outdir"
+
+memdisk_img="$(mktemp efi-image.XXXXXX)"
+workdir="$(mktemp -d efi-image.XXXXXX)"
+
+# Skeleton configuration file which finds the real boot disk.
+mkdir -p "$workdir/boot/grub"
+cat >"$workdir/boot/grub/grub.cfg" <<EOF
+search --file --set=root /.disk/info
+set prefix=(\$root)/boot/grub
+source \$prefix/$platform/grub.cfg
+EOF
+
+mkdir -p "$outdir/boot/grub/$platform"
+(for i in /usr/lib/grub/$platform/part_*.mod; do
+    i=`echo $i | sed 's?^.*/??g;s?\.mod$??g;'`
+	echo "insmod $i"
+ done; \
+ echo "source /boot/grub/grub.cfg") >"$outdir/boot/grub/$platform/grub.cfg"
+
+# Build the core image.
+(cd "$workdir"; tar -cf - boot) >"$memdisk_img"
+grub-mkimage -O "$platform" -m "$memdisk_img" \
+	-o "$workdir/boot$efi_name.efi" -p '(memdisk)/boot/grub' \
+	search iso9660 configfile normal memdisk tar part_msdos part_gpt fat
+
+grub-mkimage -O "$platform" \
+	-o "$outdir/bootnet$efi_name.efi" -p "$netboot_prefix/grub" \
+	search configfile normal efinet tftp net
+
+# Stuff it into a FAT filesystem, making it as small as possible.  24KiB
+# headroom seems to be enough; (x+31)/32*32 rounds up to multiple of 32.
+mkfs.msdos -C "$outdir/efi.img" \
+	$(( ($(stat -c %s "$workdir/boot$efi_name.efi") / 1024 + 55) \
+	    / 32 * 32 ))
+mmd -i "$outdir/efi.img" ::efi
+mmd -i "$outdir/efi.img" ::efi/boot
+mcopy -i "$outdir/efi.img" "$workdir/boot$efi_name.efi" \
+	"::efi/boot/boot$efi_name.efi"
+
+grub-cpmodules "$outdir" "$platform"
+
+exit 0
diff --git a/scripts/build/grub-cpmodules b/scripts/build/grub-cpmodules
new file mode 100755
index 0000000..437ebdf
--- /dev/null
+++ b/scripts/build/grub-cpmodules
@@ -0,0 +1,55 @@
+#! /bin/sh
+set -e
+
+# Copyright (C) 2010, 2011 Canonical Ltd.
+# Author: Colin Watson <cjwatson@ubuntu.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Copy GRUB modules.
+
+# TODO: take the modules list as parameter, and only include the needed modules, using moddeps.lst to get dependencies
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+	echo "usage: $0 OUTPUT-DIRECTORY GRUB-PLATFORM"
+	exit 1
+fi
+
+outdir="$1"
+platform="$2"
+
+# Copy over GRUB modules, except for those already built in.
+cp -a "/usr/lib/grub/$platform"/*.lst "$outdir/boot/grub/$platform/"
+for x in "/usr/lib/grub/$platform"/*.mod; do
+	# TODO: Some of these exclusions are based on knowledge of module
+	# dependencies.  It would be nice to have a way to read the module
+	# list directly out of the image.
+	case $(basename "$x" .mod) in
+	    configfile|fshelp|iso9660|memdisk|search|search_fs_file|search_fs_uuid|search_label|tar)
+		# included in boot image
+		;;
+	    affs|afs|afs_be|befs|befs_be|minix|nilfs2|sfs|zfs|zfsinfo)
+		# unnecessary filesystem modules
+		;;
+	    example_functional_test|functional_test|hello)
+		# other cruft
+		;;
+	    *)
+		cp -a "$x" "$outdir/boot/grub/$platform/"
+		;;
+	esac
+done
+
+exit 0
-- 
2.1.4

>From 4c8cd36663fdf0b8283aaeb28f22096530aee587 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Sat, 30 Jul 2016 18:47:56 +0200
Subject: [PATCH 06/13] Loop in all the bootloaders for building mkisofs
 parametres

---
 scripts/build/binary_iso | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 67dfc85..9e41873 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -107,8 +107,13 @@ then
 	XORRISO_OPTIONS="${XORRISO_OPTIONS} -V \"${LB_ISO_VOLUME}\""
 fi
 
+OLDIFS="$IFS"
+IFS=","
+for BOOTLOADER in ${LB_BOOTLOADERS}
+do
+
 # Handle xorriso architecture specific options
-case "${LB_PRIMARY_BOOTLOADER}" in
+case "${BOOTLOADER}" in
 	grub)
 		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
 		XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/stage2_eltorito"
@@ -136,7 +141,6 @@ case "${LB_PRIMARY_BOOTLOADER}" in
 
 		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
 		;;
-
 	*)
 		Echo_warning "Bootloader on your architecture not yet supported by live-build."
 		Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
@@ -144,6 +148,9 @@ case "${LB_PRIMARY_BOOTLOADER}" in
 		;;
 esac
 
+done
+IFS="$OLDIFS"
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
-- 
2.1.4

>From 0b5cb5b3961bdce2cc7e00fb93ab0c3b8ad3a972 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Sat, 30 Jul 2016 18:48:24 +0200
Subject: [PATCH 07/13] Loop in all the bootloaders for building mkisofs
 parametres (prettified)

---
 scripts/build/binary_iso | 72 +++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 9e41873..17aa3a6 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -112,41 +112,43 @@ IFS=","
 for BOOTLOADER in ${LB_BOOTLOADERS}
 do
 
-# Handle xorriso architecture specific options
-case "${BOOTLOADER}" in
-	grub)
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/stage2_eltorito"
-		XORRISO_EXCLUDE="boot/grub/stage2_eltorito"
-		;;
-
-	grub-pc)
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/grub_eltorito -J"
-		XORRISO_EXCLUDE="boot/grub/grub_eltorito"
-		;;
-
-	syslinux)
-		case "${LB_MODE}" in
-			progress-linux)
-				XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/boot.bin -c boot/boot.cat"
-				XORRISO_EXCLUDE="boot/boot.bin"
-				;;
-
-			*)
-				XORRISO_OPTIONS="${XORRISO_OPTIONS} -b isolinux/isolinux.bin -c isolinux/boot.cat"
-				XORRISO_EXCLUDE="isolinux/isolinux.bin"
-				;;
-		esac
-
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
-		;;
-	*)
-		Echo_warning "Bootloader on your architecture not yet supported by live-build."
-		Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
-		sleep 5
-		;;
-esac
+	# Handle xorriso architecture specific options
+	case "${BOOTLOADER}" in
+		grub)
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/stage2_eltorito"
+			XORRISO_EXCLUDE="boot/grub/stage2_eltorito"
+			;;
+
+		grub-pc)
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/grub_eltorito -J"
+			XORRISO_EXCLUDE="boot/grub/grub_eltorito"
+			;;
+
+		syslinux)
+			case "${LB_MODE}" in
+				progress-linux)
+					XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/boot.bin -c boot/boot.cat"
+					XORRISO_EXCLUDE="boot/boot.bin"
+					;;
+
+				*)
+					XORRISO_OPTIONS="${XORRISO_OPTIONS} -b isolinux/isolinux.bin -c isolinux/boot.cat"
+					XORRISO_EXCLUDE="isolinux/isolinux.bin"
+					;;
+			esac
+
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
+			;;
+
+
+		*)
+			Echo_warning "Bootloader on your architecture not yet supported by live-build."
+			Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
+			sleep 5
+			;;
+	esac
 
 done
 IFS="$OLDIFS"
-- 
2.1.4

>From dd30c24f9fd70ef28e2fee0b50d637e867f3dcca Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Sat, 30 Jul 2016 19:04:26 +0200
Subject: [PATCH 08/13] Force mkisofs to add an additional eltorito entry if we
 have more than one bootloader.

---
 scripts/build/binary_iso | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 17aa3a6..54bb0a9 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -109,10 +109,19 @@ fi
 
 OLDIFS="$IFS"
 IFS=","
+BOOTLOADER_NUMBER=0
 for BOOTLOADER in ${LB_BOOTLOADERS}
 do
-
+	BOOTLOADER_NUMBER=$(expr ${BOOTLOADER_NUMBER} + 1)
 	# Handle xorriso architecture specific options
+
+	# If the bootloader number is greater or equal than 2 it means
+	# we are not the first bootloader and thus we need to tell
+	# mkisosfs to add an additional eltorito entry
+	if [ ${BOOTLOADER_NUMBER} -ge 2 ]
+	then
+		XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot "
+	fi
 	case "${BOOTLOADER}" in
 		grub)
 			XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
-- 
2.1.4

>From 09f6d29ca63665210966bf4d6ef1f35da33c31ab Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:21:39 +0000
Subject: [PATCH 09/13] Support for EFI support by the means of grub-efi

This work is based on debian-cd team work and uses,
as much as possible, the same mkisofs options
than the Debian Installation CD disk does.

It assumes that /boot/grub/grub.cfg (and other design items)
is generated by: binary_loopback_cfg .

It relies on efi-image and grub-cpmodules being setup
as build scripts on live-build package.
In the future event of these two files being moved
to a binary package (they are originally from:
src: live-installer) the binary_grub-efi script would have
to be rewritten to take the new paths into account.
---
 manpages/en/lb_config.1       |   4 +-
 scripts/build/binary          |   1 +
 scripts/build/binary_grub-efi | 255 ++++++++++++++++++++++++++++++++++++++++++
 scripts/build/binary_iso      |  10 ++
 4 files changed, 268 insertions(+), 2 deletions(-)
 create mode 100755 scripts/build/binary_grub-efi

diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1
index 8e1f4f7..7e3c956 100644
--- a/manpages/en/lb_config.1
+++ b/manpages/en/lb_config.1
@@ -39,7 +39,7 @@
 .br
 	[\fB\-\-bootappend\-live\fR \fIPARAMETER\fR|\fI"PARAMETERS"\fR]
 .br
-	[\fB\-\-bootloader\fR grub|grub2|syslinux]
+	[\fB\-\-bootloader\fR grub|grub2|syslinux|grub-efi]
 .br
 	[\fB\-\-cache\fR true|false]
 .br
@@ -263,7 +263,7 @@ defines the filesystem to be used in the image type. This only has an effect if
 sets boot parameters specific to debian\-installer, if included.
 .IP "\fB\-\-bootappend\-live\fR \fIPARAMETER\fR|""\fIPARAMETERS\fR""" 4
 sets boot parameters specific to debian\-live. A complete list of boot parameters can be found in the \fIlive\-boot\fR(7) and \fIlive\-config\fR(7) manual pages.
-.IP "\fB\-\-bootloader\fR grub|grub2|syslinux" 4
+.IP "\fB\-\-bootloader\fR grub|grub2|syslinux|grub-efi" 4
 defines which bootloader is being used in the generated image. This has only an effect if the selected binary image type does allow to choose the bootloader. For example, if you build a iso, always syslinux (or more precise, isolinux) is being used. Also note that some combinations of binary images types and bootloaders may be possible but live\-build does not support them yet. \fBlb config\fR will fail to create such a not yet supported configuration and give a explanation about it. For hdd images on amd64 and i386, the default is syslinux.
 .IP "\fB\-\-cache\fR true|false" 4
 defines globally if any cache should be used at all. Different caches can be controlled through the their own options.
diff --git a/scripts/build/binary b/scripts/build/binary
index 56c7bf8..7b0d743 100755
--- a/scripts/build/binary
+++ b/scripts/build/binary
@@ -69,6 +69,7 @@ lb binary_loadlin ${@}
 lb binary_win32-loader ${@}
 lb binary_includes ${@}
 lb binary_hooks ${@}
+lb binary_grub-efi ${@}
 lb binary_checksums ${@}
 
 if [ "${LB_BUILD_WITH_CHROOT}" != "true" ]
diff --git a/scripts/build/binary_grub-efi b/scripts/build/binary_grub-efi
new file mode 100755
index 0000000..384135b
--- /dev/null
+++ b/scripts/build/binary_grub-efi
@@ -0,0 +1,255 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2016 Adrian Gibanel Lopez <adrian15sgd@gmail.com>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'prepares and installs Grub based EFI support into binary')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
+Set_defaults
+
+Check_Any_Bootloader_Role "grub-efi"
+
+Echo_message "Begin preparing Grub based EFI support..."
+
+# Requiring stage file
+Require_stagefile .build/config .build/bootstrap
+
+# Checking stage file
+Check_stagefile .build/binary_grub-efi
+
+# Checking lock file
+Check_lockfile .lock
+
+# Creating lock file
+Create_lockfile .lock
+
+# Check architecture
+Check_architectures amd64 i386
+Check_crossarchitectures
+
+case "${LB_ARCHITECTURES}" in
+	amd64)
+		_EFI_TYPE=efi64
+		;;
+	i386)
+		_EFI_TYPE=efi32
+		;;
+	*)
+		echo "ERROR: can't provide EFI boot support to architecture ${LB_ARCHITECTURES}" >&2
+		exit 1
+		;;
+esac
+
+
+# Checking depends
+case "${LB_BUILD_WITH_CHROOT}" in
+	true)
+		_CHROOT_DIR=""
+		_SYSLINUX_EFI_DIR="chroot/usr/lib/SYSLINUX.EFI/$_EFI_TYPE"
+		_SYSLINUX_COMMON_DIR="chroot/usr/lib/syslinux/modules/$_EFI_TYPE"
+
+		Check_package chroot /usr/lib/grub/x86_64-efi/configfile.mod grub-efi-amd64-bin
+		Check_package chroot /usr/lib/grub/i386-efi/configfile.mod grub-efi-ia32-bin
+		Check_package chroot /usr/bin/grub-mkimage grub-common
+		Check_package chroot /usr/bin/mcopy mtools
+		Check_package chroot /sbin/mkfs.msdos dosfstools
+		;;
+
+	false)
+		_CHROOT_DIR="chroot"
+
+		if [ ! -e /usr/lib/grub/x86_64-efi ]
+		then
+			# grub-efi-amd64-bin
+			Echo_error "/usr/lib/grub/x86_64-efi - no such directory"
+			exit 1
+		fi
+
+		if [ ! -e /usr/lib/grub/i386-efi ]
+		then
+			# grub-efi-ia32-bin
+			Echo_error "/usr/lib/grub/i386-efi - no such directory"
+			exit 1
+		fi
+
+		if [ ! -e /usr/bin/grub-mkimage ]
+		then
+			# grub-common
+			Echo_error "/usr/bin/grub-mkimage - no such file."
+			exit 1
+		fi
+
+		if [ ! -e /usr/bin/mcopy ]
+		then
+			# mtools
+			Echo_error "/usr/bin/mcopy - no such file."
+			exit 1
+		fi
+
+		if [ ! -e /sbin/mkfs.msdos ]
+		then
+			# dosfstools
+			Echo_error "/sbin/mkfs.msdos - no such file."
+			exit 1
+		fi
+		;;
+esac
+
+
+
+
+case "${LB_INITRAMFS}" in
+	live-boot)
+		INITFS="live"
+		;;
+
+	*)
+		INITFS=""
+		;;
+esac
+
+# Setting destination directory
+case "${LIVE_IMAGE_TYPE}" in
+	iso*|tar)
+		case "${LB_INITRAMFS}" in
+			live-boot)
+				DESTDIR_LIVE="binary/live"
+				;;
+
+			*)
+				DESTDIR_LIVE="binary/live"
+				;;
+		esac
+
+		DESTDIR_INSTALL="binary/install"
+		;;
+
+	hdd*|netboot)
+		Echo_warning "Bootloader in this image type not yet supported by live-build."
+		Echo_warning "This would produce a not bootable image, aborting (FIXME)."
+		exit 1
+	;;
+esac
+
+# Restoring cache
+Restore_cache cache/packages.binary
+
+# Installing depends
+Install_package
+
+# Cleanup files that we generate
+rm -rf binary/boot/efi.img binary/boot/grub/i386-efi/ binary/boot/grub/x86_64-efi
+
+# This is workaround till both efi-image and grub-cpmodules are put into a binary package
+case "${LB_BUILD_WITH_CHROOT}" in
+        true)
+		if [ ! -e "${LIVE_BUILD}" ] ; then
+			LIVE_BUILD_PATH="/usr/lib/live/build"
+		else
+			LIVE_BUILD_PATH="${LIVE_BUILD}/scripts/build"
+		fi
+		mkdir -p chroot/${LIVE_BUILD_PATH}
+		cp "${LIVE_BUILD_PATH}/efi-image" "chroot/${LIVE_BUILD_PATH}"
+		cp "${LIVE_BUILD_PATH}/grub-cpmodules" "chroot/${LIVE_BUILD_PATH}"
+        ;;
+esac
+#####
+cat >binary.sh <<END
+#!/bin/sh
+
+set -e
+
+PRE_EFI_IMAGE_PATH="${PATH}"
+if [ ! -e "${LIVE_BUILD}" ] ; then
+	LIVE_BUILD_PATH="/usr/lib/live/build"
+else
+	LIVE_BUILD_PATH="${LIVE_BUILD}/scripts/build"
+fi
+
+PATH="${PATH}:\${LIVE_BUILD_PATH}" # Make sure grub-cpmodules is used as if it was installed in the system
+
+"\${LIVE_BUILD_PATH}/efi-image" "${_CHROOT_DIR}/grub-efi-temp-x86_64-efi/" "x86_64-efi" "x64" "debian-live/amd64"
+mkdir -p ${_CHROOT_DIR}/grub-efi-temp/efi/boot
+mcopy -n -i ${_CHROOT_DIR}/grub-efi-temp-x86_64-efi/efi.img '::efi/boot/boot*.efi' ${_CHROOT_DIR}/grub-efi-temp/efi/boot
+cp -r "${_CHROOT_DIR}"/grub-efi-temp-x86_64-efi/* "${_CHROOT_DIR}/grub-efi-temp/"
+
+"\${LIVE_BUILD_PATH}/efi-image" "${_CHROOT_DIR}/grub-efi-temp-i386-efi/" "i386-efi" "ia32" "debian-live/i386"
+PATH="\${PRE_EFI_IMAGE_PATH}"
+mkdir -p ${_CHROOT_DIR}/grub-efi-temp/efi/boot
+mcopy -n -i ${_CHROOT_DIR}/grub-efi-temp-i386-efi/efi.img '::efi/boot/boot*.efi' ${_CHROOT_DIR}/grub-efi-temp/efi/boot
+cp -r "${_CHROOT_DIR}"/grub-efi-temp-i386-efi/* "${_CHROOT_DIR}/grub-efi-temp/"
+
+# The code below is adapted from tools/boot/jessie/boot-x86
+# in debian-cd
+
+# Stuff the EFI boot files into a FAT filesystem, making it as
+# small as possible.  24KiB headroom seems to be enough;
+# (x+31)/32*32 rounds up to multiple of 32.
+# This is the same as in efi-image, but we need to redo it here in
+# the case of a multi-arch amd64/i386 image
+
+size=0
+for file in ${_CHROOT_DIR}/grub-efi-temp/efi/boot/boot*.efi; do
+	size=\$((\$size + \$(stat -c %s "\$file")))
+done
+
+blocks=\$(((\$size / 1024 + 55) / 32 * 32 ))
+
+rm -f ${_CHROOT_DIR}/grub-efi-temp/boot/grub/efi.img
+mkfs.msdos -C "${_CHROOT_DIR}/grub-efi-temp/boot/grub/efi.img" \$blocks >/dev/null
+mmd -i "${_CHROOT_DIR}/grub-efi-temp/boot/grub/efi.img" ::efi
+mmd -i "${_CHROOT_DIR}/grub-efi-temp/boot/grub/efi.img" ::efi/boot
+mcopy -o -i "${_CHROOT_DIR}/grub-efi-temp/boot/grub/efi.img" ${_CHROOT_DIR}/grub-efi-temp/efi/boot/boot*.efi \
+	"::efi/boot"
+END
+
+case "${LB_BUILD_WITH_CHROOT}" in
+        true)
+			mv binary.sh chroot/
+			Chroot chroot "sh binary.sh"
+			rm -f chroot/binary.sh
+
+			# Saving cache
+			Save_cache cache/packages.binary
+
+			# Removing depends
+			Remove_package
+			;;
+
+		false)
+			sh binary.sh
+			rm -f binary.sh
+			;;
+esac
+
+# Remove unnecessary files
+rm -f chroot/grub-efi-temp/bootnetia32.efi
+rm -f chroot/grub-efi-temp/bootnetx64.efi
+
+mkdir -p binary
+cp -r chroot/grub-efi-temp/* binary/
+rm -rf chroot/grub-efi-temp-x86_64-efi
+rm -rf chroot/grub-efi-temp-i386-efi
+rm -rf chroot/grub-efi-temp
+
+# We rely on: binary_loopback_cfg to generate grub.cfg and other configuration files
+
+# Creating stage file
+Create_stagefile .build/binary_grub-efi
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 54bb0a9..9ebf7bf 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -151,6 +151,15 @@ do
 			XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
 			;;
 
+		grub-efi)
+			if [ -e binary/boot/grub/efi.img ]
+			then
+				XORRISO_OPTIONS="${XORRISO_OPTIONS} -e boot/grub/efi.img -no-emul-boot"
+				XORRISO_OPTIONS="${XORRISO_OPTIONS} -isohybrid-gpt-basdat -isohybrid-apm-hfsplus"
+			else
+				Echo "No EFI boot code to include in the ISO"
+			fi
+			;;
 
 		*)
 			Echo_warning "Bootloader on your architecture not yet supported by live-build."
@@ -162,6 +171,7 @@ do
 done
 IFS="$OLDIFS"
 
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
-- 
2.1.4

>From 568eea23270c6db48547274ffc81be556ec1cfff Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 21 Mar 2016 15:36:19 +0100
Subject: [PATCH 10/13] defaults.sh LB_BOOTLOADER updated to be: LB_BOOTLOADERS
 in incompatible warning

---
 functions/defaults.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/functions/defaults.sh b/functions/defaults.sh
index 334984f..3d310df 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -854,7 +854,7 @@ Check_defaults ()
 			fat*|ntfs|ext[234]|btrfs)
 				;;
 			*)
-				Echo_warning "You have selected values of LB_BOOTLOADER and LB_BINARY_FILESYSTEM which are incompatible - the syslinux family only support FAT, NTFS, ext[234] or btrfs filesystems."
+				Echo_warning "You have selected values of LB_BOOTLOADERS and LB_BINARY_FILESYSTEM which are incompatible - the syslinux family only support FAT, NTFS, ext[234] or btrfs filesystems."
 				;;
 		esac
 	fi
-- 
2.1.4

>From 0ae9f525ada67e7ed23adb1663e4c9437925bab2 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:13:37 +0000
Subject: [PATCH 11/13] Many binary bootloaders were rewritten to make use of
 the new bootloader role functions.

Since the introduction of the new switch:

--bootloaders

you can setup it like this:

--bootloaders=syslinux,grub-efi

.

This means that syslinux is the first bootloader and grub-efi is an extra bootloader.

This commit modifies many of these bootloaders so that these roles for these binaries was enforced:

binary_grub-efi : Either first or extra bootloader
binary_grub-legacy : First bootloader
binary_grub-pc : Either first or extra bootloader
binary_syslinux : Either first or extra bootloader

If a bootloader is tried to be used in a role that it's not meant to be used then the build fails because that might lead to a non-bootable system.

Conflicts:
	scripts/build/binary_grub-efi
	scripts/build/binary_iso
---
 functions/bootloaders.sh         | 50 ++++++++++++++++++++--------------------
 functions/defaults.sh            |  6 ++---
 scripts/build/binary_grub-legacy | 17 +-------------
 scripts/build/binary_grub-pc     | 19 +--------------
 scripts/build/binary_hdd         |  8 +++----
 scripts/build/binary_iso         |  2 +-
 scripts/build/binary_syslinux    | 19 +--------------
 7 files changed, 36 insertions(+), 85 deletions(-)

diff --git a/functions/bootloaders.sh b/functions/bootloaders.sh
index 0829903..1898232 100644
--- a/functions/bootloaders.sh
+++ b/functions/bootloaders.sh
@@ -7,11 +7,11 @@
 ## This is free software, and you are welcome to redistribute it
 ## under certain conditions; see COPYING for details.
 
-Is_Primary_Bootloader ()
+Is_First_Bootloader ()
 {
-	EVAL_PRIMARY_BOOTLOADER="${1}"
+	EVAL_FIRST_BOOTLOADER="${1}"
 
-	if [ "${LB_PRIMARY_BOOTLOADER}" = "${EVAL_PRIMARY_BOOTLOADER}" ]
+	if [ "${LB_FIRST_BOOTLOADER}" = "${EVAL_FIRST_BOOTLOADER}" ]
 	then
 		return 0
 	else
@@ -37,15 +37,15 @@ Is_Bootloader ()
 	return 1
 }
 
-Is_Secondary_Bootloader ()
+Is_Extra_Bootloader ()
 {
-	EVAL_SECONDARY_BOOTLOADER="${1}"
+	EVAL_EXTRA_BOOTLOADER="${1}"
 
-	if Is_Primary_Bootloader "${EVAL_SECONDARY_BOOTLOADER}"
+	if Is_First_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
 	then
 		return 1
 	else
-		if Is_Bootloader "${EVAL_SECONDARY_BOOTLOADER}"
+		if Is_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
 		then
 			return 0
 		fi
@@ -54,13 +54,13 @@ Is_Secondary_Bootloader ()
 
 }
 
-Check_Non_Primary_Bootloader ()
+Check_Non_First_Bootloader ()
 {
-	NON_PRIMARY_BOOTLOADER="${1}"
+	NON_FIRST_BOOTLOADER="${1}"
 
-	if Is_Primary_Bootloader "${NON_PRIMARY_BOOTLOADER}"
+	if Is_First_Bootloader "${NON_FIRST_BOOTLOADER}"
 	then
-		Echo_error "Bootloader: ${NON_PRIMARY_BOOTLOADER} not supported as a primary bootloader."
+		Echo_error "Bootloader: ${NON_FIRST_BOOTLOADER} not supported as a first bootloader."
 		exit 1
 	else
 		return 0
@@ -68,25 +68,25 @@ Check_Non_Primary_Bootloader ()
 }
 
 
-Check_Non_Secondary_Bootloader ()
+Check_Non_Extra_Bootloader ()
 {
-	NON_SECONDARY_BOOTLOADER="${1}"
+	NON_EXTRA_BOOTLOADER="${1}"
 
-	if Is_Secondary_Bootloader "${NON_SECONDARY_BOOTLOADER}"
+	if Is_Extra_Bootloader "${NON_EXTRA_BOOTLOADER}"
 	then
-		Echo_error "Bootloader: ${NON_SECONDARY_BOOTLOADER} not supported as a secondary bootloader."
+		Echo_error "Bootloader: ${NON_EXTRA_BOOTLOADER} not supported as a extra bootloader."
 		exit 1
 	else
 		return 0
 	fi
 }
 
-Check_Primary_Bootloader_Role ()
+Check_First_Bootloader_Role ()
 {
-	PRIMARY_BOOTLOADER_ROLE="${1}"
-	Check_Non_Secondary_Bootloader "${PRIMARY_BOOTLOADER_ROLE}"
+	FIRST_BOOTLOADER_ROLE="${1}"
+	Check_Non_Extra_Bootloader "${FIRST_BOOTLOADER_ROLE}"
 
-	if Is_Primary_Bootloader "${PRIMARY_BOOTLOADER_ROLE}"
+	if Is_First_Bootloader "${FIRST_BOOTLOADER_ROLE}"
 	then
 		return 0
 	else
@@ -95,12 +95,12 @@ Check_Primary_Bootloader_Role ()
 
 }
 
-Check_Secondary_Bootloader_Role ()
+Check_Extra_Bootloader_Role ()
 {
-	SECONDARY_BOOTLOADER_ROLE="${1}"
-	Check_Non_Primary_Bootloader "${SECONDARY_BOOTLOADER_ROLE}"
+	EXTRA_BOOTLOADER_ROLE="${1}"
+	Check_Non_First_Bootloader "${EXTRA_BOOTLOADER_ROLE}"
 
-	if Is_Secondary_Bootloader "${SECONDARY_BOOTLOADER_ROLE}"
+	if Is_Extra_Bootloader "${EXTRA_BOOTLOADER_ROLE}"
 	then
 		return 0
 	else
@@ -113,12 +113,12 @@ Check_Any_Bootloader_Role ()
 {
 	ANY_BOOTLOADER_ROLE="${1}"
 
-	if Is_Primary_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	if Is_First_Bootloader "${ANY_BOOTLOADER_ROLE}"
 	then
 		return 0
 	fi
 
-	if Is_Secondary_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	if Is_Extra_Bootloader "${ANY_BOOTLOADER_ROLE}"
 	then
 		return 0
 	fi
diff --git a/functions/defaults.sh b/functions/defaults.sh
index 3d310df..6b28837 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -537,7 +537,7 @@ Set_defaults ()
 		esac
 	fi
 
-	LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
+	LB_FIRST_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
 
 	# Setting checksums
 	case "${LB_MODE}" in
@@ -847,7 +847,7 @@ Check_defaults ()
 		fi
 	fi
 
-	if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
+	if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
 	then
 		# syslinux + fat or ntfs, or extlinux + ext[234] or btrfs
 		case "${LB_BINARY_FILESYSTEM}" in
@@ -861,7 +861,7 @@ Check_defaults ()
 
 	case "${LIVE_IMAGE_TYPE}" in
 		hdd*)
-			case "${LB_PRIMARY_BOOTLOADER}" in
+			case "${LB_FIRST_BOOTLOADER}" in
 				grub)
 					Echo_error "You have selected a combination of bootloader and image type that is currently not supported by live-build. Please use either another bootloader or a different image type."
 					exit 1
diff --git a/scripts/build/binary_grub-legacy b/scripts/build/binary_grub-legacy
index f885c00..93d9b9e 100755
--- a/scripts/build/binary_grub-legacy
+++ b/scripts/build/binary_grub-legacy
@@ -24,22 +24,7 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-FOUND_MYSELF=""
-IFS=","
-for BOOTLOADER in ${LB_BOOTLOADERS}
-do
-
-       case ${BOOTLOADER} in
-               "grub-legacy" )
-                       FOUND_MYSELF="True"
-                       break ;;
-       esac
-
-done
-
-if [ -z ${FOUND_MYSELF} ] ; then
-        exit 0
-fi
+Check_First_Bootloader_Role "grub-legacy"
 
 Echo_message "Begin installing grub-legacy..."
 
diff --git a/scripts/build/binary_grub-pc b/scripts/build/binary_grub-pc
index 998c3d4..4909ead 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -24,24 +24,7 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-FOUND_MYSELF=""
-OLDIFS="$IFS"
-IFS=","
-for BOOTLOADER in ${LB_BOOTLOADERS}
-do
-
-       case ${BOOTLOADER} in
-               "grub-pc" )
-                       FOUND_MYSELF="True"
-                       break ;;
-       esac
-
-done
-IFS="$OLDIFS"
-
-if [ -z ${FOUND_MYSELF} ] ; then
-        exit 0
-fi
+Check_Any_Bootloader_Role "grub-pc"
 
 Echo_message "Begin installing grub-pc..."
 
diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index b45b2a9..400403c 100755
--- a/scripts/build/binary_hdd
+++ b/scripts/build/binary_hdd
@@ -67,7 +67,7 @@ do
 	esac
 done
 
-case ${LB_PRIMARY_BOOTLOADER} in
+case ${LB_FIRST_BOOTLOADER} in
 		syslinux)
 			case ${LB_BINARY_FILESYSTEM} in
 				fat*|ntfs)
@@ -182,7 +182,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
 		Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
 
-		if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
+		if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
 		then
 			dd if=chroot/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1
 		fi
@@ -202,7 +202,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		parted -s "${FREELO}" set 1 boot on || true
 		parted -s "${FREELO}" set 1 lba off || true
 
-		if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
+		if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
 		then
 			dd if=/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1
 		fi
@@ -268,7 +268,7 @@ cp -T ${CP_OPTIONS} binary/ chroot/binary.tmp
 
 FIXME()
 {
-if [ "${LB_PRIMARY_BOOTLOADER}" = "grub" ]
+if [ "${LB_FIRST_BOOTLOADER}" = "grub" ]
 then
 
 cat > chroot/grub.sh << EOF
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 9ebf7bf..9ae8997 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -177,7 +177,7 @@ IFS="$OLDIFS"
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
 #fi
 
-if [ "${LB_PRIMARY_BOOTLOADER}" = "grub-pc" ]
+if [ "${LB_FIRST_BOOTLOADER}" = "grub-pc" ]
 then
 
 cat > binary.sh << EOF
diff --git a/scripts/build/binary_syslinux b/scripts/build/binary_syslinux
index 66c14a0..1a442d7 100755
--- a/scripts/build/binary_syslinux
+++ b/scripts/build/binary_syslinux
@@ -24,24 +24,7 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-FOUND_MYSELF=""
-OLDIFS="$IFS"
-IFS=","
-for BOOTLOADER in ${LB_BOOTLOADERS}
-do
-
-       case ${BOOTLOADER} in
-               "syslinux" )
-                       FOUND_MYSELF="True"
-                       break ;;
-       esac
-
-done
-IFS="$OLDIFS"
-
-if [ -z ${FOUND_MYSELF} ] ; then
-        exit 0
-fi
+Check_Any_Bootloader_Role "syslinux"
 
 Echo_message "Begin installing syslinux..."
 
-- 
2.1.4

>From f9e919ca8a38b28a4464173414ce0a54a637a303 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 18 Jan 2016 03:29:30 +0000
Subject: [PATCH 12/13] Make: syslinux,grub-efi the default bootloaders because
 UEFI is getting widely adopted but BIOS support is still needed.

---
 functions/defaults.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/functions/defaults.sh b/functions/defaults.sh
index 6b28837..90921d7 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -532,7 +532,7 @@ Set_defaults ()
 	then
 		case "${LB_ARCHITECTURES}" in
 			amd64|i386)
-				LB_BOOTLOADERS="syslinux"
+				LB_BOOTLOADERS="syslinux,grub-efi"
 				;;
 		esac
 	fi
-- 
2.1.4

>From 9d896ace64daca3458b31f8cb2e5672d2d652b98 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Mon, 21 Mar 2016 19:44:04 +0100
Subject: [PATCH 13/13] Force the use of insmod all_video in grub.cfg so that
 we do not boot in blind mode in UEFI mode.

---
 scripts/build/binary_loopback_cfg | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg
index 6031a8d..6c8712c 100755
--- a/scripts/build/binary_loopback_cfg
+++ b/scripts/build/binary_loopback_cfg
@@ -87,6 +87,13 @@ Grub_live_autodetect_entry ()
 	LINUX_LIVE="${LINUX_LIVE}\n}"
 }
 
+Grub_live_video ()
+{
+
+	LINUX_LIVE="${LINUX_LIVE}\ninsmod all_video\n"
+
+}
+
 if [ -e "config/bootloaders/grub-pc" ]
 then
 	# Internal local copy
@@ -201,6 +208,8 @@ do
 done
 IFS="$OLDIFS"
 
+Grub_live_video
+
 if [ -z ${FOUND_SYSLINUX} ]
 then
 
-- 
2.1.4


Reply to: