0 | |
From: =?utf-8?q?Rapha=C3=ABl_Hertzog?= <[email protected]>
|
1 | |
Date: Fri, 5 Dec 2014 09:36:27 +0100
|
2 | |
Subject: Add support for EFI boot with syslinux-efi.
|
3 | |
|
4 | |
Bug-Debian: http://bugs.debian.org/731709
|
5 | |
Bug-Kali: https://bugs.kali.org/view.php?id=680
|
6 | |
---
|
7 | |
scripts/build/binary | 3 +
|
8 | |
scripts/build/binary_efi | 282 +++++++++++++++++++++++++++++++++++++++++++++++
|
9 | |
scripts/build/binary_iso | 37 +++++++
|
10 | |
3 files changed, 322 insertions(+)
|
11 | |
create mode 100644 scripts/build/binary_efi
|
12 | |
|
13 | |
diff --git a/scripts/build/binary b/scripts/build/binary
|
14 | |
index fe90d8e..779dc7d 100755
|
15 | |
--- a/scripts/build/binary
|
16 | |
+++ b/scripts/build/binary
|
17 | |
@@ -68,6 +68,9 @@ lb binary_loadlin ${@}
|
18 | |
lb binary_win32-loader ${@}
|
19 | |
lb binary_includes ${@}
|
20 | |
lb binary_hooks ${@}
|
21 | |
+lb binary_efi ${@} # After includes/hooks because it copies in efi.img
|
22 | |
+ # files that can be overriden by binary_includes and
|
23 | |
+ # modified by binary_hooks
|
24 | |
lb binary_checksums ${@}
|
25 | |
|
26 | |
if [ "${LB_BUILD_WITH_CHROOT}" != "true" ]
|
27 | |
diff --git a/scripts/build/binary_efi b/scripts/build/binary_efi
|
28 | |
new file mode 100644
|
29 | |
index 0000000..038a7de
|
30 | |
--- /dev/null
|
31 | |
+++ b/scripts/build/binary_efi
|
32 | |
@@ -0,0 +1,282 @@
|
33 | |
+#!/bin/sh
|
34 | |
+
|
35 | |
+## live-build(7) - System Build Scripts
|
36 | |
+## Copyright (C) 2014 Raphaël Hertzog <[email protected]>
|
37 | |
+##
|
38 | |
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
39 | |
+## This is free software, and you are welcome to redistribute it
|
40 | |
+## under certain conditions; see COPYING for details.
|
41 | |
+
|
42 | |
+
|
43 | |
+set -e
|
44 | |
+
|
45 | |
+# Including common functions
|
46 | |
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
|
47 | |
+
|
48 | |
+# Setting static variables
|
49 | |
+DESCRIPTION="$(Echo 'prepares and installs EFI support into binary')"
|
50 | |
+HELP=""
|
51 | |
+USAGE="${PROGRAM} [--force]"
|
52 | |
+
|
53 | |
+Arguments "${@}"
|
54 | |
+
|
55 | |
+# Reading configuration files
|
56 | |
+Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
|
57 | |
+Set_defaults
|
58 | |
+
|
59 | |
+if [ "${LB_BOOTLOADER}" != "syslinux" ]
|
60 | |
+then
|
61 | |
+ exit 0
|
62 | |
+fi
|
63 | |
+
|
64 | |
+Echo_message "Begin preparing EFI support..."
|
65 | |
+
|
66 | |
+# Requiring stage file
|
67 | |
+Require_stagefile .build/config .build/bootstrap
|
68 | |
+
|
69 | |
+# Checking stage file
|
70 | |
+Check_stagefile .build/binary_efi
|
71 | |
+
|
72 | |
+# Checking lock file
|
73 | |
+Check_lockfile .lock
|
74 | |
+
|
75 | |
+# Creating lock file
|
76 | |
+Create_lockfile .lock
|
77 | |
+
|
78 | |
+# Check architecture
|
79 | |
+Check_architectures amd64 i386
|
80 | |
+Check_crossarchitectures
|
81 | |
+
|
82 | |
+case "${LB_ARCHITECTURES}" in
|
83 | |
+ amd64)
|
84 | |
+ _EFI_TYPE=efi64
|
85 | |
+ ;;
|
86 | |
+ i386)
|
87 | |
+ _EFI_TYPE=efi32
|
88 | |
+ ;;
|
89 | |
+ *)
|
90 | |
+ echo "ERROR: can't provide EFI boot support to architecture ${LB_ARCHITECTURES}" >&2
|
91 | |
+ exit 1
|
92 | |
+ ;;
|
93 | |
+esac
|
94 | |
+
|
95 | |
+# Assembling image specifics
|
96 | |
+case "${LIVE_IMAGE_TYPE}" in
|
97 | |
+ iso*)
|
98 | |
+ _BOOTLOADER="isolinux"
|
99 | |
+
|
100 | |
+ case "${LB_MODE}" in
|
101 | |
+ progress-linux)
|
102 | |
+ _CONFDIR="binary/boot"
|
103 | |
+ ;;
|
104 | |
+
|
105 | |
+ *)
|
106 | |
+ _CONFDIR="binary/isolinux"
|
107 | |
+ ;;
|
108 | |
+ esac
|
109 | |
+ ;;
|
110 | |
+
|
111 | |
+ netboot)
|
112 | |
+ _BOOTLOADER="pxelinux"
|
113 | |
+ _CONFDIR="tftpboot"
|
114 | |
+ ;;
|
115 | |
+
|
116 | |
+ hdd*|*)
|
117 | |
+ case ${LB_BINARY_FILESYSTEM} in
|
118 | |
+ fat*|ntfs)
|
119 | |
+ _BOOTLOADER=syslinux
|
120 | |
+
|
121 | |
+ case "${LB_MODE}" in
|
122 | |
+ progress-linux)
|
123 | |
+ _CONFDIR="binary/boot"
|
124 | |
+ ;;
|
125 | |
+
|
126 | |
+ *)
|
127 | |
+ _CONFDIR="binary/syslinux"
|
128 | |
+ ;;
|
129 | |
+ esac
|
130 | |
+ ;;
|
131 | |
+
|
132 | |
+ ext[234]|btrfs)
|
133 | |
+ _BOOTLOADER=extlinux
|
134 | |
+ _CONFDIR="binary/boot/extlinux"
|
135 | |
+ ;;
|
136 | |
+
|
137 | |
+ *)
|
138 | |
+ Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}"
|
139 | |
+ exit 1
|
140 | |
+ ;;
|
141 | |
+ esac
|
142 | |
+ ;;
|
143 | |
+esac
|
144 | |
+
|
145 | |
+# Checking depends
|
146 | |
+case "${LB_BUILD_WITH_CHROOT}" in
|
147 | |
+ true)
|
148 | |
+ _CHROOT_DIR=""
|
149 | |
+ _SYSLINUX_EFI_DIR="chroot/usr/lib/SYSLINUX.EFI/$_EFI_TYPE"
|
150 | |
+ _SYSLINUX_COMMON_DIR="chroot/usr/lib/syslinux/modules/$_EFI_TYPE"
|
151 | |
+
|
152 | |
+ Check_package chroot/usr/bin/syslinux syslinux
|
153 | |
+ Check_package chroot/usr/lib/syslinux syslinux-common
|
154 | |
+ Check_package chroot/usr/lib/SYSLINUX.EFI syslinux-efi
|
155 | |
+ Check_package chroot/usr/bin/mcopy mtools
|
156 | |
+ Check_package chroot/sbin/mkfs.msdos dosfstools
|
157 | |
+ ;;
|
158 | |
+
|
159 | |
+ false)
|
160 | |
+ _CHROOT_DIR="chroot"
|
161 | |
+ _SYSLINUX_EFI_DIR="/usr/lib/syslinux/$_EFI_TYPE"
|
162 | |
+ _SYSLINUX_COMMON_DIR="/usr/lib/syslinux/modules/$_EFI_TYPE"
|
163 | |
+
|
164 | |
+ if [ ! -e /usr/bin/syslinux ]
|
165 | |
+ then
|
166 | |
+ # syslinux
|
167 | |
+ Echo_error "/usr/bin/syslinux - no such file."
|
168 | |
+ exit 1
|
169 | |
+ fi
|
170 | |
+
|
171 | |
+ if [ ! -e /usr/lib/syslinux ]
|
172 | |
+ then
|
173 | |
+ # syslinux-common
|
174 | |
+ Echo_error "/usr/lib/syslinux - no such directory"
|
175 | |
+ exit 1
|
176 | |
+ fi
|
177 | |
+
|
178 | |
+ if [ ! -e /usr/lib/SYSLINUX.EFI ]
|
179 | |
+ then
|
180 | |
+ # syslinux-efi
|
181 | |
+ Echo_error "/usr/lib/SYSLINUX.EFI - no such directory"
|
182 | |
+ exit 1
|
183 | |
+ fi
|
184 | |
+
|
185 | |
+ if [ ! -e /usr/bin/mcopy ]
|
186 | |
+ then
|
187 | |
+ # mtools
|
188 | |
+ Echo_error "/usr/bin/mcopy - no such file."
|
189 | |
+ exit 1
|
190 | |
+ fi
|
191 | |
+
|
192 | |
+ if [ ! -e /sbin/mkfs.msdos ]
|
193 | |
+ then
|
194 | |
+ # dosfstools
|
195 | |
+ Echo_error "/sbin/mkfs.msdos - no such file."
|
196 | |
+ exit 1
|
197 | |
+ fi
|
198 | |
+ ;;
|
199 | |
+esac
|
200 | |
+
|
201 | |
+# Restoring cache
|
202 | |
+Restore_cache cache/packages.binary
|
203 | |
+
|
204 | |
+# Installing depends
|
205 | |
+Install_package
|
206 | |
+
|
207 | |
+# Abort if we don't have the required EFI files
|
208 | |
+if [ ! -e $_SYSLINUX_EFI_DIR/syslinux.efi ]; then
|
209 | |
+ Echo_warning "$_SYSLINUX_EFI_DIR/syslinux.efi missing, no EFI support included."
|
210 | |
+ case "${LB_BUILD_WITH_CHROOT}" in
|
211 | |
+ true)
|
212 | |
+ # Saving cache
|
213 | |
+ Save_cache cache/packages.binary
|
214 | |
+
|
215 | |
+ # Removing depends
|
216 | |
+ Remove_package
|
217 | |
+ ;;
|
218 | |
+ esac
|
219 | |
+ exit 0
|
220 | |
+fi
|
221 | |
+
|
222 | |
+# Cleanup files that we generate
|
223 | |
+rm -rf chroot/efi-temp chroot/efi.img binary/boot/efi.img
|
224 | |
+
|
225 | |
+# Copy syslinux and its config files in the temporary EFI image
|
226 | |
+mkdir -p chroot/efi-temp/live
|
227 | |
+mkdir -p chroot/efi-temp/EFI/BOOT
|
228 | |
+for _F in $_CONFDIR/*.cfg $_CONFDIR/*.png $_SYSLINUX_COMMON_DIR/*.*32 $_SYSLINUX_COMMON_DIR/*.*64; do
|
229 | |
+ if [ -e $_F ]; then
|
230 | |
+ cp $_F chroot/efi-temp/EFI/BOOT/
|
231 | |
+ else
|
232 | |
+ Echo_warning "No file matching $_F, EFI support might be broken."
|
233 | |
+ fi
|
234 | |
+done
|
235 | |
+cp $_SYSLINUX_EFI_DIR/syslinux.efi chroot/efi-temp/EFI/BOOT/BOOTX64.efi
|
236 | |
+cp $_SYSLINUX_EFI_DIR/syslinux.efi chroot/efi-temp/EFI/BOOT/syslinux.efi
|
237 | |
+
|
238 | |
+# Copy the various kernel images
|
239 | |
+cp binary/live/vmlinuz* binary/live/initrd.img* chroot/efi-temp/live/
|
240 | |
+if [ -d binary/install ]; then
|
241 | |
+ cp -r binary/install chroot/efi-temp/
|
242 | |
+fi
|
243 | |
+
|
244 | |
+# Edit the menu to differentiate the EFI version
|
245 | |
+if [ -e chroot/efi-temp/EFI/BOOT/menu.cfg ]; then
|
246 | |
+ sed -i -e "s/^menu title/menu title EFI/" chroot/efi-temp/EFI/BOOT/menu.cfg
|
247 | |
+else
|
248 | |
+ Echo_warning "No menu.cfg file that can be edited to indicate that we boot on EFI!"
|
249 | |
+fi
|
250 | |
+
|
251 | |
+# Ensure we have a syslinux.cfg
|
252 | |
+if [ ! -e chroot/efi-temp/EFI/BOOT/syslinux.cfg ]; then
|
253 | |
+ for _F in isolinux.cfg pxelinux.cfg/default extlinux.conf; do
|
254 | |
+ if [ -f chroot/efi-temp/EFI/BOOT/$_F ]; then
|
255 | |
+ cp chroot/efi-temp/EFI/BOOT/$_F chroot/efi-temp/EFI/BOOT/syslinux.cfg
|
256 | |
+ break
|
257 | |
+ fi
|
258 | |
+ done
|
259 | |
+fi
|
260 | |
+
|
261 | |
+# Define the EFI filesystem size
|
262 | |
+_TOTALSIZE=$(du -sk chroot/efi-temp/ | awk '{print $1}')
|
263 | |
+# Add 5% safety margin
|
264 | |
+_TOTALSIZE=$(( $_TOTALSIZE * 21 / 20 ))
|
265 | |
+# Required size rounded to upper 32kb
|
266 | |
+_BLOCKS=$(( ($_TOTALSIZE + 31) / 32 * 32 ))
|
267 | |
+Echo "EFI boot image needs $_TOTALSIZE Kb, thus allocating $_BLOCKS blocks."
|
268 | |
+
|
269 | |
+# Script to generate the EFI boot image
|
270 | |
+cat >binary.sh <<END
|
271 | |
+#!/bin/sh
|
272 | |
+
|
273 | |
+set -e
|
274 | |
+
|
275 | |
+mkfs.msdos -C $_CHROOT_DIR/efi.img $_BLOCKS
|
276 | |
+mcopy -s -v -i $_CHROOT_DIR/efi.img $_CHROOT_DIR/efi-temp/* ::
|
277 | |
+END
|
278 | |
+
|
279 | |
+# Copying files
|
280 | |
+case "${LB_BUILD_WITH_CHROOT}" in
|
281 | |
+ true)
|
282 | |
+ mv binary.sh chroot/
|
283 | |
+ Chroot chroot "sh binary.sh"
|
284 | |
+ rm -f chroot/binary.sh
|
285 | |
+
|
286 | |
+ # Saving cache
|
287 | |
+ Save_cache cache/packages.binary
|
288 | |
+
|
289 | |
+ # Removing depends
|
290 | |
+ Remove_package
|
291 | |
+ ;;
|
292 | |
+
|
293 | |
+ false)
|
294 | |
+ sh binary.sh
|
295 | |
+ rm -f binary.sh
|
296 | |
+ ;;
|
297 | |
+esac
|
298 | |
+
|
299 | |
+mkdir -p binary/boot
|
300 | |
+mv chroot/efi.img binary/boot/
|
301 | |
+rm -rf chroot/efi-temp
|
302 | |
+
|
303 | |
+case "${LB_BUILD_WITH_CHROOT}" in
|
304 | |
+ true)
|
305 | |
+ # Saving cache
|
306 | |
+ Save_cache cache/packages.binary
|
307 | |
+
|
308 | |
+ # Removing depends
|
309 | |
+ Remove_package
|
310 | |
+ ;;
|
311 | |
+esac
|
312 | |
+
|
313 | |
+# Creating stage file
|
314 | |
+Create_stagefile .build/binary_efi
|
315 | |
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
|
316 | |
index e81a13a..d5b9c8e 100755
|
317 | |
--- a/scripts/build/binary_iso
|
318 | |
+++ b/scripts/build/binary_iso
|
319 | |
@@ -71,6 +71,23 @@ fi
|
320 | |
# Handle xorriso generic options
|
321 | |
XORRISO_OPTIONS="-R -r -J -joliet-long -l -cache-inodes -iso-level 3"
|
322 | |
|
323 | |
+case "${LB_BUILD_WITH_CHROOT}" in
|
324 | |
+ true)
|
325 | |
+ XORRISO_VER=$(Chroot chroot xorriso --version 2>&1 | awk '
|
326 | |
+ /^xorriso version/ {
|
327 | |
+ split($4, ver, ".")
|
328 | |
+ print ver[1]*10000+ver[2]*100+ver[3]
|
329 | |
+ }')
|
330 | |
+ ;;
|
331 | |
+ false)
|
332 | |
+ XORRISO_VER=$(xorriso --version 2>&1 | awk '
|
333 | |
+ /^xorriso version/ {
|
334 | |
+ split($4, ver, ".")
|
335 | |
+ print ver[1]*10000+ver[2]*100+ver[3]
|
336 | |
+ }')
|
337 | |
+ ;;
|
338 | |
+esac
|
339 | |
+
|
340 | |
# Handle xorriso live-build specific options
|
341 | |
if [ "${LIVE_IMAGE_TYPE}" = "iso-hybrid" ]
|
342 | |
then
|
343 | |
@@ -144,6 +161,26 @@ case "${LB_BOOTLOADER}" in
|
344 | |
;;
|
345 | |
esac
|
346 | |
|
347 | |
+if [ -e binary/boot/efi.img ]; then
|
348 | |
+ #if [ "$XORRISO_VER" -le 10202 ]; then
|
349 | |
+ # 1.2.2 shipping in wheezy
|
350 | |
+ Echo "Using older EFI command line for xorriso $XORRISO_VER"
|
351 | |
+ # Tell xorriso to create a secondary ElTorito boot record for the
|
352 | |
+ # EFI bootloader
|
353 | |
+ XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot --efi-boot boot/efi.img"
|
354 | |
+ # Add the efi image as a FAT partition too, so our CD image will
|
355 | |
+ # also boot on a USB key (like isohybrid, just implemented
|
356 | |
+ # differently)
|
357 | |
+ XORRISO_OPTIONS="${XORRISO_OPTIONS} -append_partition 2 0x01 binary/boot/efi.img"
|
358 | |
+ #else
|
359 | |
+ # Echo "Using newer EFI support in xorriso $XORRISO_VER"
|
360 | |
+ # XORRISO_OPTIONS="${XORRISO_OPTIONS} -eltorito-alt-boot -e boot/efi.img -no-emul-boot"
|
361 | |
+ # XORRISO_OPTIONS="${XORRISO_OPTIONS} -isohybrid-gpt-basdat"
|
362 | |
+ #fi
|
363 | |
+else
|
364 | |
+ Echo "No EFI boot code to include in the ISO"
|
365 | |
+fi
|
366 | |
+
|
367 | |
#if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
|
368 | |
#then
|
369 | |
# XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
|