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

Bug#731709: EFI support for ISO images



Hi

At Lernstick we use the patch attached to create ISO images which boot
on EFI systems. This does not include adding a EFI bootloader to the
image. We do that with config/includes.binary which is of course not a
complete solution.

The debian-cd folks (Steve McIntyre) did a lot of testing to find the
right combination of xorriso options to create an image which boots on
most EFI hardware. Because there are lots of broken implementations out
there.

The patch also adds a dependency on xorriso.

Gaudenz

commit c048047fb581e407db6059bd7de48b36f49a1baf
Author: Gaudenz Steinlin <gaudenz@debian.org>
Date:   Wed Apr 30 10:50:39 2014 +0200

    Option to include an EFI image into ISO images
    
    --efi-boot option to include an EFI boot image as an alternative El
    Torrito boot image into the ISO image. This is necessary for booting an
    ISO image on most EFI implementations. Booting the ISO image also works
    from USB devices when writeing the image directly to the device. The EFI
    boot files must be present in binary/efi/boot already. Use a binary hook
    or include to copy the files to this directory.
    
    This code is an adaption of similar code present in debian-cd.

diff --git a/functions/defaults.sh b/functions/defaults.sh
index a1040d7..5b93698 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -700,6 +700,9 @@ Set_defaults ()
 		esac
 	fi
 
+	# Setting efi boot
+	LB_EFI_BOOT="${LB_EFI_BOOT:-false}"
+
 	# Setting checksums
 	case "${LB_MODE}" in
 		progress-linux)
diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1
index 4ef252a..2a6557a 100644
--- a/manpages/en/lb_config.1
+++ b/manpages/en/lb_config.1
@@ -41,6 +41,8 @@
 .br
 	[\fB\-\-bootloader\fR grub|grub2|syslinux]
 .br
+	[\fB\-\-efi\-boot\fR true|false]
+.br
 	[\fB\-\-cache\fR true|false]
 .br
 	[\fB\-\-cache\-indices\fR true|false]
@@ -265,6 +267,8 @@ sets boot parameters specific to debian\-installer, if included.
 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
 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\-\-efi\-boot\fR true|false" 4
+control if an EFI boot image should be included as an alternate El Torrito image. This is necessary for booting an ISO image under EFI on most implementations. Booting the ISO image also works from USB devices when writeing the image directly to the device. The EFI boot files must be present in binary/efi/boot already. Use a binary hook or include to copy the files to this directory.
 .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.
 .IP "\fB\-\-cache\-indices\fR true|false" 4
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index 44a9418..0b0d5db 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -144,6 +144,30 @@ case "${LB_BOOTLOADER}" in
 		;;
 esac
 
+if [ "${LB_EFI_BOOT}" = "true" ]
+then
+	XORRISO_VER=$(xorriso --version 2>&1 | awk '
+			/^xorriso version/ {
+				split($4, ver, ".")
+				print ver[1]*10000+ver[2]*100+ver[3]
+			}')
+	# Ugh - different code here depending on the version of xorriso we've got
+	if [ $XORRISO_VER -le 10202 ] ; then
+		# 1.2.2 shipping in Wheezy
+		# Tell xorriso to create a secondary ElTorito boot record for the
+		# EFI bootloader
+		XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot --efi-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/efi.img"
+
+	elif [ $XORRISO_VER -gt 10202 ] ; then
+		XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot -e efi.img -no-emul-boot"
+		XORRISO_OPTIONS="${XORRISO_OPTIONS} -isohybrid-gpt-basdat -isohybrid-apm-hfsplus"
+	fi
+fi
+
 #if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
 #then
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
@@ -181,6 +205,34 @@ else
 	echo "#!/bin/sh" > binary.sh
 fi
 
+if [ "${LB_EFI_BOOT}" = "true" ]
+then
+# 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.
+
+cat >> binary.sh << EOF
+
+efi_img="binary/efi.img"
+
+size=0
+for file in binary/efi/boot/*; do
+	size=\$((\$size + \$(stat -c %s "\$file")))
+done
+
+blocks=\$(((\$size / 1024 + 55) / 32 * 32 ))
+
+mkfs.msdos -C "\$efi_img" \$blocks >/dev/null
+mmd -i "\$efi_img" ::efi
+mmd -i "\$efi_img" ::efi/boot
+mcopy -i "\$efi_img" binary/efi/boot/* "::efi/boot"
+
+EOF
+fi
+
 cat >> binary.sh << EOF
 
 xorriso -as mkisofs ${XORRISO_OPTIONS} -o ${IMAGE} binary
diff --git a/scripts/build/config b/scripts/build/config
index 77f4029..2a7eaaf 100755
--- a/scripts/build/config
+++ b/scripts/build/config
@@ -33,6 +33,7 @@ USAGE="${PROGRAM}   [--apt apt|aptitude]\n\
 \t    [--bootappend-live PARAMETER|\"PARAMETERS\"]\n\
 \t    [--bootappend-live-failsafe PARAMETER|\"PARAMETERS\"]\n\
 \t    [--bootloader grub|grub2|syslinux]\n\
+\t    [--efi-boot true|false]\n\
 \t    [--cache true|false]\n\
 \t    [--cache-indices true|false]\n\
 \t    [--cache-packages true|false]\n\
@@ -138,7 +139,7 @@ Local_arguments ()
 		archive-areas:,parent-archive-areas:,chroot-filesystem:,
 		gzip-options:,image-name:,interactive:,keyring-packages:,linux-flavours:,linux-packages:,
 		security:,updates:,backports:,binary-filesystem:,binary-images:,
-		apt-indices:,bootappend-install:,bootappend-live:,bootappend-live-failsafe:,bootloader:,checksums:,compression:,config:,zsync:,build-with-chroot:,
+		apt-indices:,bootappend-install:,bootappend-live:,bootappend-live-failsafe:,bootloader:,efi-boot:,checksums:,compression:,config:,zsync:,build-with-chroot:,
 		debian-installer:,debian-installer-distribution:,debian-installer-preseedfile:,debian-installer-gui:,
 		grub-splash:,isohybrid-options:,hdd-label:,hdd-size:,iso-application:,iso-preparer:,iso-publisher:,
 		iso-volume:,jffs2-eraseblock:,memtest:,net-root-filesystem:,net-root-mountoptions:,
@@ -502,6 +503,11 @@ Local_arguments ()
 				shift 2
 				;;
 
+			--efi-boot)
+				LB_EFI_BOOT="${2}"
+				shift 2
+				;;
+
 			--checksums)
 				LB_CHECKSUMS="${2}"
 				shift 2
@@ -1163,6 +1169,10 @@ LB_BOOTAPPEND_LIVE_FAILSAFE="${LB_BOOTAPPEND_LIVE_FAILSAFE}"
 # (Default: ${LB_BOOTLOADER})
 LB_BOOTLOADER="${LB_BOOTLOADER}"
 
+# \$LB_EFI_BOOT: control if an EFI boot image should be included as an alternate El Torrito image
+# (Default: ${LB_EFI_BOOT})
+LB_EFI_BOOT="${LB_EFI_BOOT}"
+
 # \$LB_CHECKSUMS: set checksums
 # (Default: ${LB_CHECKSUMS})
 LB_CHECKSUMS="${LB_CHECKSUMS}"

Attachment: signature.asc
Description: PGP signature


Reply to: