2014-12-07 16:20:09 -01:00
|
|
|
#!/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
|
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
# Variable used to embed newlines
|
|
|
|
NL="
|
|
|
|
"
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
# Local functions
|
|
|
|
Grub_menu_entry() {
|
|
|
|
local LABEL="$1"
|
|
|
|
local KERNEL="$2"
|
|
|
|
local INITRD="$3"
|
|
|
|
local APPEND="$4"
|
|
|
|
|
|
|
|
cat <<END
|
|
|
|
menuentry "$LABEL" {
|
|
|
|
linux $KERNEL $APPEND
|
|
|
|
initrd $INITRD
|
|
|
|
}
|
|
|
|
END
|
2014-12-07 16:20:09 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
Grub_live_entry ()
|
|
|
|
{
|
2016-12-13 16:37:41 -01:00
|
|
|
LINUX_LIVE="${LINUX_LIVE}$(Grub_menu_entry "$@")$NL"
|
2014-12-07 16:20:09 -01:00
|
|
|
}
|
|
|
|
|
2016-08-26 18:23:02 +00:00
|
|
|
Grub_install_entry ()
|
|
|
|
{
|
|
|
|
LABEL="${1}"
|
2016-12-02 20:41:55 -01:00
|
|
|
TYPE="${2}"
|
|
|
|
KERNEL="${3}"
|
|
|
|
INITRD="${4}"
|
|
|
|
APPEND="${5}"
|
2016-08-26 18:23:02 +00:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
# Drop "quiet" kernel parameter for rescue entries
|
|
|
|
case $TYPE in
|
|
|
|
rescue|rescuegui)
|
|
|
|
APPEND=$(echo "$APPEND" | sed -e 's/ quiet//')
|
|
|
|
;;
|
|
|
|
esac
|
2016-08-26 18:23:02 +00:00
|
|
|
|
2016-12-02 20:41:55 -01:00
|
|
|
if [ -z "$LINUX_INSTALL" ]; then
|
|
|
|
# First entry recorded in LINUX_INSTALL
|
2016-12-13 16:37:41 -01:00
|
|
|
LINUX_INSTALL="$(Grub_menu_entry "$LABEL" "$KERNEL" "$INITRD" "$APPEND")$NL"
|
2016-12-02 20:41:55 -01:00
|
|
|
else
|
|
|
|
# Remaining entries recorded in LINUX_ADVANCED_INSTALL
|
2016-12-13 16:37:41 -01:00
|
|
|
LINUX_ADVANCED_INSTALL="$LINUX_ADVANCED_INSTALL$(Grub_menu_entry "$LABEL" "$KERNEL" "$INITRD" "$APPEND")$NL"
|
2016-12-02 20:41:55 -01:00
|
|
|
fi
|
2016-08-26 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
Grub_live_autodetect_menu_entry ()
|
2014-12-07 16:20:09 -01:00
|
|
|
{
|
|
|
|
local LABEL="${1}"
|
|
|
|
local AMD64_KERNEL="${2}"
|
|
|
|
local AMD64_INITRD="${3}"
|
2017-12-15 17:27:48 -01:00
|
|
|
local _686_KERNEL="${4}"
|
|
|
|
local _686_INITRD="${5}"
|
2014-12-07 16:20:09 -01:00
|
|
|
local APPEND="${6}"
|
2016-12-13 16:37:41 -01:00
|
|
|
cat <<END
|
|
|
|
# Autodetect if amd64 is supported
|
|
|
|
menuentry "$LABEL" {
|
|
|
|
if cpuid -l; then
|
|
|
|
linux ${AMD64_KERNEL} ${APPEND}
|
|
|
|
initrd ${AMD64_INITRD}
|
|
|
|
else
|
2017-12-15 17:27:48 -01:00
|
|
|
linux ${_686_KERNEL} ${APPEND}
|
|
|
|
initrd ${_686_INITRD}
|
2016-12-13 16:37:41 -01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
END
|
|
|
|
}
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
Grub_live_autodetect_entry ()
|
|
|
|
{
|
|
|
|
LINUX_LIVE="${LINUX_LIVE}$(Grub_live_autodetect_menu_entry "$@")$NL"
|
|
|
|
}
|
|
|
|
|
|
|
|
Grub_memtest_menu_entry ()
|
|
|
|
{
|
|
|
|
cat <<END
|
|
|
|
menuentry "$LB_MEMTEST" {
|
|
|
|
linux16 /${INITFS}/memtest
|
|
|
|
}
|
|
|
|
END
|
2014-12-07 16:20:09 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Check_multiarchitectures
|
|
|
|
|
|
|
|
# Setting boot parameters
|
2016-12-02 13:10:19 -01:00
|
|
|
if [ "${LB_UNION_FILESYSTEM}" != "overlay" ]
|
2014-12-07 16:20:09 -01:00
|
|
|
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
|
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
# 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-||')"
|
|
|
|
|
|
|
|
KERNEL_LIVE="/${INITFS}/${DEFAULT_KERNEL}"
|
|
|
|
INITRD_LIVE="/${INITFS}/${DEFAULT_INITRD}"
|
|
|
|
APPEND_LIVE="${LB_BOOTAPPEND_LIVE}"
|
2014-12-07 16:20:09 -01:00
|
|
|
|
|
|
|
# Assembling kernel configuration
|
2017-12-15 17:27:48 -01:00
|
|
|
_AMD64_686_NUMBER="0"
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-02 20:41:55 -01:00
|
|
|
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
|
|
|
|
do
|
2017-12-15 17:27:48 -01:00
|
|
|
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "686" ] ; then
|
|
|
|
_AMD64_686_NUMBER="$((${_AMD64_686_NUMBER} + 1))"
|
2016-12-02 20:41:55 -01:00
|
|
|
fi
|
2014-12-07 16:20:09 -01:00
|
|
|
done
|
|
|
|
|
2017-12-15 17:27:48 -01:00
|
|
|
if [ "${_AMD64_686_NUMBER}" -ge 2 ] ; then
|
2016-12-02 20:41:55 -01:00
|
|
|
# Default entries
|
|
|
|
AMD64_KERNEL="$(basename chroot/boot/vmlinuz-*amd64)"
|
|
|
|
AMD64_INITRD="initrd.img-$(echo ${AMD64_KERNEL} | sed -e 's|vmlinuz-||')"
|
2017-12-15 17:27:48 -01:00
|
|
|
_686_KERNEL="$(basename chroot/boot/vmlinuz-*686)"
|
|
|
|
_686_INITRD="initrd.img-$(echo ${_686_KERNEL} | sed -e 's|vmlinuz-||')"
|
2016-12-02 20:41:55 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
Grub_live_autodetect_entry "Live system (autodetect)" \
|
|
|
|
"/${INITFS}/${AMD64_KERNEL}" \
|
|
|
|
"/${INITFS}/${AMD64_INITRD}" \
|
2017-12-15 17:27:48 -01:00
|
|
|
"/${INITFS}/${_686_KERNEL}" \
|
|
|
|
"/${INITFS}/${_686_INITRD}" \
|
2017-12-16 22:01:33 -01:00
|
|
|
"${APPEND_LIVE}"
|
|
|
|
|
|
|
|
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]
|
|
|
|
then
|
|
|
|
Grub_live_autodetect_entry "Live system (autodetect) (fail-safe mode)" \
|
|
|
|
"/${INITFS}/${AMD64_KERNEL}" \
|
|
|
|
"/${INITFS}/${AMD64_INITRD}" \
|
|
|
|
"/${INITFS}/${_686_KERNEL}" \
|
|
|
|
"/${INITFS}/${_686_INITRD}" \
|
|
|
|
"${LB_BOOTAPPEND_LIVE_FAILSAFE}"
|
|
|
|
fi
|
2016-12-13 16:37:41 -01:00
|
|
|
else
|
|
|
|
Grub_live_entry "Live system" "/${INITFS}/${DEFAULT_KERNEL}" "/${INITFS}/${DEFAULT_INITRD}" "${APPEND_LIVE}"
|
2017-12-16 22:01:33 -01:00
|
|
|
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]
|
|
|
|
then
|
|
|
|
Grub_live_entry "Live system (fail-safe mode)" "/${INITFS}/${DEFAULT_KERNEL}" "/${INITFS}/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
|
|
|
|
fi
|
2016-12-02 20:41:55 -01:00
|
|
|
fi
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-02 20:41:55 -01:00
|
|
|
_COUNT=0
|
|
|
|
for KERNEL in chroot/boot/vmlinuz-*; do
|
2017-12-16 21:18:21 -01:00
|
|
|
_COUNT=$(( $_COUNT + 1 ))
|
2016-12-02 20:41:55 -01:00
|
|
|
done
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-02 20:41:55 -01:00
|
|
|
if [ $_COUNT -gt 1 ]; then
|
2014-12-07 16:20:09 -01:00
|
|
|
for KERNEL in chroot/boot/vmlinuz-*
|
|
|
|
do
|
|
|
|
VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
|
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
Grub_live_entry "Live system, kernel ${VERSION}" "/${INITFS}/$(basename ${KERNEL})" "/${INITFS}/initrd.img-${VERSION}" "${APPEND_LIVE}"
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
if [ "${LB_BOOTAPPEND_LIVE_FAILSAFE}" != "none" ]; then
|
|
|
|
Grub_live_entry "Live system, kernel ${VERSION} (fail-safe mode)" "/${INITFS}/$(basename ${KERNEL})" "/${INITFS}/initrd.img-${VERSION}" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
|
2016-12-02 20:41:55 -01:00
|
|
|
fi
|
|
|
|
done
|
2014-12-07 16:20:09 -01:00
|
|
|
fi
|
|
|
|
|
2016-08-26 18:23:02 +00:00
|
|
|
# Assembling debian-installer configuration
|
|
|
|
if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
|
|
|
|
then
|
2016-12-13 16:37:41 -01:00
|
|
|
KERNEL_DI="/install/vmlinuz"
|
|
|
|
INITRD_DI="/install/initrd.gz"
|
|
|
|
APPEND_DI="vga=normal quiet ${LB_BOOTAPPEND_INSTALL}"
|
|
|
|
|
|
|
|
KERNEL_GI="/install/gtk/vmlinuz"
|
|
|
|
INITRD_GI="/install/gtk/initrd.gz"
|
|
|
|
APPEND_GI="video=vesa:ywrap,mtrr vga=788 quiet ${LB_BOOTAPPEND_INSTALL}"
|
|
|
|
|
|
|
|
Grub_install_entry "Start installer" "installgui" "${KERNEL_GI}" "${INITRD_GI}" "${APPEND_GI}"
|
|
|
|
|
|
|
|
Grub_install_entry "Install in graphical mode" "installgui" "${KERNEL_GI}" "${INITRD_GI}" "${APPEND_GI}"
|
|
|
|
Grub_install_entry "Install in text mode" "install" "${KERNEL_DI}" "${INITRD_DI}" "${APPEND_DI}"
|
|
|
|
Grub_install_entry "Expert install in graphical mode" "expertgui" "${KERNEL_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
|
|
|
|
Grub_install_entry "Expert install in text mode" "expert" "${KERNEL_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
|
|
|
|
Grub_install_entry "Automatic install in graphical mode" "autogui" "${KERNEL_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
|
|
|
|
Grub_install_entry "Automatic install in text mode" "auto" "${KERNEL_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
|
|
|
|
Grub_install_entry "Rescue system in graphical mode" "rescuegui" "${KERNEL_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
|
|
|
|
Grub_install_entry "Rescue system in text mode" "rescue" "${KERNEL_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
|
2016-08-26 18:23:02 +00:00
|
|
|
fi
|
|
|
|
|
2014-12-07 16:20:09 -01:00
|
|
|
# Assembling memtest configuration
|
2016-12-13 16:37:41 -01:00
|
|
|
if [ -f "binary/${INITFS}/memtest" ]
|
2014-12-07 16:20:09 -01:00
|
|
|
then
|
2016-12-13 16:37:41 -01:00
|
|
|
MEMTEST="$(Grub_memtest_menu_entry)$NL"
|
2014-12-07 16:20:09 -01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Copying templates
|
|
|
|
mkdir -p binary/boot/grub
|
2016-11-28 19:05:06 -01:00
|
|
|
cp -a "${_SOURCE}"/* binary/boot/grub/
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
escape_for_sed() {
|
|
|
|
echo -n "$1" | perl -npe 's/\n/\\n/gm'
|
|
|
|
}
|
2014-12-07 16:20:09 -01:00
|
|
|
|
2016-12-13 16:37:41 -01:00
|
|
|
sed -i \
|
|
|
|
-e "s|LINUX_LIVE|$(escape_for_sed "${LINUX_LIVE}")|" \
|
|
|
|
-e "s|LINUX_ADVANCED_INSTALL|$(escape_for_sed "${LINUX_ADVANCED_INSTALL}")|" \
|
|
|
|
-e "s|LINUX_INSTALL|$(escape_for_sed "${LINUX_INSTALL}")|" \
|
|
|
|
-e "s|MEMTEST|$(escape_for_sed "${MEMTEST}")|" \
|
|
|
|
-e "s|KERNEL_GI|$(escape_for_sed "${KERNEL_GI}")|" \
|
|
|
|
-e "s|INITRD_GI|$(escape_for_sed "${INITRD_GI}")|" \
|
|
|
|
-e "s|APPEND_GI|$(escape_for_sed "${APPEND_GI}")|" \
|
|
|
|
-e "s|KERNEL_DI|$(escape_for_sed "${KERNEL_DI}")|" \
|
|
|
|
-e "s|INITRD_DI|$(escape_for_sed "${INITRD_DI}")|" \
|
|
|
|
-e "s|APPEND_DI|$(escape_for_sed "${APPEND_DI}")|" \
|
|
|
|
-e "s|KERNEL_LIVE|$(escape_for_sed "${KERNEL_LIVE}")|" \
|
|
|
|
-e "s|INITRD_LIVE|$(escape_for_sed "${INITRD_LIVE}")|" \
|
|
|
|
-e "s|APPEND_LIVE|$(escape_for_sed "${APPEND_LIVE}")|" \
|
|
|
|
-e "s|LB_BOOTAPPEND_INSTALL|$(escape_for_sed "${LB_BOOTAPPEND_INSTALL}")|" \
|
|
|
|
-e "s|LB_BOOTAPPEND_LIVE_FAILSAFE|$(escape_for_sed "${LB_BOOTAPPEND_LIVE_FAILSAFE}")|" \
|
|
|
|
-e "s|LB_BOOTAPPEND_LIVE|$(escape_for_sed "${LB_BOOTAPPEND_LIVE}")|" \
|
|
|
|
binary/boot/grub/*.cfg
|
|
|
|
|
|
|
|
sed -i -e 's|//|/|g' binary/boot/grub/*.cfg
|
2016-11-22 16:17:53 -01:00
|
|
|
sed -i -e 's|\ $||g' binary/boot/grub/*.cfg
|
2016-01-18 02:15:47 -01:00
|
|
|
|
|
|
|
echo "source /boot/grub/grub.cfg" > binary/boot/grub/loopback.cfg
|
2014-12-07 16:20:09 -01:00
|
|
|
|
|
|
|
# Creating stage file
|
|
|
|
Create_stagefile .build/binary_loopback_cfg
|