Skip to content

Commit

Permalink
This is a patch for adding Loopback cfg support.
Browse files Browse the repository at this point in the history
Development details
--------------------

* This patch has been based originally on: binary_grub2 . It has been
improved thanks to some binary_syslinux bits.

* This patch ensures that binary_loopback_cfg needs is run before binary_syslinux is run.
The reason is that it reuses some code from binary_syslinux to avoid
problems when binary_syslinux renames the kernel filenames.

* This patch already supports CPU detection

* I haven't tested all the possible scenarios for the script (with the
latest version). When amd64 and 486 Gnu/Linux flavours is used and the
bootloader is syslinux it works ok.

* I have not implemented a disable switch for not generating it.
Usually you always want loopback.cfg to be there.

* Compared to binary_grub2 script I have removed the installation
entries because I did not see any of them in binary_syslinux.

How to test
-----------

These are some steps to easily test if Looback cfg support is working ok.

0) We assume you have generated an iso
1) Make sure you have a partition that Grub understands. Plain ext4 or
vfat should do it.
2) Create directory: /boot/boot-isos/
3) Put the iso file into that directory making sure it has an ISO or iso
extension.
4) Setup your computer to boot from cdrom and use: Super Grub2 Disk
2.00s2 (Hybrid version recommended)
5) Choose Boot manually...
6) Choose Bootable ISOs (in /boot- ... )
7) Choose (the detected) GRUB Loopback Config
(hdN,msodsN)/boot/boot-ios/name-of-the.iso
8) You will be presented your loopback.cfg. Choose anyone of the entries
(unless it does not match your cpu architecture of course).
9) You should boot into your Debian Live without problems (thanks to
findiso boot parametre).

If you ever wanted to test from your grub2 installation instead from
Super Grub2 Disk check: http://www.supergrubdisk.org/wiki/Loopback.cfg
for an example.
  • Loading branch information
adriangibanelbtactic committed Dec 7, 2014
1 parent a060853 commit 32fc1dd
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/build/binary
Expand Up @@ -64,6 +64,7 @@ lb binary_debian-installer ${@}
lb binary_memtest ${@}
lb binary_grub ${@}
lb binary_grub2 ${@}
lb binary_loopback_cfg ${@}
lb binary_syslinux ${@}
lb binary_yaboot ${@}
lb binary_silo ${@}
Expand Down
305 changes: 305 additions & 0 deletions scripts/build/binary_loopback_cfg
@@ -0,0 +1,305 @@
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2006-2013 Daniel Baumann <daniel@debian.org>
##
## 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

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 grub2 templates
Check_templates grub2

# Checking lock file
Check_lockfile .lock

# Creating lock file
Create_lockfile .lock

# Check architecture
Check_architectures amd64 i386
Check_crossarchitectures

# Checking depends
#Check_package chroot/usr/bin/grub-mkimage grub-pc

# Restoring cache
Restore_cache cache/packages.binary

# Installing depends
Install_package

# 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_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}"
}

case "${LB_INITRAMFS}" in
casper)
INITFS="casper"
;;

live-boot)
INITFS="live"
;;

*)
INITFS=""
;;
esac

# Setting destination directory
case "${LB_BINARY_IMAGES}" in
iso*|tar)
case "${LB_INITRAMFS}" in
casper)
DESTDIR_LIVE="binary/casper"
;;

live-boot)
DESTDIR_LIVE="binary/live"
;;

*)
DESTDIR_LIVE="binary/live"
;;
esac

DESTDIR_INSTALL="binary/install"
;;

hdd*|netboot)
Echo_warning "Bootloader in this image type not yet supported by live-build."
Echo_warning "This would produce a not bootable image, aborting (FIXME)."
exit 1
;;
esac

Check_multiarchitectures

# Creating directory
mkdir -p "${DESTDIR_LIVE}"

# Setting boot parameters
if [ "${LB_UNION_FILESYSTEM}" != "aufs" ]
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

if [ "${LB_EXPOSED_ROOT}" != "false" ]
then
LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} exposedroot"
fi

LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's| ||')"

# Assembling kernel configuration

if [ "${LB_BOOTLOADER}" != "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)" \
"$(basename ${DESTDIR_LIVE})/${AMD64_KERNEL}" \
"$(basename ${DESTDIR_LIVE})/${AMD64_INITRD}" \
"$(basename ${DESTDIR_LIVE})/${_486_KERNEL}" \
"$(basename ${DESTDIR_LIVE})/${_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" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${DEFAULT_INITRD}"

if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
then
Grub_live_entry "live (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/${DEFAULT_KERNEL}" "$(basename ${DESTDIR_LIVE})/${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}" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}"
Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "$(basename ${DESTDIR_LIVE})/$(basename ${KERNEL})" "$(basename ${DESTDIR_LIVE})/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
done
else # LB_BOOTLOADER = syslinux

#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})" "$(basename ${DESTDIR_LIVE})/vmlinuz" "$(basename ${DESTDIR_LIVE})/initrd.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${LB_LINUX_FLAVOURS}) (failsafe mode)" "$(basename ${DESTDIR_LIVE})/vmlinuz" "$(basename ${DESTDIR_LIVE})/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})" "$(basename ${DESTDIR_LIVE})/vmlinuz${_NUMBER}" "$(basename ${DESTDIR_LIVE})/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "$(basename ${DESTDIR_LIVE})/vmlinuz${_NUMBER}" "$(basename ${DESTDIR_LIVE})/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"

else
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then

Grub_live_autodetect_entry "live (autodetect)" \
"$(basename ${DESTDIR_LIVE})/${AMD64_KERNEL}" \
"$(basename ${DESTDIR_LIVE})/${AMD64_INITRD}" \
"$(basename ${DESTDIR_LIVE})/${_486_KERNEL}" \
"$(basename ${DESTDIR_LIVE})/${_486_INITRD}"
fi

Grub_live_entry "live (${_FLAVOUR})" "$(basename ${DESTDIR_LIVE})/vmlinuz${_NUMBER}" "$(basename ${DESTDIR_LIVE})/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "$(basename ${DESTDIR_LIVE})/vmlinuz${_NUMBER}" "$(basename ${DESTDIR_LIVE})/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 memtest configuration
if [ -f "${DESTDIR_LIVE}"/memtest ]
then
MEMTEST="#\t \"Other\"\n"
MEMTEST="${MEMTEST}\nmenuentry\t\"${LB_MEMTEST}\" {\nlinux16\t$(basename ${DESTDIR_LIVE})/memtest\n}"
MEMTEST="$(/bin/echo ${MEMTEST} | sed -e 's|//|/|g')"
fi

# Copying templates
mkdir -p binary/boot/grub
cp "${TEMPLATES}"/grub.cfg binary/boot/grub/loopback.cfg

sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL||" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/loopback.cfg
sed -i -e "s#LB_BOOTAPPEND_INSTALL##" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/loopback.cfg

sed -i -e 's|\ $||g' binary/boot/grub/loopback.cfg

# Saving cache
Save_cache cache/packages.binary

# Removing depends
Remove_package

# Creating stage file
Create_stagefile .build/binary_loopback_cfg

0 comments on commit 32fc1dd

Please sign in to comment.