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