Bug#573173: support multiple kernel versions with same flavour

2016-11-28 Thread Raphael Hertzog
Control: tag -1 - patch

Hello Michal,

On Thu, 25 Aug 2016, Michal Suchanek wrote:
> sending fixed/updated version of the patch.
> This works for me quite well with live-build in Debian and Syslinux.
> Grub is unsupported.

As long as grub is unsupported, I can't really apply this patch.
In particular since grub is required for EFI support nowadays.

Also I'm not sure that I like the fact that we advertise the kernel
version by default. As you might have noticed, the default grub config
in Debian hides the current kernel version. You only see it in a sub-menu.

We should probably aim for something similar in live-build when
we have multiple kernels.

Cheers,
-- 
Raphaël Hertzog ◈ Debian Developer

Support Debian LTS: http://www.freexian.com/services/debian-lts.html
Learn to master Debian: http://debian-handbook.info/get/



Bug#573173: support multiple kernel versions with same flavour

2016-08-25 Thread Michal Suchanek
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 

Bug#573173: support multiple kernel versions with same flavour

2016-08-16 Thread Michal Suchanek
Package: live-build
Version: 1:20151215
Followup-For: Bug #573173

Hello,

sending patch against version of live-build currently in debian:
20151215

The patch was rejected in the past mainly due to pending rewrite of
live-build in python which is no longer planned AFAIK.

This patch makes the menu more verbose showing the kernel version and
also makes it possible to build image with multiple kernels of the same
flavour.

Kernels are sorted lowest first (from stable to experimental).

-- Package-specific info:

-- System Information:
Debian Release: stretch/sid
  APT prefers testing
  APT policy: (910, 'testing'), (900, 'stable'), (610, 'oldstable'), (410, 
'unstable'), (400, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armhf

Kernel: Linux 4.6.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)

Versions of packages live-build depends on:
ii  debootstrap  1.0.81

Versions of packages live-build recommends:
ii  apt-utils   1.3~pre2
ii  cpio2.11+dfsg-5
ii  live-boot-doc   1:20160511
ii  live-config-doc 5.20160608
pn  live-manual-html | live-manual  
ii  wget1.18-2

Versions of packages live-build suggests:
ii  debian-keyring  2016.07.02
ii  gpgv1.4.20-6

-- no debconf information
Build menu for multiple kernels of the same flavour.

This allows to include stable and sid kernel in single image to support wider
range of hardware.

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


Index: live-build-20151215mk1/scripts/build/binary_syslinux
===
--- live-build-20151215mk1.orig/scripts/build/binary_syslinux	2016-08-16 11:20:07.691549799 +0200
+++ live-build-20151215mk1/scripts/build/binary_syslinux	2016-08-16 11:20:07.687549755 +0200
@@ -197,50 +197,43 @@
 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 +$
+	then
+		_FLAVOURS_GIT=""
+	else
+		_FLAVOURS_GIT="$(echo ${LB_LINUX_FLAVOURS} | tr " " "\n" | sed -e '/^$/d' -e 's/$/+/')"
+	fi
+
+	_NUMBER="0"
+
+	for _FLAVOUR in ${_FLAVOURS} ${_FLAVOURS_GIT}
+	do
+		for _KERNEL in $(ls binary/live/vmlinuz-*-${_FLAVOUR})
+		do
+			_NUMBER="$((${_NUMBER} + 1))"
+			_KVER=$(basename "${_KERNEL}" -"${_FLAVOUR}" | sed -e 's/vmlinuz-//')
+			_INITRD="$(echo "${_KERNEL}" | sed -e 's|/vmlinuz-|/initrd.img-|')"
+			mv "${_KERNEL}" binary/${_INITRAMFS}/vmlinuz${_NUMBER}
+			mv "${_INITRD}" binary/${_INITRAMFS}/initrd${_NUMBER}.img
+
+			if [ "${_NUMBER}" -gt 1 ]
+			then
+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" \
+			-e "s|@APPEND_LIVE@|${LB_BOOTAPPEND_LIVE}|g" \
+			-e "s|@APPEND_FAILSAFE@|${LB_BOOTAPPEND_FAILSAFE}.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"