For discussion of Alpine Linux development and developer support

[alpine-devel] some patches for syslinux/update-extlinux

Message ID
Sender timestamp
DKIM signature
Download raw message
While I'm sending in some patches (I've got a bunch more, just waiting
for time to clean them up and explain them), here are some ideas for the
update-extlinux pieces of syslinux. Below are some git patches against
the aports tree. But before that, I'll explain what these patches do.

First, the update-extlinux script that Alpine supplies currently looks
for a /boot/memtest, and if it finds it, it adds another entry to the
bootmenu. I extend that behavior to two further elements: /boot/hdt.c32
and /boot/reboot.c32. These are both supplied with the syslinux sources.
If one wants bootmenu entries for these, it is already possible to
achieve that in a way using the /etc/update-extlinux.d/ folder; but the
present system is more intelligent. Also, we don't add an entry for
memtest if adding an entry for hdt, because hdt can already invoke
memtest as one of its menu options. Using hdt to its full capacity
requires finding or generating modules.pcimap and pci.ids files for your
machine, and installing them in /boot. We might want to document this,
which I don't here (but the online docs for hdt do); but hdt is still
pretty useful without those.

hdt provides a curses-like interface to display lots of hardware info
about your machine; reboot reboots your machine (obviously). The
syslinux sources also provide a shutdown module, but I couldn't get this
to work and looking at the sources reveals it to be for machines with
apm enabled. Not sure how many machines that applies to anymore.

The second change is to detect a password= setting in the
update-extlinux.conf file. This can be generated using a perl script
supplied with the syslinux sources, which I've changed the APKBUILD to
also install. You need perl and perl-digest-sha1 installed to run that
script, but having generated the password once, they don't need to stay
installed. The only auto-generted entry that requires a password (if a
password is supplied in the config file) is hdt. However, one can add
"MENU PASSWD" to custom entries that one puts in
/etc/update-extlinux.d/. I do this, for example, to provide a menu entry
to boot from a USB key, but only when the password is provided. (If you
want to do this kind of thing, you should also password-protect your
bios, else someone can just escape to bios before the extlinux
bootloader starts up, and change the boot device order there.)

The third change is some refinements/bugfixes to the update-extlinux
script. We invoke mboot.c32 and the Linux kernel using the more specific
commands COM32 and LINUX rather than the current, more general command
KERNEL. We supply the initramfs using a separate INITRD line, rather
than as the first argument on the APPEND line. And in two places in
loops (once for Xen, and once for normal kernels), we make sure not to
use a stale initramfs from an earlier iteration, when the appropriate
initramfs for the current iteration is missing. (First two sentences
describe refinements; last sentence describes bugfix.)

Fourth, if when running the update-extlinux script the config file is
unchanged, we don't create a pointless extlinux.conf.old or file underneath /boot.

I can appreciate that you might want to break these up into separate
patches; or that you might want to adopt only some of them---though I
encourage you to adopt all of them. If so, and you want me to do the
breaking-up, I'll be glad to, just let me know. Also, I probably won't
be able to attend to it right away.

I've been using these patches in practice on my laptop for some months
and have had no difficulties with them. They really are straightforward,
one just has to read the syslinux docs (for example, at and at

(Since I'm sending the patches through webmail rather than directly from
git (don't have sendmail set up yet on this machine), I fear some
unwanted line breaks are going to get inserted into the patches...)

diff --git a/main/syslinux/update-extlinux.conf
index 59f9e60..6cabc61 100644
--- a/main/syslinux/update-extlinux.conf
+++ b/main/syslinux/update-extlinux.conf
@@ -42,3 +42,12 @@ default=grsec
 # options to hand to xen hypervisor, useful ones are:
 #    dom0_mem=256M (give domain-0 environment 256M ram)
+# none of /boot/memtest, /boot/hdt.c32, or /boot/reboot.c32 are
installed by default
+# but entries for them will be auto-generated if they're present
+# optional password
+# generate using /usr/sbin/sha1pass, which has a runtime dependency on
perl and perl-digest-sha1
+# of the auto-generated entries, only hdt (if present) is
+# but you can include "MENU PASSWD" in any entries in
diff --git a/main/syslinux/update-extlinux
index 74bd429..1bbf7a0 100755
--- a/main/syslinux/update-extlinux
+++ b/main/syslinux/update-extlinux
@@ -91,6 +91,8 @@ if [ -f "/boot/xen.gz" ]; then
 		if [ -f "/boot/initramfs-$tag" ]; then
 			everbose "Found initramfs: /boot/initramfs-$tag"
+               else
+                       initramfs=
 		label=xen-$(grep -w -l $tag
 		/usr/share/kernel/*/kernel.release \
 				| cut -d/ -f5)
@@ -103,7 +105,7 @@ if [ -f "/boot/xen.gz" ]; then
 			echo "  MENU DEFAULT" >> $
 		echo "  MENU LABEL Xen + Linux $tag" >> $
-               echo "  KERNEL mboot.c32" >> $
+               echo "  COM32 mboot.c32" >> $
 		echo "  APPEND xen.gz $xen_opts --- $(basename $kernel)
 		root=$root modules=${modules}${TYPE:+,$TYPE}
 		$default_kernel_opts --- $initramfs" >> $
 		echo "" >> $
 		lst=$(($lst + 1))
@@ -113,11 +115,6 @@ fi
 for kernel in $(find /boot -name "vmlinuz-*" -type f); do
 	tag=$(basename $kernel | cut -b9-)
 	everbose "Found kernel: $kernel"
-       if [ -f "/boot/initramfs-$tag" ]; then
-               everbose "Found initramfs: /boot/initramfs-$tag"
-               initramfs="initrd=initramfs-$tag"
-       fi
 	label=$(grep -w -l $tag /usr/share/kernel/*/kernel.release | cut
 	-d/ -f5)
 	if [ -z "$label" ]; then
@@ -127,38 +124,77 @@ for kernel in $(find /boot -name "vmlinuz-*" -type
f); do
 		echo "  MENU DEFAULT" >> $
 	echo "  MENU LABEL Linux $tag" >> $
-       echo "  KERNEL $(basename $kernel)" >> $
-       echo "  APPEND $initramfs root=$root
modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $
+       echo "  LINUX $(basename $kernel)" >> $
+       if [ -f "/boot/initramfs-$tag" ]; then
+               everbose "Found initramfs: /boot/initramfs-$tag"
+               echo "  INITRD initramfs-$tag" >> $
+       fi
+       echo "  APPEND root=$root modules=${modules}${TYPE:+,$TYPE}
$default_kernel_opts" >> $
 	echo "" >> $
 	lst=$(($lst + 1))
-if [ -f "/boot/memtest" ]; then
+if [ -n "$password" ]; then
+       echo "NOESCAPE 1" >> $
+       echo "MENU MASTER PASSWD $password" >> $
+       echo "" >> $
+       chmod o-r $
+everbose "$lst entries found."
+for entry in /etc/update-extlinux.d/*; do
+       [ -f "$entry" ] && { cat $entry; echo ""; } >> $
+echo "MENU SEPARATOR" >> $
+echo "" >> $
+if [ -f "/boot/hdt.c32" ]; then
+       everbose "Found Hardware Detection Tool: /boot/hdt.c32"
+       echo "LABEL hdt" >> $
+       echo "  MENU LABEL Hardware info" >> $
+       if [ -n "$password" ]; then
+               echo "  MENU PASSWD" >> $
+       fi
+       echo "  COM32 hdt.c32" >> $
+       if [ -f "/boot/memtest" ]; then
+               everbose "Found memtest86+: /boot/memtest"
+               echo "  APPEND memtest=memtest" >> $
+       fi
+       echo "" >> $
+elif [ -f "/boot/memtest" ]; then
 	everbose "Found memtest86+: /boot/memtest"
 	echo "LABEL memtest" >> $
 	echo "  MENU LABEL Memtest86+" >> $
         echo "  KERNEL memtest" >> $
 	echo "" >> $
-       lst=$(($lst + 1))
-everbose "$lst entries found."
+if [ -f "/boot/reboot.c32" ]; then
+       everbose "Found reboot"
+       echo "LABEL reboot" >> $
+       echo "  MENU LABEL Reboot" >> $
+        echo "  COM32 reboot.c32" >> $
+       echo "" >> $
-for entry in /etc/update-extlinux.d/*; do
-       [ -f "$entry" ] && cat $entry >> $
+if diff -q $ $conf >/dev/null 2>&1; then
+       everbose "Configuration unchanged."
+       rm $
 if [ "$overwrite" != "1" ]; then
 	exit 0
+elif [ -f "$" ]; then
+       # keep a backup just in case
+       if [ -f "$conf" ]; then
+               mv $conf $conf.old
+       fi
-# keep a backup just in case
-if [ -f "$conf" ]; then
-       mv $conf $conf.old
+       mv $ $conf
-mv $ $conf
 everbose "Installing libutil.c32 mboot.c32 menu.c32 vesamenu.c32 to
 cp /usr/share/syslinux/libutil.c32 \
 	/usr/share/syslinux/mboot.c32 \
diff --git a/main/syslinux/APKBUILD b/main/syslinux/APKBUILD
index ba8f065..791c261 100644
--- a/main/syslinux/APKBUILD
+++ b/main/syslinux/APKBUILD
@@ -39,6 +39,7 @@ build() {
 package() {
 	cd "$_builddir"
 	make INSTALLROOT="$pkgdir" MANDIR=/usr/share/man local-install
+       install -D -m755 utils/sha1pass "$pkgdir"/usr/sbin/sha1pass ||
return 1
 	mkdir -p "$pkgdir"/etc/update-extlinux.d
 	cp "$srcdir"/update-extlinux.conf "$pkgdir"/etc/
@@ -48,11 +49,11 @@ package() {
 md5sums="88fd0566415b95979818188b244505a7  syslinux-5.02-pre3.tar.xz
-7ef73a7a858b8aa1ac6635d6391ac8e5  update-extlinux.conf
-d420755f22dc70a617e2d7b96d3c39b3  update-extlinux"
+7b2dbc5bd981a0748df31424bba658e7  update-extlinux.conf
+52bd42a63bac0baa263663f1d4510282  update-extlinux"