[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 21/03/16 a las 22:19, Michal Suchanek escribió:
Hello,

On 21 March 2016 at 21:09, adrian15 <adrian15sgd@gmail.com> wrote:


The branch which include specifically the commits I attach here as patches
is:

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

.

About the variable names issue: I think the new terms: first and extra are
ok because they are not implying some sort of rank while explaining what's
the difference between them. Also, notice, that these are internal variables
which final user of live-build does not see. I think we should focus on
other aspects of my patch if there are more problems for it.

The problem is not with the name of the variable.

The problem is that you use it at all. In most places when you check
for primary or secondary bootloader you should just loop all
bootloaders and check each. In fact, in the previous batch of patches
I found no place where checking for primary or secondary bootloader
made any sense.


If you think that the way bootloaders is currently managed by live-build is
wrong please file up a new bug and send there your patch with your
improvements so that it's get discussed.

The bootloader support in live-build is limited. With your patches it
becomes wrong. eg. compatibility of bootloader with selected
filesystem and image type is only checked for first bootloader and EFI
support is added only when grub-efi extra bootloader but not when it
is the first bootloader.

This is not fixed by renaming the variables.

Thanks

Michal

Ok, what about now? Actually from my former email I only added one additional patch (0011) with some sort of modular support for bootloaders.

There probably needs some work to be done on binary_hdd but I first wanted to gather information on what to improve on this last patch.


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


adrian15
--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/
>From ff8206aea1985760dfea9ec94b93686a242f137e 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 f895f653dffb614639fa37a318e62c51104a4b2d 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 d0db382..0c9c5af 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 9175a624b7d88bfea80448a5a1e6ac1b11d651aa 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: 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 bbc15f1735441c0d696d0edb83b8c56265b4754c 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 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 89671984f8a6188945602717d110ff3595962a9b 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 e23d5c2ee7533d0c4ce9ea06435186a00f2d5faa 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 06/11] 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      |  11 ++
 4 files changed, 269 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..faf3420
--- /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_Secondary_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 67dfc85..e716034 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -144,6 +144,17 @@ case "${LB_PRIMARY_BOOTLOADER}" in
 		;;
 esac
 
+if Is_Secondary_Bootloader "grub-efi"
+then
+	if [ -e binary/boot/grub/efi.img ]
+	then
+		XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot -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
+fi
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
-- 
2.1.4

>From bacd34a62f86545942d3e7c272b1deaf172a3485 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 07/11] defaults.sh LB_BOOTLOADER updated to be: LB_BOOTOADERS
 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 caa3d07969f4805c885de85ce7bca09eb8d5eed6 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 08/11] 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 the current roles for these binaries was enforced:

binary_grub-efi : Extra bootloader
binary_grub-legacy : First bootloader
binary_grub-pc : First bootloader
binary_syslinux : First bootloader
binary_syslinux-efi : 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         | 50 ++++++++++++++++++++--------------------
 functions/defaults.sh            |  6 ++---
 scripts/build/binary_grub-efi    |  2 +-
 scripts/build/binary_grub-legacy | 17 +-------------
 scripts/build/binary_grub-pc     | 19 +--------------
 scripts/build/binary_hdd         |  8 +++----
 scripts/build/binary_iso         |  6 ++---
 scripts/build/binary_syslinux    | 19 +--------------
 8 files changed, 39 insertions(+), 88 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-efi b/scripts/build/binary_grub-efi
index faf3420..81766d1 100755
--- a/scripts/build/binary_grub-efi
+++ b/scripts/build/binary_grub-efi
@@ -24,7 +24,7 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-Check_Secondary_Bootloader_Role "grub-efi"
+Check_Extra_Bootloader_Role "grub-efi"
 
 Echo_message "Begin preparing Grub based EFI support..."
 
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..12e77be 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_First_Bootloader_Role "grub-pc"
 
 Echo_message "Begin installing grub-pc..."
 
diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index 0c9c5af..88cd0d8 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/SYSLINUX/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/SYSLINUX/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 e716034..305a4ce 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -108,7 +108,7 @@ then
 fi
 
 # Handle xorriso architecture specific options
-case "${LB_PRIMARY_BOOTLOADER}" in
+case "${LB_FIRST_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"
@@ -138,7 +138,7 @@ case "${LB_PRIMARY_BOOTLOADER}" in
 		;;
 
 	*)
-		Echo_warning "Bootloader on your architecture not yet supported by live-build."
+		Echo_warning "Bootloader on your architecture not yet supported by live-build as the primary bootloader."
 		Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
 		sleep 5
 		;;
@@ -160,7 +160,7 @@ fi
 #	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 024b563..a58994b 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_First_Bootloader_Role "syslinux"
 
 Echo_message "Begin installing syslinux..."
 
-- 
2.1.4

>From e90a3b72ef1f518e668e5defc7ad45be5401d976 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 702c58e59ca2cd5c6d2917975e8fffe01db8dda3 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 ca82006432bc07c62f1a3a6cd5d81fb499366844 Mon Sep 17 00:00:00 2001
From: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date: Tue, 22 Mar 2016 01:23:22 +0100
Subject: [PATCH 11/11] * binary_grub-efi works as a first bootloader and as an
 extra bootloader * Added include_* scripts to make bootloader support modular

---
 functions/defaults.sh             | 29 +++---------
 scripts/build/binary_grub-efi     |  2 +-
 scripts/build/binary_iso          | 93 +++++++++------------------------------
 scripts/build/include_grub-efi    | 61 +++++++++++++++++++++++++
 scripts/build/include_grub-legacy | 58 ++++++++++++++++++++++++
 scripts/build/include_grub-pc     | 85 +++++++++++++++++++++++++++++++++++
 scripts/build/include_syslinux    | 69 +++++++++++++++++++++++++++++
 7 files changed, 303 insertions(+), 94 deletions(-)
 create mode 100755 scripts/build/include_grub-efi
 create mode 100755 scripts/build/include_grub-legacy
 create mode 100755 scripts/build/include_grub-pc
 create mode 100755 scripts/build/include_syslinux

diff --git a/functions/defaults.sh b/functions/defaults.sh
index 90921d7..065f904 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -847,28 +847,13 @@ Check_defaults ()
 		fi
 	fi
 
-	if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
-	then
-		# syslinux + fat or ntfs, or extlinux + ext[234] or btrfs
-		case "${LB_BINARY_FILESYSTEM}" in
-			fat*|ntfs|ext[234]|btrfs)
-				;;
-			*)
-				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
-
-	case "${LIVE_IMAGE_TYPE}" in
-		hdd*)
-			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
-					;;
-			esac
-			;;
-	esac
+	[ -d "${LIVE_BUILD}" ] && INCLUDED_PATH="${LIVE_BUILD}/scripts/build" || INCLUDED_PATH="/usr/lib/live/build"
+	for ninclude_file in "${INCLUDED_PATH}"/include_*
+	do
+		. "${ninclude_file}"
+		${INCLUDED_PREFIX}_check_binary_filesystem
+		${INCLUDED_PREFIX}_check_image_type
+	done
 
 	if [ "$(echo \"${LB_ISO_APPLICATION}\" | wc -c)" -gt 128 ]
 	then
diff --git a/scripts/build/binary_grub-efi b/scripts/build/binary_grub-efi
index 81766d1..384135b 100755
--- a/scripts/build/binary_grub-efi
+++ b/scripts/build/binary_grub-efi
@@ -24,7 +24,7 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-Check_Extra_Bootloader_Role "grub-efi"
+Check_Any_Bootloader_Role "grub-efi"
 
 Echo_message "Begin preparing Grub based EFI support..."
 
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 305a4ce..b28cf18 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -107,90 +107,41 @@ then
 	XORRISO_OPTIONS="${XORRISO_OPTIONS} -V \"${LB_ISO_VOLUME}\""
 fi
 
-# Handle xorriso architecture specific options
-case "${LB_FIRST_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"
-		;;
+PRE_INCLUDE_XORRISO_OPTIONS="${XORRISO_OPTIONS}"
 
-	*)
-		Echo_warning "Bootloader on your architecture not yet supported by live-build as the primary bootloader."
-		Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
-		sleep 5
-		;;
-esac
+# Handle xorriso architecture specific options
+[ -d "${LIVE_BUILD}" ] && INCLUDED_PATH="${LIVE_BUILD}/scripts/build" || INCLUDED_PATH="/usr/lib/live/build"
+for ninclude_file in "${INCLUDED_PATH}"/include_*
+do
+	. "${ninclude_file}"
+	${INCLUDED_PREFIX}_xorriso_first_bootloader_architecture_options
+done
 
-if Is_Secondary_Bootloader "grub-efi"
+if [ "${PRE_INCLUDE_XORRISO_OPTIONS}" = "${XORRISO_OPTIONS}" ]
 then
-	if [ -e binary/boot/grub/efi.img ]
-	then
-		XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot -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 as the primary bootloader."
+	Echo_warning "This will produce a most likely not bootable image (Continuing in 5 seconds)."
+	sleep 5
 fi
 
+for ninclude_file in "${INCLUDED_PATH}"/include_*
+do
+	. "${ninclude_file}"
+	${INCLUDED_PREFIX}_xorriso_extra_bootloader_architecture_options
+done
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
 #fi
 
-if [ "${LB_FIRST_BOOTLOADER}" = "grub-pc" ]
-then
-
-cat > binary.sh << EOF
-#!/bin/sh
-
-input_dir=/usr/lib/grub/i386-pc
+echo "#!/bin/sh" > binary.sh
 
-# build core.img
-core_img=\$(mktemp)
-grub-mkimage -d \${input_dir} -o \${core_img} -O i386-pc biosdisk iso9660
-
-# build grub_eltorito image
-cat \${input_dir}/cdboot.img \${core_img} > binary/boot/grub/grub_eltorito
-
-rm -f \${core_img}
-
-for file in \${input_dir}/*.mod \${input_dir}/efiemu??.o \
-	\${input_dir}/command.lst \${input_dir}/moddep.lst \${input_dir}/fs.lst \
-	\${input_dir}/handler.lst \${input_dir}/parttool.lst
+for ninclude_file in "${INCLUDED_PATH}"/include_*
 do
-	if test -f "\$file"
-	then
-		cp -f "\$file" binary/boot/grub/i386-pc
-	fi
+	. "${ninclude_file}"
+	${INCLUDED_PREFIX}_custom_additional_binary_top_script
 done
-EOF
-
-else
-	echo "#!/bin/sh" > binary.sh
-fi
 
 cat >> binary.sh << EOF
 
diff --git a/scripts/build/include_grub-efi b/scripts/build/include_grub-efi
new file mode 100755
index 0000000..be82450
--- /dev/null
+++ b/scripts/build/include_grub-efi
@@ -0,0 +1,61 @@
+#!/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
+
+INCLUDED_PREFIX="grub_efi"
+
+grub_efi_check_binary_filesystem()
+
+{
+:
+}
+
+grub_efi_check_image_type()
+
+{
+:
+}
+
+grub_efi_xorriso_first_bootloader_architecture_options()
+
+{
+	if Is_First_Bootloader "grub-efi"
+	then
+		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
+	fi
+}
+
+grub_efi_xorriso_extra_bootloader_architecture_options()
+
+{
+	if Is_Extra_Bootloader "grub-efi"
+	then
+		if [ -e binary/boot/grub/efi.img ]
+		then
+			XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot -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
+	fi
+}
+
+grub_efi_custom_additional_binary_top_script()
+
+{
+:
+}
\ No newline at end of file
diff --git a/scripts/build/include_grub-legacy b/scripts/build/include_grub-legacy
new file mode 100755
index 0000000..4c08a80
--- /dev/null
+++ b/scripts/build/include_grub-legacy
@@ -0,0 +1,58 @@
+#!/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
+
+INCLUDED_PREFIX="grub_legacy"
+
+grub_legacy_check_binary_filesystem()
+
+{
+:
+}
+
+grub_legacy_check_image_type()
+
+{
+	case "${LIVE_IMAGE_TYPE}" in
+		hdd*)
+			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
+					;;
+			esac
+			;;
+	esac
+}
+
+grub_legacy_xorriso_first_bootloader_architecture_options()
+
+{
+	case "${LB_FIRST_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"
+			;;
+	esac
+}
+
+grub_legacy_xorriso_extra_bootloader_architecture_options()
+
+{
+:
+}
+
+grub_legacy_custom_additional_binary_top_script()
+
+{
+:
+}
\ No newline at end of file
diff --git a/scripts/build/include_grub-pc b/scripts/build/include_grub-pc
new file mode 100755
index 0000000..f38a7a1
--- /dev/null
+++ b/scripts/build/include_grub-pc
@@ -0,0 +1,85 @@
+#!/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
+
+INCLUDED_PREFIX="grub_pc"
+
+grub_pc_check_binary_filesystem()
+
+{
+:
+}
+
+grub_pc_check_image_type()
+
+{
+	case "${LIVE_IMAGE_TYPE}" in
+		hdd*)
+			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
+					;;
+			esac
+			;;
+	esac
+}
+
+grub_pc_xorriso_first_bootloader_architecture_options()
+
+{
+	case "${LB_FIRST_BOOTLOADER}" in
+		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"
+			;;
+	esac
+}
+
+grub_pc_xorriso_extra_bootloader_architecture_options()
+
+{
+:
+}
+
+grub_pc_custom_additional_binary_top_script()
+
+{
+	if [ "${LB_FIRST_BOOTLOADER}" = "grub-pc" ]
+	then
+
+	cat > binary.sh << EOF
+
+	input_dir=/usr/lib/grub/i386-pc
+
+	# build core.img
+	core_img=\$(mktemp)
+	grub-mkimage -d \${input_dir} -o \${core_img} -O i386-pc biosdisk iso9660
+
+	# build grub_eltorito image
+	cat \${input_dir}/cdboot.img \${core_img} > binary/boot/grub/grub_eltorito
+
+	rm -f \${core_img}
+
+	for file in \${input_dir}/*.mod \${input_dir}/efiemu??.o \
+		\${input_dir}/command.lst \${input_dir}/moddep.lst \${input_dir}/fs.lst \
+		\${input_dir}/handler.lst \${input_dir}/parttool.lst
+	do
+		if test -f "\$file"
+		then
+			cp -f "\$file" binary/boot/grub/i386-pc
+		fi
+	done
+EOF
+
+	fi
+}
\ No newline at end of file
diff --git a/scripts/build/include_syslinux b/scripts/build/include_syslinux
new file mode 100755
index 0000000..1c7b88d
--- /dev/null
+++ b/scripts/build/include_syslinux
@@ -0,0 +1,69 @@
+#!/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
+
+INCLUDED_PREFIX="syslinux"
+
+syslinux_check_binary_filesystem()
+
+{
+	if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
+	then
+		# syslinux + fat or ntfs, or extlinux + ext[234] or btrfs
+		case "${LB_BINARY_FILESYSTEM}" in
+			fat*|ntfs|ext[234]|btrfs)
+				;;
+			*)
+				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
+}
+
+syslinux_check_image_type()
+
+{
+:
+}
+
+syslinux_xorriso_first_bootloader_architecture_options()
+
+{
+	case "${LB_FIRST_BOOTLOADER}" in
+		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"
+			;;
+	esac
+}
+
+syslinux_xorriso_extra_bootloader_architecture_options()
+
+{
+:
+}
+
+syslinux_custom_additional_binary_top_script()
+
+{
+:
+}
\ No newline at end of file
-- 
2.1.4


Reply to: