[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)



El 26/08/16 a las 09:52, Raphael Hertzog escribió:
(...)
Can you explain to me why such Installation entries are not available in
binary_syslinux?
Maybe they should be put there also?

Well, the menu entries are there by default:
$ cat share/bootloaders/isolinux/menu.cfg
menu hshift 0
menu width 82

menu title Boot menu
include stdmenu.cfg
include live.cfg
include install.cfg
menu begin advanced
	menu title Advanced options
	include stdmenu.cfg
	label mainmenu
		menu label ^Back..
		menu exit
	include advanced.cfg
menu end

menu clear
$ cat share/bootloaders/isolinux/install.cfg
label install
	menu label ^Install
	linux /install/vmlinuz
	initrd /install/initrd.gz
	append vga=788 @APPEND_INSTALL@ --- quiet

label installgui
	menu label ^Graphical install
	linux /install/gtk/vmlinuz
	initrd /install/gtk/initrd.gz
	append video=vesa:ywrap,mtrr vga=788 @APPEND_INSTALL@ --- quiet

In fact I have not found any code to drop those entries when you don't
want debian-installer in your live image... so I would rather see the opposite
problem.

So please add those entries in the grub menu.

(...)
I guess that some of those issues are not due to your changes, they
are probably longstanding issues in the generic grub code but still
it would be nice to have this fixed to have a more consistent experience
between grub and syslinux.

Well, there are some possible solutions to this problem:
(...)

3. Commit the patch as is and later on add more patches on the minimal set
needed for prettyfing this.

I'm ok for this but I would still like you to re-add the installer entries first.

Cheers,


So, here's my current uefi patch + the installation boot entries.

This recycled code from old binary_grub-pc does drop the installation entries if LB_DEBIAN_INSTALLER is false.

I don't know how to add Debian Installer to a Debian Live so I have not been able to test it.

So your feedback as user of the Debian Installer is welcome.

https://github.com/rescatux/live-build/tree/efi_support_based_on_debian_cd_rebased_10

adrian15
--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/
>From 01a9df8ce325c5df9762f0db86128614b4d3476c 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/11] 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 0624064d44ed811aec5c43fabfd7b928688ed8e1 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/11] 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 9d1a983cc8fe12966d1a2c24a6ee0cfb419b3ce5 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/11] Added new multi bootloader helper functions * Added:
 functions/bootloaders.sh . This file adds bootloader functions that are
 heavily used in efi scenarios where a bootloader can act as a first or an
 extra 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 first bootloader and grub-efi is the extra bootloader.

* Added new bootloader functions: Check_Non_First_Bootloader and Check_Non_Extra_Bootloader.

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

* Added bootloader functions: Check_First_Bootloader_Role, Check_Extra_Bootloader_Role and Check_Any_Bootloader_Role

These functions let bootloaders to force their default role in a single line.

At the same time many binary bootloaders were rewritten to make use of the new bootloader role functions explained above.

These roles were enforced:

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.
---
 functions/bootloaders.sh         | 128 +++++++++++++++++++++++++++++++++++++++
 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, 139 insertions(+), 60 deletions(-)
 create mode 100644 functions/bootloaders.sh

diff --git a/functions/bootloaders.sh b/functions/bootloaders.sh
new file mode 100644
index 0000000..1898232
--- /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_First_Bootloader ()
+{
+	EVAL_FIRST_BOOTLOADER="${1}"
+
+	if [ "${LB_FIRST_BOOTLOADER}" = "${EVAL_FIRST_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_Extra_Bootloader ()
+{
+	EVAL_EXTRA_BOOTLOADER="${1}"
+
+	if Is_First_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
+	then
+		return 1
+	else
+		if Is_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
+		then
+			return 0
+		fi
+	fi
+	return 1
+
+}
+
+Check_Non_First_Bootloader ()
+{
+	NON_FIRST_BOOTLOADER="${1}"
+
+	if Is_First_Bootloader "${NON_FIRST_BOOTLOADER}"
+	then
+		Echo_error "Bootloader: ${NON_FIRST_BOOTLOADER} not supported as a first bootloader."
+		exit 1
+	else
+		return 0
+	fi
+}
+
+
+Check_Non_Extra_Bootloader ()
+{
+	NON_EXTRA_BOOTLOADER="${1}"
+
+	if Is_Extra_Bootloader "${NON_EXTRA_BOOTLOADER}"
+	then
+		Echo_error "Bootloader: ${NON_EXTRA_BOOTLOADER} not supported as a extra bootloader."
+		exit 1
+	else
+		return 0
+	fi
+}
+
+Check_First_Bootloader_Role ()
+{
+	FIRST_BOOTLOADER_ROLE="${1}"
+	Check_Non_Extra_Bootloader "${FIRST_BOOTLOADER_ROLE}"
+
+	if Is_First_Bootloader "${FIRST_BOOTLOADER_ROLE}"
+	then
+		return 0
+	else
+		exit 0
+	fi
+
+}
+
+Check_Extra_Bootloader_Role ()
+{
+	EXTRA_BOOTLOADER_ROLE="${1}"
+	Check_Non_First_Bootloader "${EXTRA_BOOTLOADER_ROLE}"
+
+	if Is_Extra_Bootloader "${EXTRA_BOOTLOADER_ROLE}"
+	then
+		return 0
+	else
+		exit 0
+	fi
+
+}
+
+Check_Any_Bootloader_Role ()
+{
+	ANY_BOOTLOADER_ROLE="${1}"
+
+	if Is_First_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	fi
+
+	if Is_Extra_Bootloader "${ANY_BOOTLOADER_ROLE}"
+	then
+		return 0
+	fi
+
+	exit 0
+
+}
\ No newline at end of file
diff --git a/functions/defaults.sh b/functions/defaults.sh
index 334984f..deeaf2d 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 1eae93a..9252f7a 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 67dfc85..a390f61 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -149,7 +149,7 @@ esac
 #	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 c4327f61384910014b3914f125521577c97e5d79 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/11] 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 9252f7a..4909ead 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -53,52 +53,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"
@@ -134,84 +88,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*)
@@ -228,14 +106,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 58a97219c91183a1ee387cb3e450f911c5b5f183 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/11] 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 9cebad25f98976d9bb0a42fcbf76392a26503d6a 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/11] Handle multiple bootloaders properly in binary_iso .
 Force mkisofs to add an additional eltorito entry if we have more than one
 bootloader.

---
 scripts/build/binary_iso | 86 +++++++++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 34 deletions(-)

diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index a390f61..c063c70 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -107,42 +107,60 @@ then
 	XORRISO_OPTIONS="${XORRISO_OPTIONS} -V \"${LB_ISO_VOLUME}\""
 fi
 
-# Handle xorriso architecture specific options
-case "${LB_PRIMARY_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
+OLDIFS="$IFS"
+IFS=","
+BOOTLOADER_NUMBER=0
+for BOOTLOADER in ${LB_BOOTLOADERS}
+do
+	BOOTLOADER_NUMBER=$(expr ${BOOTLOADER_NUMBER} + 1)
+	# Handle xorriso architecture specific options
 
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
-		;;
+	# 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"
+			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
 
-	*)
-		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"
 
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
-- 
2.1.4

>From 7becd08e4d721ee2c187e82fba8168d76dfb33aa 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 07/11] Added 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      |   9 ++
 4 files changed, 267 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 c063c70..d4a872e 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."
-- 
2.1.4

>From ee9a6de2ccdda16cee641eb9d6faf625d48e0cfd 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 08/11] 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 deeaf2d..6b28837 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 f811656150ff5f78e55b21702688f082330f78bd 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 09/11] 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 2d61dcc53cd855d529b97a1a5a5e8a2fdb214bd2 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 10/11] 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

>From 7667d5faa775e4d65a386cb70744bc70bd6e70f5 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Fri, 26 Aug 2016 20:23:02 +0200
Subject: [PATCH 11/11] Readded Installation boot entries to grub configuration
 files.

---
 scripts/build/binary_loopback_cfg | 48 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg
index 6c8712c..45e1aec 100755
--- a/scripts/build/binary_loopback_cfg
+++ b/scripts/build/binary_loopback_cfg
@@ -69,6 +69,24 @@ Grub_live_entry ()
 	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}"
+}
+
 Grub_live_autodetect_entry ()
 {
 	local LABEL="${1}"
@@ -329,6 +347,32 @@ else # LB_BOOTLOADERS does not contain syslinux
 fi
 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
@@ -341,8 +385,8 @@ fi
 mkdir -p binary/boot/grub
 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/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|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
 
-- 
2.1.4


Reply to: