blob: 8a7b41815224b7d69258bd4c87adc4d6304d8cdc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## 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 'installs loopback.cfg 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
# We avoid checking if we need to be running this bootloader
# on purpose. The reason: You will always want to have
# a loopback.cfg file
# TODO: Add an option to be able to disable this file creation
Echo_message "Begin installing loopback.cfg..."
# Requiring stage file
Require_stagefile .build/config .build/bootstrap
# Checking stage file
Check_stagefile .build/binary_loopback_cfg
# Checking lock file
Check_lockfile .lock
# Creating lock file
Create_lockfile .lock
# Check architecture
Check_architectures amd64 i386
Check_crossarchitectures
# Local functions
Grub_live_entry_commands ()
{
local KERNEL="${1}"
local INITRD="${2}"
local APPEND="${3}"
LINUX_LIVE="${LINUX_LIVE}\nlinux\t\t/${KERNEL} ${INITFS:+boot=${INITFS} }config LB_BOOTAPPEND_LIVE ${APPEND}"
LINUX_LIVE="${LINUX_LIVE}\ninitrd\t\t/${INITRD}"
}
Grub_live_entry ()
{
local LABEL="${1}"
local KERNEL="${2}"
local INITRD="${3}"
local APPEND="${4}"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
Grub_live_entry_commands "${KERNEL}" "${INITRD}" "${APPEND} findiso=\${iso_path}"
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}"
}
Grub_live_autodetect_entry ()
{
local LABEL="${1}"
local AMD64_KERNEL="${2}"
local AMD64_INITRD="${3}"
local _486_KERNEL="${4}"
local _486_INITRD="${5}"
local APPEND="${6}"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
LINUX_LIVE="${LINUX_LIVE}\nif cpuid -l ; then"
Grub_live_entry_commands "${AMD64_KERNEL}" "${AMD64_INITRD}" "${APPEND} findiso=\${iso_path}"
LINUX_LIVE="${LINUX_LIVE}\nelse"
Grub_live_entry_commands "${_486_KERNEL}" "${_486_INITRD}" "${APPEND} findiso=\${iso_path}"
LINUX_LIVE="${LINUX_LIVE}\nfi"
LINUX_LIVE="${LINUX_LIVE}\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"
;;
*)
INITFS=""
;;
esac
# Assembling image specifics
case "${LIVE_IMAGE_TYPE}" in
iso*)
_BOOTLOADER="isolinux"
case "${LB_MODE}" in
progress-linux)
_TARGET="binary/boot"
;;
*)
_TARGET="binary/isolinux"
;;
esac
;;
netboot)
_BOOTLOADER="pxelinux"
_TARGET="tftpboot"
;;
hdd*|*)
case ${LB_BINARY_FILESYSTEM} in
fat*|ntfs)
_BOOTLOADER=syslinux
case "${LB_MODE}" in
progress-linux)
_TARGET="binary/boot"
;;
*)
_TARGET="binary/syslinux"
;;
esac
;;
ext[234]|btrfs)
_BOOTLOADER=extlinux
_TARGET="binary/boot/extlinux"
;;
*)
Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}"
exit 1
;;
esac
;;
esac
DESTDIR_LIVE="${_TARGET}"
Check_multiarchitectures
# Creating directory
mkdir -p "${DESTDIR_LIVE}"
# Setting boot parameters
if [ "${LB_UNION_FILESYSTEM}" != "overlay" ]
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
# If Bootloader is not syslinux that means
# binary_syslinux it's not going to rename kernel filenames in a later stage.
# We will use binary_grub2 algorithm which does not rename kernel filenames.
FOUND_SYSLINUX=""
OLDIFS="$IFS"
IFS=","
for BOOTLOADER in ${LB_BOOTLOADERS}
do
case ${BOOTLOADER} in
"syslinux" )
FOUND_SYSLINUX="True"
break ;;
esac
done
IFS="$OLDIFS"
if [ -z ${FOUND_SYSLINUX} ]
then
_AMD64_486_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "486" ] ; then
_AMD64_486_NUMBER="$((${_AMD64_486_NUMBER} + 1))"
fi
done
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
# Default entries
AMD64_KERNEL="$(basename chroot/boot/vmlinuz-*amd64)"
AMD64_INITRD="initrd.img-$(echo ${AMD64_KERNEL} | sed -e 's|vmlinuz-||')"
_486_KERNEL="$(basename chroot/boot/vmlinuz-*486)"
_486_INITRD="initrd.img-$(echo ${_486_KERNEL} | sed -e 's|vmlinuz-||')"
Grub_live_autodetect_entry "live (autodetect)" \
"${INITFS}/${AMD64_KERNEL}" \
"${INITFS}/${AMD64_INITRD}" \
"${INITFS}/${_486_KERNEL}" \
"${INITFS}/${_486_INITRD}"
fi
# 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" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${DEFAULT_INITRD}"
if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
then
Grub_live_entry "live (fail-safe mode)" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${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}" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}"
Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
done
else # LB_BOOTLOADERS does not contain syslinux
# If one of the bootloader is syslinux that means
# binary_syslinux it's going to rename kernel filenames.
# We will use binary_syslinux algorithm but without renaming kernel filenames.
# That will ensure binary_syslinux will find the original kernel filenames.
#if [ -e "${_TARGET}/live.cfg.in" ]
#then
# This is all rather suboptimal.. needs prettifying at some point
_FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
case "${_FLAVOURS}" in
1)
Grub_live_entry "live (${LB_LINUX_FLAVOURS})" "${INITFS}/vmlinuz" "${INITFS}/initrd.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${LB_LINUX_FLAVOURS}) (failsafe mode)" "${INITFS}/vmlinuz" "${INITFS}/initrd.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
;;
*)
_AMD64_486_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "486" ] ; then
_AMD64_486_NUMBER="$((${_AMD64_486_NUMBER} + 1))"
fi
done
_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
_NUMBER="$((${_NUMBER} + 1))"
if [ "${_FLAVOUR}" = "amd64" ] ; then
AMD64_KERNEL="vmlinuz${_NUMBER}"
AMD64_INITRD="initrd${_NUMBER}.img"
fi
if [ "${_FLAVOUR}" = "486" ] ; then
_486_KERNEL="vmlinuz${_NUMBER}"
_486_INITRD="initrd${_NUMBER}.img"
fi
done
_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
_NUMBER="$((${_NUMBER} + 1))"
if [ "${_NUMBER}" -gt 1 ]
then
Grub_live_entry "live (${_FLAVOUR})" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
else
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
Grub_live_autodetect_entry "live (autodetect)" \
"${INITFS}/${AMD64_KERNEL}" \
"${INITFS}/${AMD64_INITRD}" \
"${INITFS}/${_486_KERNEL}" \
"${INITFS}/${_486_INITRD}"
fi
Grub_live_entry "live (${_FLAVOUR})" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
fi
done
;;
esac
#fi
fi
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${INITFS}/memtest\n}"
MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
fi
# Copying templates
mkdir -p binary/boot/grub
cp -a "${_SOURCE}"/* binary/boot/grub/
sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/*.cfg
sed -i -e "s#LB_BOOTAPPEND_INSTALL#${LB_BOOTAPPEND_INSTALL}#" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/*.cfg
sed -i -e 's|\ $||g' binary/boot/grub/*.cfg
echo "source /boot/grub/grub.cfg" > binary/boot/grub/loopback.cfg
# Creating stage file
Create_stagefile .build/binary_loopback_cfg
|