[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#757883: Patch for Loopback cfg support



El 08/12/14 a las 07:28, Daniel Baumann escribió:
On 12/08/14 00:09, jnqnfe wrote:
I believe I'm right in saying that you must
build against live-build 4.x, preferably the debian-next branch

correct, we will not touch live-* 3.x anymore unless there's a security
issue or another bug making the existing, officially built 3.x/wheezy
live images unusable.

I attach the rebased commit for loopback cfg adapted to debian-next as requested and with some of your suggestions implemented.

The order in binary file remains the same because, as I explained earlier, syslinux renames the kernel filenames.

Just in case you want the detailed commits from debian-old-3.0 to debian-next they can be found here:

https://github.com/adrian15/live-build/commit/b907d5ca4cfac5407e4231a202b5b84cfcf8c56c
https://github.com/adrian15/live-build/commit/5c7636f8848b3d1d058bb2ed7fd69e01ad05270d
https://github.com/adrian15/live-build/commit/1dcec1bdc96a9b5eefb3a464b40250738bf3dfec
https://github.com/adrian15/live-build/commit/f08a3bbfeb98faad99643dbf88aead8a98a69b6f
https://github.com/adrian15/live-build/commit/0cd9b26c8697d4eeb5e950546c6e7b9c94b5ac14
https://github.com/adrian15/live-build/commit/77ac5d6acce430b6a1106e0cdb20a177e36a1b48
https://github.com/adrian15/live-build/commit/9afdaf59138392b09fce41bb522d0d0e1ea1ca11

The new patch and the resulting binary_loopback_cfg file can be also found here:

https://github.com/adrian15/live-build/commit/9c67d2d05502e03e0c52827a4e0c7d088f361e88

https://github.com/adrian15/live-build/blob/9c67d2d05502e03e0c52827a4e0c7d088f361e88/scripts/build/binary_loopback_cfg

adrian15
--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/
commit 9c67d2d05502e03e0c52827a4e0c7d088f361e88
Author: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date:   Sun Dec 7 18:20:09 2014 +0100

    This is a patch for adding Loopback cfg support.
    
    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.

diff --git a/scripts/build/binary b/scripts/build/binary
index c1f9ec6..97d7ebc 100755
--- a/scripts/build/binary
+++ b/scripts/build/binary
@@ -63,6 +63,7 @@ lb binary_linux-image ${@}
 lb binary_memtest ${@}
 lb binary_grub ${@}
 lb binary_grub2 ${@}
+lb binary_loopback_cfg ${@}
 lb binary_syslinux ${@}
 lb binary_disk ${@}
 lb binary_loadlin ${@}
diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg
new file mode 100755
index 0000000..64958c4
--- /dev/null
+++ b/scripts/build/binary_loopback_cfg
@@ -0,0 +1,311 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2014 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
+
+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
+
+# 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"
+		;;
+
+	*)
+		INITFS="live"
+		;;
+
+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}" != "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
+
+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.
+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)" \
+			"${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_BOOTLOADER = syslinux
+# If 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 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 "${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
+
+# Creating stage file
+Create_stagefile .build/binary_loopback_cfg

Reply to: