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

Re: Multi Bootloaders support patch (not working)



I attach the new patch that seems to work ok with the default value.
I have not tried two bootloaders at the same time yet.
I will do these tests when I implement loopback.cfg binary based on this commit.

I copy and paste from the git commit because I'm concerned on how to deal with IFS variable (not saving and reusing the old value (well, that's not exactly what I'm actually doing) was the reason why things did not work as expected).

Finally I have not commited this to a custom tmp-something branch based debian-next yet. I will wait till I have something more robust unless you think it's better for me to commit it instead of sending patches here.

---

Note: OLDIFS use makes IFS to be reset to "" instead to it being unset.
    Either we need to detect if old IFS was unset to unset it
    or we need a proper way of setting it as a local variable.
    Even more IFS it's not currently used in
    Check_package (which it's called from: binary_hdd).
we should have a clean way of resetting/unsetting IFS when calling Check_package.

The other approach it's to explicitly define IFS with its default value in the places inside live-build code where we implicitly suppose that it's going to have
    its default value.




El 21/08/15 a las 20:08, adrian15 escribió:
This is a patch for adding Multi bootloaders support to Debian Live. (Based on current git master).

This is the first step I need to be able to add loopback.cfg support to Debian Live.

It's currently not working. Any help on debugging it it's needed.

Thank you !

adrian15

--
Support free software. Donate to Super Grub Disk. Apoya el software libre. Dona a Super Grub Disk. http://www.supergrubdisk.org/donate/

commit 036355074e84e4088d307d7c4cd7474ac0010b04
Author: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date:   Fri Aug 21 23:54:46 2015 +0200

    Multi bootloader support
    
    Note: OLDIFS use makes IFS to be reset to "" instead to it being unset.
    Either we need to detect if old IFS was unset to unset it
    or we need a proper way of setting it as a local variable.
    Even more IFS it's not currently used in
    Check_package (which it's called from: binary_hdd).
    we should have a clean way of resetting/unsetting IFS when calling Check_package.
    
    The other approach it's to explicitly define IFS with its default value in the
    places inside live-build code where we implicitly suppose that it's going to have
    its default value.

diff --git a/functions/defaults.sh b/functions/defaults.sh
index eba52ae..a0cb968 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -536,11 +536,11 @@ Set_defaults ()
 	esac
 
 	# Setting bootloader
-	if [ -z "${LB_BOOTLOADER}" ]
+	if [ -z "${LB_BOOTLOADERS}" ]
 	then
 		case "${LB_ARCHITECTURES}" in
 			amd64|i386)
-				LB_BOOTLOADER="syslinux"
+				LB_BOOTLOADERS="syslinux"
 				;;
 		esac
 	fi
@@ -853,7 +853,10 @@ Check_defaults ()
 		fi
 	fi
 
-	if [ "${LB_BOOTLOADER}" = "syslinux" ]
+
+	LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
+
+	if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
 	then
 		# syslinux + fat or ntfs, or extlinux + ext[234] or btrfs
 		case "${LB_BINARY_FILESYSTEM}" in
@@ -867,7 +870,7 @@ Check_defaults ()
 
 	case "${LIVE_IMAGE_TYPE}" in
 		hdd*)
-			case "${LB_BOOTLOADER}" in
+			case "${LB_PRIMARY_BOOTLOADER}" in
 				grub)
 					Echo_error "You have selected a combination of bootloader and image type that is currently not supported by live-build. Please use either another bootloader or a different image type."
 					exit 1
diff --git a/scripts/build/binary_grub-legacy b/scripts/build/binary_grub-legacy
index 8a2093b..59daab0 100755
--- a/scripts/build/binary_grub-legacy
+++ b/scripts/build/binary_grub-legacy
@@ -24,9 +24,19 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-if [ "${LB_BOOTLOADER}" != "grub-legacy" ]
-then
-	exit 0
+FOUND_MYSELF=""
+IFS="," ; for BOOTLOADER in ${LB_BOOTLOADERS} ; do
+
+       case ${BOOTLOADER} in
+               "grub-legacy" )
+                       FOUND_MYSELF="True"
+                       break ;;
+       esac
+
+done
+
+if [ -z ${FOUND_MYSELF} ] ; then
+        exit 0
 fi
 
 Echo_message "Begin installing grub-legacy..."
diff --git a/scripts/build/binary_grub-pc b/scripts/build/binary_grub-pc
index de2683c..d8085fb 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -24,9 +24,21 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-if [ "${LB_BOOTLOADER}" != "grub-pc" ]
-then
-	exit 0
+FOUND_MYSELF=""
+OLDIFS="$IFS"
+IFS="," ; for BOOTLOADER in ${LB_BOOTLOADERS} ; do
+
+       case ${BOOTLOADER} in
+               "grub-pc" )
+                       FOUND_MYSELF="True"
+                       break ;;
+       esac
+
+done
+IFS="$OLDIFS"
+
+if [ -z ${FOUND_MYSELF} ] ; then
+        exit 0
 fi
 
 Echo_message "Begin installing grub-pc..."
diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index 45158c9..94dd809 100755
--- a/scripts/build/binary_hdd
+++ b/scripts/build/binary_hdd
@@ -57,26 +57,32 @@ esac
 Check_package chroot /usr/share/doc/mtools mtools
 Check_package chroot /sbin/parted parted
 
-case "${LB_BOOTLOADER}" in
-	grub)
-		Check_package chroot /usr/sbin/grub grub
-		;;
-
-	syslinux)
-		case ${LB_BINARY_FILESYSTEM} in
-			fat*|ntfs)
-				_BOOTLOADER=syslinux
-				;;
-			ext[234]|btrfs)
-				_BOOTLOADER=extlinux
-				;;
-			*)
-				Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}"
-				exit 1
-				;;
-		esac
-		Check_package chroot /usr/bin/${_BOOTLOADER} ${_BOOTLOADER}
-		;;
+echo "${LB_BOOTLOADERS}" | while IFS="," read -r BOOTLOADER ; do
+	case "${BOOTLOADER}" in
+		grub)
+			Check_package chroot /usr/sbin/grub grub
+			;;
+	esac
+done
+
+LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
+
+case ${LB_PRIMARY_BOOTLOADER} in
+		syslinux)
+			case ${LB_BINARY_FILESYSTEM} in
+				fat*|ntfs)
+					_BOOTLOADER=syslinux
+					;;
+				ext[234]|btrfs)
+					_BOOTLOADER=extlinux
+					;;
+				*)
+					Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}"
+					exit 1
+					;;
+			esac
+			Check_package chroot /usr/bin/${_BOOTLOADER} ${_BOOTLOADER}
+			;;
 esac
 
 # Restoring cache
@@ -168,7 +174,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
 		Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
 
-		if [ "${LB_BOOTLOADER}" = "syslinux" ]
+		if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
 		then
 			dd if=chroot/usr/lib/SYSLINUX/mbr.bin of=${FREELO} bs=440 count=1
 		fi
@@ -180,7 +186,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		parted -s "${FREELO}" set 1 boot on || true
 		parted -s "${FREELO}" set 1 lba off || true
 
-		if [ "${LB_BOOTLOADER}" = "syslinux" ]
+		if [ "${LB_PRIMARY_BOOTLOADER}" = "syslinux" ]
 		then
 			dd if=/usr/lib/SYSLINUX/mbr.bin of=${FREELO} bs=440 count=1
 		fi
@@ -246,7 +252,7 @@ cp -T ${CP_OPTIONS} binary/ chroot/binary.tmp
 
 FIXME()
 {
-if [ "${LB_BOOTLOADER}" = "grub" ]
+if [ "${LB_PRIMARY_BOOTLOADER}" = "grub" ]
 then
 
 cat > chroot/grub.sh << EOF
diff --git a/scripts/build/binary_iso b/scripts/build/binary_iso
index e81a13a..d8b1553 100755
--- a/scripts/build/binary_iso
+++ b/scripts/build/binary_iso
@@ -107,8 +107,10 @@ then
 	XORRISO_OPTIONS="${XORRISO_OPTIONS} -V \"${LB_ISO_VOLUME}\""
 fi
 
+LB_PRIMARY_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk -F, '{ print $1 }')
+
 # Handle xorriso architecture specific options
-case "${LB_BOOTLOADER}" in
+case "${LB_PRIMARY_BOOTLOADER}" in
 	grub)
 		XORRISO_OPTIONS="${XORRISO_OPTIONS} -no-emul-boot -boot-load-size 4 -boot-info-table"
 		XORRISO_OPTIONS="${XORRISO_OPTIONS} -b boot/grub/stage2_eltorito"
@@ -149,7 +151,7 @@ esac
 #	XORRISO_OPTIONS="${XORRISO_OPTIONS} -m ${XORRISO_EXCLUDE}"
 #fi
 
-if [ "${LB_BOOTLOADER}" = "grub-pc" ]
+if [ "${LB_PRIMARY_BOOTLOADER}" = "grub-pc" ]
 then
 
 cat > binary.sh << EOF
diff --git a/scripts/build/binary_syslinux b/scripts/build/binary_syslinux
index 41d7fec..d7a2d92 100755
--- a/scripts/build/binary_syslinux
+++ b/scripts/build/binary_syslinux
@@ -24,9 +24,21 @@ Arguments "${@}"
 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 Set_defaults
 
-if [ "${LB_BOOTLOADER}" != "syslinux" ]
-then
-	exit 0
+FOUND_MYSELF=""
+OLDIFS="$IFS"
+IFS="," ; for BOOTLOADER in ${LB_BOOTLOADERS} ; do
+
+       case ${BOOTLOADER} in
+               "syslinux" )
+                       FOUND_MYSELF="True"
+                       break ;;
+       esac
+
+done
+IFS="$OLDIFS"
+
+if [ -z ${FOUND_MYSELF} ] ; then
+        exit 0
 fi
 
 Echo_message "Begin installing syslinux..."
diff --git a/scripts/build/config b/scripts/build/config
index 66bf64f..0c289ca 100755
--- a/scripts/build/config
+++ b/scripts/build/config
@@ -32,7 +32,7 @@ USAGE="${PROGRAM}   [--apt apt|aptitude]\n\
 \t    [--bootappend-install PARAMETER|\"PARAMETERS\"]\n\
 \t    [--bootappend-live PARAMETER|\"PARAMETERS\"]\n\
 \t    [--bootappend-live-failsafe PARAMETER|\"PARAMETERS\"]\n\
-\t    [--bootloader grub-legacy|grub-pc|syslinux]\n\
+\t    [--bootloaders grub-legacy|grub-pc|syslinux]\n\
 \t    [--cache true|false]\n\
 \t    [--cache-indices true|false]\n\
 \t    [--cache-packages true|false]\n\
@@ -491,8 +491,8 @@ Local_arguments ()
 				shift 2
 				;;
 
-			--bootloader)
-				LB_BOOTLOADER="${2}"
+			--bootloaders)
+				LB_BOOTLOADERS="${2}"
 				shift 2
 				;;
 
@@ -1149,9 +1149,9 @@ LB_BOOTAPPEND_INSTALL="${LB_BOOTAPPEND_INSTALL}"
 # (Default: empty)
 LB_BOOTAPPEND_LIVE_FAILSAFE="${LB_BOOTAPPEND_LIVE_FAILSAFE}"
 
-# \$LB_BOOTLOADER: set bootloader
-# (Default: ${LB_BOOTLOADER})
-LB_BOOTLOADER="${LB_BOOTLOADER}"
+# \$LB_BOOTLOADERS: set bootloaders
+# (Default: ${LB_BOOTLOADERS})
+LB_BOOTLOADERS="${LB_BOOTLOADERS}"
 
 # \$LB_CHECKSUMS: set checksums
 # (Default: ${LB_CHECKSUMS})
diff --git a/scripts/build/source_debian b/scripts/build/source_debian
index 9b3b634..3ff00f9 100755
--- a/scripts/build/source_debian
+++ b/scripts/build/source_debian
@@ -52,8 +52,13 @@ fi
 # Download sources
 Chroot chroot "dpkg --get-selections" | awk '{ print $1 }' > source-selection.txt
 
+echo "${LB_BOOTLOADERS}" | while IFS="," read -r BOOTLOADER ; do
+  cat >> source-selection.txt << EOF
+  ${BOOTLOADER}
+EOF
+done
+
 cat >> source-selection.txt << EOF
-${LB_BOOTLOADER}
 live-build
 EOF
 

Reply to: