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

Bug#731709: Updated EFI patch



I attach a patch based on your work (which I have not tested so feedback is welcome).

You can find the specific modifications to your original commit/patch (which I had to cherry-pick) on branch:

https://github.com/adrian15/live-build/tree/efi_support_based_on_debian_cd

Now I'm going to work on grub-efi support based on debian-cd / Lernstick work so that we can probably have also Secure Boot by default.

So, to make it clear, after my changes you would need to add or modify live config parametres to have:

--bootloaders="syslinux,syslinux-efi"

in order for it to work.



Do not expect me not to improve this patch even more because I'm going to add 'grub-efi' which it's going to be based on debian-cd. And that means some conflicts in the way of doing the final ISO.

And, well, then the final idea is to have the syslinux-efi as a backup method and the grub-efi would be the default one. I will make an specific commit for it.


So, yes, feedback is welcome for this patch and for my other ideas.


El 11/12/14 a las 10:58, Raphael Hertzog escribió:
Attached is an updated patch that works on top of 4.0.4 (change needed
to replace LIVE_IMAGE_ARCHITECTURE with LB_ARCHITECTURES).

Cheers,


adrian15
--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/
diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1
index 8e1f4f7..e3482b2 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|syslinux-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|syslinux-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..1668b8c 100755
--- a/scripts/build/binary
+++ b/scripts/build/binary
@@ -69,6 +69,9 @@ lb binary_loadlin ${@}
 lb binary_win32-loader ${@}
 lb binary_includes ${@}
 lb binary_hooks ${@}
+lb binary_syslinux-efi ${@} # After includes/hooks because it copies in efi.img
+		   # files that can be overriden by binary_includes and
+		   # modified by binary_hooks
 lb binary_checksums ${@}
 
 if [ "${LB_BUILD_WITH_CHROOT}" != "true" ]
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index d8b1553..2b52938 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -140,12 +140,25 @@ 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
 		;;
 esac
 
+if [ -e binary/boot/efi.img ]; then
+	Echo "Using older EFI command line for xorriso $XORRISO_VER"
+	# Tell xorriso to create a secondary ElTorito boot record for the
+	# EFI bootloader
+	XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot --efi-boot boot/efi.img"
+	# Add the efi image as a FAT partition too, so our CD image will
+	# also boot on a USB key (like isohybrid, just implemented
+	# differently)
+	XORRISO_OPTIONS="${XORRISO_OPTIONS} -append_partition 2 0x01 binary/boot/efi.img"
+else
+	Echo "No EFI boot code to include in the ISO"
+fi
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
diff --git a/scripts/build/binary_syslinux-efi b/scripts/build/binary_syslinux-efi
new file mode 100644
index 0000000..029ae7a
--- /dev/null
+++ b/scripts/build/binary_syslinux-efi
@@ -0,0 +1,296 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2014 Raphaël Hertzog <buxy@kali.org>
+##
+## 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 Syslinux 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
+
+FOUND_MYSELF=""
+OLDIFS="$IFS"
+IFS=","
+for BOOTLOADER in ${LB_BOOTLOADERS}
+do
+
+       case ${BOOTLOADER} in
+               "syslinux-efi" )
+                       FOUND_MYSELF="True"
+                       break ;;
+       esac
+
+done
+IFS="$OLDIFS"
+
+if [ -z ${FOUND_MYSELF} ] ; then
+        exit 0
+fi
+
+Echo_message "Begin preparing EFI support..."
+
+# Requiring stage file
+Require_stagefile .build/config .build/bootstrap
+
+# Checking stage file
+Check_stagefile .build/binary_syslinux-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
+
+# Assembling image specifics
+case "${LIVE_IMAGE_TYPE}" in
+	iso*)
+		_BOOTLOADER="isolinux"
+
+		case "${LB_MODE}" in
+			progress-linux)
+				_CONFDIR="binary/boot"
+				;;
+
+			*)
+				_CONFDIR="binary/isolinux"
+				;;
+		esac
+		;;
+
+	netboot)
+		_BOOTLOADER="pxelinux"
+		_CONFDIR="tftpboot"
+		;;
+
+	hdd*|*)
+		case ${LB_BINARY_FILESYSTEM} in
+			fat*|ntfs)
+				_BOOTLOADER=syslinux
+
+				case "${LB_MODE}" in
+					progress-linux)
+						_CONFDIR="binary/boot"
+						;;
+
+					*)
+						_CONFDIR="binary/syslinux"
+						;;
+				esac
+				;;
+
+			ext[234]|btrfs)
+				_BOOTLOADER=extlinux
+				_CONFDIR="binary/boot/extlinux"
+				;;
+
+			*)
+				Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}"
+				exit 1
+				;;
+		esac
+		;;
+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/bin/syslinux syslinux
+		Check_package chroot/usr/lib/syslinux syslinux-common
+		Check_package chroot/usr/lib/SYSLINUX.EFI syslinux-efi
+		Check_package chroot/usr/bin/mcopy mtools
+		Check_package chroot/sbin/mkfs.msdos dosfstools
+		;;
+
+	false)
+		_CHROOT_DIR="chroot"
+		_SYSLINUX_EFI_DIR="/usr/lib/syslinux/$_EFI_TYPE"
+		_SYSLINUX_COMMON_DIR="/usr/lib/syslinux/modules/$_EFI_TYPE"
+
+		if [ ! -e /usr/bin/syslinux ]
+		then
+			# syslinux
+			Echo_error "/usr/bin/syslinux - no such file."
+			exit 1
+		fi
+
+		if [ ! -e /usr/lib/syslinux ]
+		then
+			# syslinux-common
+			Echo_error "/usr/lib/syslinux - no such directory"
+			exit 1
+		fi
+
+		if [ ! -e /usr/lib/SYSLINUX.EFI ]
+		then
+			# syslinux-efi
+			Echo_error "/usr/lib/SYSLINUX.EFI - no such directory"
+			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
+
+# Restoring cache
+Restore_cache cache/packages.binary
+
+# Installing depends
+Install_package
+
+# Abort if we don't have the required EFI files
+if [ ! -e $_SYSLINUX_EFI_DIR/syslinux.efi ]; then
+	Echo_warning "$_SYSLINUX_EFI_DIR/syslinux.efi missing, no EFI support included."
+	case "${LB_BUILD_WITH_CHROOT}" in
+		true)
+			# Saving cache
+			Save_cache cache/packages.binary
+
+			# Removing depends
+			Remove_package
+			;;
+	esac
+	exit 0
+fi
+
+# Cleanup files that we generate
+rm -rf chroot/efi-temp chroot/efi.img binary/boot/efi.img
+
+# Copy syslinux and its config files in the temporary EFI image
+mkdir -p chroot/efi-temp/live
+mkdir -p chroot/efi-temp/EFI/BOOT
+for _F in $_CONFDIR/*.cfg $_CONFDIR/*.png $_SYSLINUX_COMMON_DIR/*.*32 $_SYSLINUX_COMMON_DIR/*.*64; do
+	if [ -e $_F ]; then
+		cp $_F chroot/efi-temp/EFI/BOOT/
+	else
+		Echo_warning "No file matching $_F, EFI support might be broken."
+	fi
+done
+cp $_SYSLINUX_EFI_DIR/syslinux.efi chroot/efi-temp/EFI/BOOT/BOOTX64.efi
+cp $_SYSLINUX_EFI_DIR/syslinux.efi chroot/efi-temp/EFI/BOOT/syslinux.efi
+
+# Copy the various kernel images
+cp binary/live/vmlinuz* binary/live/initrd.img* chroot/efi-temp/live/
+if [ -d binary/install ]; then
+	cp -r binary/install chroot/efi-temp/
+fi
+
+# Edit the menu to differentiate the EFI version
+if [ -e chroot/efi-temp/EFI/BOOT/menu.cfg ]; then
+	sed -i -e "s/^menu title/menu title EFI/" chroot/efi-temp/EFI/BOOT/menu.cfg
+else
+        Echo_warning "No menu.cfg file that can be edited to indicate that we boot on EFI!"
+fi
+
+# Ensure we have a syslinux.cfg
+if [ ! -e chroot/efi-temp/EFI/BOOT/syslinux.cfg ]; then
+	for _F in isolinux.cfg pxelinux.cfg/default extlinux.conf; do
+		if [ -f chroot/efi-temp/EFI/BOOT/$_F ]; then
+			cp chroot/efi-temp/EFI/BOOT/$_F chroot/efi-temp/EFI/BOOT/syslinux.cfg
+			break
+		fi
+	done
+fi
+
+# Define the EFI filesystem size
+_TOTALSIZE=$(du -sk chroot/efi-temp/ | awk '{print $1}')
+# Add 5% safety margin
+_TOTALSIZE=$(( $_TOTALSIZE * 21 / 20 ))
+# Required size rounded to upper 32kb
+_BLOCKS=$(( ($_TOTALSIZE + 31) / 32 * 32 ))
+Echo "EFI boot image needs $_TOTALSIZE Kb, thus allocating $_BLOCKS blocks."
+
+# Script to generate the EFI boot image
+cat >binary.sh <<END
+#!/bin/sh
+
+set -e
+
+mkfs.msdos -C $_CHROOT_DIR/efi.img $_BLOCKS
+mcopy -s -v -i $_CHROOT_DIR/efi.img $_CHROOT_DIR/efi-temp/* ::
+END
+
+# Copying files
+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
+
+mkdir -p binary/boot
+mv chroot/efi.img binary/boot/
+rm -rf chroot/efi-temp
+
+case "${LB_BUILD_WITH_CHROOT}" in
+        true)
+                # Saving cache
+                Save_cache cache/packages.binary
+
+                # Removing depends
+                Remove_package
+                ;;
+esac
+
+# Creating stage file
+Create_stagefile .build/binary_syslinux-efi

Reply to: