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

Bug#757697: RFE: Autodetection of architecture at boot time to load appropiate kernel



El 15/08/14 a las 13:04, Daniel Baumann escribió:
On 08/15/2014 07:12 AM, adrian15 wrote:
I attach a patch for Isolinux / Syslinux implementation for cpu detection.

nice, thanks.

from a quick look, sounds good. will check, test, and apply next week.

As suggested (by another bug) I attach both patches / commits updated so that they are based on debian-next branch.

Related branch can be found at: https://github.com/adrian15/live-build/commits/rescatux_0.32_debian-next_arch_detection_rebased

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

    Syslinux build now supports: Arch detection
    It adds a default boot option that automatically chooses either amd64 or x86 kernel depending on the detected cpu flags.

diff --git a/scripts/build/binary_syslinux b/scripts/build/binary_syslinux
index abd900a..d59bd05 100755
--- a/scripts/build/binary_syslinux
+++ b/scripts/build/binary_syslinux
@@ -233,6 +233,12 @@ case "${LB_BUILD_WITH_CHROOT}" in
 		;;
 esac
 
+# Copy necessary syslinux modules
+for module in ifcpu64.c32
+do
+	cp "chroot/usr/lib/syslinux/modules/bios/${module}" "${_TARGET}/"
+done
+
 # Configuring files
 if [ -e "${_TARGET}/live.cfg.in" ]
 then
@@ -255,6 +261,22 @@ 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
+				_AMD64_LABEL=$(cat "${_TARGET}/live.cfg.in" | grep "^label" | grep -v "failsafe" | sed 's/label //g' | sed -e "s|@FLAVOUR@|""amd64""|g")
+				_486_LABEL=$(cat "${_TARGET}/live.cfg.in" | grep "^label" | grep -v "failsafe" | sed 's/label //g' | sed -e "s|@FLAVOUR@|""486""|g")
+				_AUTO_LABEL=$(cat "${_TARGET}/live.cfg.in" | grep "^label" | grep -v "failsafe" | sed 's/label //g' | sed -e "s|@FLAVOUR@|""autodetect""|g")
+				_AUTO_MENU_LABEL=$(cat "${_TARGET}/live.cfg.in" | grep "menu label" | grep -v "failsafe" | sed 's/.*menu label //g' | sed -e "s|@FLAVOUR@|""auto""|g")
+			fi
+
 			_NUMBER="0"
 
 			for _FLAVOUR in ${LB_LINUX_FLAVOURS}
@@ -269,7 +291,22 @@ then
 					echo "" >> "${_TARGET}/live.cfg"
 					grep -v 'menu default' "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
 				else
-					cat "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
+					if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
+						cat << EOF >> "${_TARGET}/live.cfg"
+label ${_AUTO_LABEL}
+	menu label ${_AUTO_MENU_LABEL}
+	com32 ifcpu64.c32
+	append ${_AMD64_LABEL} -- ${_486_LABEL} -- ${_486_LABEL}
+
+EOF
+					fi
+
+
+					if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
+						grep -v 'menu default' "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
+					else
+						cat "${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
+					fi
 				fi
 
 				sed -i -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
commit 36f781c4dc55e9a0d14cc74df5ff36f9eac2e33f
Author: Adrian Gibanel Lopez <adrian.gibanel@btactic.com>
Date:   Sun Dec 7 17:50:16 2014 +0100

        Grub2 build now supports: Arch detection
        It adds a default boot option that automatically chooses either amd64 or x86 kernel depending on the detected cpu flags.

diff --git a/scripts/build/binary_grub2 b/scripts/build/binary_grub2
index bf5f8ce..a23c2f9 100755
--- a/scripts/build/binary_grub2
+++ b/scripts/build/binary_grub2
@@ -60,6 +60,16 @@ Restore_cache cache/packages.binary
 Install_package
 
 # Local functions
+Grub_live_entry_commands ()
+{
+	KERNEL="${1}"
+	INITRD="${2}"
+	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 ()
 {
 	LABEL="${1}"
@@ -68,8 +78,25 @@ Grub_live_entry ()
 	APPEND="${4}"
 
 	LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
-	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_commands "${KERNEL}" "${INITRD}" "${APPEND}"
+	LINUX_LIVE="${LINUX_LIVE}\n}"
+}
+
+Grub_live_autodetect_entry ()
+{
+	LABEL="${1}"
+	AMD64_KERNEL="${2}"
+	AMD64_INITRD="${3}"
+	_486_KERNEL="${4}"
+	_486_INITRD="${5}"
+	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}"
+	LINUX_LIVE="${LINUX_LIVE}\nelse"
+	Grub_live_entry_commands "${_486_KERNEL}" "${_486_INITRD}" "${APPEND}"
+	LINUX_LIVE="${LINUX_LIVE}\nfi"
 	LINUX_LIVE="${LINUX_LIVE}\n}"
 }
 
@@ -153,6 +180,29 @@ LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's|  ||')"
 
 # Assembling kernel configuration
 
+_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})"

Reply to: