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

Bug#573173: support multiple kernel versions with same flavour



Package: live-build
Followup-For: Bug #573173

Hello,

sending fixed/updated version of the patch.

This works for me quite well with live-build in Debian and Syslinux.

Grub is unsupported.
Build menu for multiple kernels of the same flavour.

 - does not crash if multiple kernels of same flavour are installed
 - includes all kernels in boot menu
 - handles snapshot flavours (ending with +)

This allows to include stable and sid kernel as well as custom built kernel
snapshot in single image to support wider range of hardware.

Kernel version is included in menu label. This allows differentiating multiple
kernel versions of same flavour and gives useful information for single kernel
images as well.

The main menu text which lists kernel version was broken. The version list
included (none) - either due to duplicate packages in release/updates or
different sources between binary and chroot. Use dpkg to determine kernel
version rather than apt-cache.

TODO:
 * support fo non-syslinux bootloaders


Index: live-build-20151215mk1/scripts/build/binary_syslinux
===================================================================
--- live-build-20151215mk1.orig/scripts/build/binary_syslinux	2016-08-19 15:14:10.253502710 +0200
+++ live-build-20151215mk1/scripts/build/binary_syslinux	2016-08-23 10:44:53.491514403 +0200
@@ -197,52 +197,54 @@
 if [ -e "${_TARGET}/live.cfg.in" ]
 then
 	# This is all rather suboptimal.. needs prettifying at some point
-	_FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
+	_FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | tr " " "\n" | sed -e '/^$/d')"
+	if ! echo "${_FLAVOURS}" | grep -q signed
+	then
+		_FLAVOURS="$(echo ${_FLAVOURS} | sed -e '/^$/d' -e 's/$/-signed/')
+		${_FLAVOURS}
+		$(echo ${_FLAVOURS} | sed -e '/^$/d' -e 's/$/-unsigned/')"
+	fi
+	if echo ${_FLAVOURS} | grep -q +$
+	then
+		_FLAVOURS_GIT=""
+	else
+		_FLAVOURS_GIT="$(echo ${_FLAVOURS} | sed -e '/^$/d' -e 's/$/+/')"
+	fi
+
+	_NUMBER="0"
+
+	for _FLAVOUR in ${_FLAVOURS} ${_FLAVOURS_GIT}
+	do
+		_KERNELS="$(ls -r --sort=version binary/${_INITRAMFS}/vmlinuz-*-${_FLAVOUR} 2>/dev/null || :)"
+		_KVERSIONS="$(for _KERNEL in ${_KERNELS} ; do basename "${_KERNEL}" -"${_FLAVOUR}" | sed -e 's/vmlinuz-//' ; done)"
+		for _KVER in ${_KVERSIONS}
+		do
+			_NUMBER="$((${_NUMBER} + 1))"
+			_KERNEL="vmlinuz-${_KVER}-${_FLAVOUR}"
+			_INITRD="initrd.img-${_KVER}-${_FLAVOUR}"
+			mv "binary/${_INITRAMFS}/${_KERNEL}" "binary/${_INITRAMFS}/vmlinuz${_NUMBER}"
+			mv "binary/${_INITRAMFS}/${_INITRD}" "binary/${_INITRAMFS}/initrd${_NUMBER}.img"
+
+			if [ "${_NUMBER}" -gt 1 ]
+			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"
+			fi
+
+			sed -i -e "s|@FLAVOUR@|${_FLAVOUR}-${_KVER}|g" \
+			    -e "s|@LINUX@|/${_INITRAMFS}/vmlinuz${_NUMBER}|g" \
+			    -e "s|@INITRD@|/${_INITRAMFS}/initrd${_NUMBER}.img|g" \
+			    "${_TARGET}/live.cfg"
+		done
+	done
 
-	case "${_FLAVOURS}" in
-		1)
-			# If multiple initrd images are being generated (by DKMS packages, etc),
-			# we likely only want the latest version.
-			mv $(ls -r1 --sort=version binary/${_INITRAMFS}/vmlinuz-* | head -n 1) binary/${_INITRAMFS}/vmlinuz
-			mv $(ls -r1 --sort=version binary/${_INITRAMFS}/initrd.img-* | head -n 1) binary/${_INITRAMFS}/initrd.img
-
-			sed -e "s|@FLAVOUR@|${LB_LINUX_FLAVOURS}|g" \
-			    -e "s|@LINUX@|/${_INITRAMFS}/vmlinuz|g" \
-			    -e "s|@INITRD@|/${_INITRAMFS}/initrd.img|g" \
-			"${_TARGET}/live.cfg.in" >> "${_TARGET}/live.cfg"
-
-			rm -f "${_TARGET}/live.cfg.in"
-			;;
-
-		*)
-			_NUMBER="0"
-
-			for _FLAVOUR in ${LB_LINUX_FLAVOURS}
-			do
-				_NUMBER="$((${_NUMBER} + 1))"
-
-				mv binary/${_INITRAMFS}/vmlinuz-*-${_FLAVOUR} binary/${_INITRAMFS}/vmlinuz${_NUMBER}
-				mv binary/${_INITRAMFS}/initrd.img-*-${_FLAVOUR} binary/${_INITRAMFS}/initrd${_NUMBER}.img
-
-				if [ "${_NUMBER}" -gt 1 ]
-				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"
-				fi
-
-				sed -i -e "s|@FLAVOUR@|${_FLAVOUR}|g" \
-				       -e "s|@LINUX@|/${_INITRAMFS}/vmlinuz${_NUMBER}|g" \
-				       -e "s|@INITRD@|/${_INITRAMFS}/initrd${_NUMBER}.img|g" \
-				"${_TARGET}/live.cfg"
-			done
-
-			rm -f "${_TARGET}/live.cfg.in"
-			;;
-	esac
+	rm -f "${_TARGET}/live.cfg.in"
 fi
 
+Echo_message "Menu for $_NUMBER kernels created..."
+
 if [ -e chroot/etc/os-release ]
 then
 	_VERSION="$(. chroot/etc/os-release && echo ${VERSION_ID})"
@@ -261,7 +263,8 @@
 _MINUTE="$(date +%M)"
 _SECOND="$(date +%S)"
 
-_LINUX_VERSIONS="$(for _LINUX in chroot/boot/vmlinuz-* ; do chroot chroot apt-cache policy $(basename ${_LINUX} | sed -e 's|vmlinuz-|linux-image-|') | awk '/Installed: / { print $2 }' ; done | sort -Vru | tr "\n" " ")"
+_LINUX_VERSIONS="$(for i in chroot/boot/vmlinuz-* ; do chroot chroot dpkg -S "$(basename $i)" ; done \
+	| cut -d: -f1 | xargs chroot chroot dpkg -s | awk '/Version: / { print $2 }' | sort -Vru | tr "\n" " ")"
 
 _LIVE_BUILD_VERSION="$(lb --version)"
 _LIVE_BOOT_VERSION="$(chroot chroot apt-cache policy live-boot | awk '/Installed: / { print $2 }')"

Reply to: