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

From: Dubiousjim <[email-masked]>
Date: Wed, 13 Mar 2013 16:29:57 -0400

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
extlinux.conf.new 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
http://www.syslinux.org/wiki/index.php/SYSLINUX and at
http://www.syslinux.org/wiki/index.php/Comboot/menu.c32).

(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
b/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)
 xen_opts=dom0_mem=256M
+
+# 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
password-protected
+# but you can include "MENU PASSWD" in any entries in
/etc/update-extlinux.d/
+password=''
diff --git a/main/syslinux/update-extlinux
b/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"
 			initramfs="initramfs-$tag"
+               else
+                       initramfs=
 		fi
 		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" >> $conf.new
 		fi
 		echo "  MENU LABEL Xen + Linux $tag" >> $conf.new
-               echo "  KERNEL mboot.c32" >> $conf.new
+               echo "  COM32 mboot.c32" >> $conf.new
 		echo "  APPEND xen.gz $xen_opts --- $(basename $kernel)
 		root=$root modules=${modules}${TYPE:+,$TYPE}
 		$default_kernel_opts --- $initramfs" >> $conf.new
 		echo "" >> $conf.new
 		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
 		label=$lst
@@ -127,38 +124,77 @@ for kernel in $(find /boot -name "vmlinuz-*" -type
f); do
 		echo "  MENU DEFAULT" >> $conf.new
 	fi
 	echo "  MENU LABEL Linux $tag" >> $conf.new
-       echo "  KERNEL $(basename $kernel)" >> $conf.new
-       echo "  APPEND $initramfs root=$root
modules=${modules}${TYPE:+,$TYPE} $default_kernel_opts" >> $conf.new
+       echo "  LINUX $(basename $kernel)" >> $conf.new
+       if [ -f "/boot/initramfs-$tag" ]; then
+               everbose "Found initramfs: /boot/initramfs-$tag"
+               echo "  INITRD initramfs-$tag" >> $conf.new
+       fi
+       echo "  APPEND root=$root modules=${modules}${TYPE:+,$TYPE}
$default_kernel_opts" >> $conf.new
 	echo "" >> $conf.new
 	lst=$(($lst + 1))
 done
 
-if [ -f "/boot/memtest" ]; then
+if [ -n "$password" ]; then
+       echo "NOESCAPE 1" >> $conf.new
+       echo "MENU MASTER PASSWD $password" >> $conf.new
+       echo "" >> $conf.new
+       chmod o-r $conf.new
+fi
+
+everbose "$lst entries found."
+
+for entry in /etc/update-extlinux.d/*; do
+       [ -f "$entry" ] && { cat $entry; echo ""; } >> $conf.new
+done
+
+echo "MENU SEPARATOR" >> $conf.new
+echo "" >> $conf.new
+
+if [ -f "/boot/hdt.c32" ]; then
+       everbose "Found Hardware Detection Tool: /boot/hdt.c32"
+       echo "LABEL hdt" >> $conf.new
+       echo "  MENU LABEL Hardware info" >> $conf.new
+       if [ -n "$password" ]; then
+               echo "  MENU PASSWD" >> $conf.new
+       fi
+       echo "  COM32 hdt.c32" >> $conf.new
+       if [ -f "/boot/memtest" ]; then
+               everbose "Found memtest86+: /boot/memtest"
+               echo "  APPEND memtest=memtest" >> $conf.new
+       fi
+       echo "" >> $conf.new
+elif [ -f "/boot/memtest" ]; then
 	everbose "Found memtest86+: /boot/memtest"
 	echo "LABEL memtest" >> $conf.new
 	echo "  MENU LABEL Memtest86+" >> $conf.new
         echo "  KERNEL memtest" >> $conf.new
 	echo "" >> $conf.new
-       lst=$(($lst + 1))
 fi
 
-everbose "$lst entries found."
+if [ -f "/boot/reboot.c32" ]; then
+       everbose "Found reboot"
+       echo "LABEL reboot" >> $conf.new
+       echo "  MENU LABEL Reboot" >> $conf.new
+        echo "  COM32 reboot.c32" >> $conf.new
+       echo "" >> $conf.new
+fi
 
-for entry in /etc/update-extlinux.d/*; do
-       [ -f "$entry" ] && cat $entry >> $conf.new
-done
+if diff -q $conf.new $conf >/dev/null 2>&1; then
+       everbose "Configuration unchanged."
+       rm $conf.new
+fi
 
 if [ "$overwrite" != "1" ]; then
 	exit 0
-fi
+elif [ -f "$conf.new" ]; 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.new $conf
 fi
 
-mv $conf.new $conf
-
 everbose "Installing libutil.c32 mboot.c32 menu.c32 vesamenu.c32 to
 /boot."
 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"
 sha256sums="f3af6b9d91ee047fca06b9b6be965da390e1c2e6fa602de090046c3b2a3144ad
  syslinux-5.02-pre3.tar.xz
-ee970729e981ee1756ffe97f0cdda652d1e82773993310eeecfca1f2ddbe718b 
update-extlinux.conf
-261c33f782f23fef134abbd9ddfc58535a1ed6d7214cbf9a8a2d2a17edfd5bcf 
update-extlinux"
+e5c74f663d10efd61f58380001e36fdce4915e4d82e64e63e253fc0ed24e1744 
update-extlinux.conf
+c16b17512454e0e54b0f1751fcbac1b06a0b0cbaef0038acd7253a051735837d 
update-extlinux"
 sha512sums="a1d90fe0d6da8257da5715a7c1c9a0f004ae6573c1077f3eb16761b478d42c736068a8f3f4650eb3bdfeba1de75ee33ccfa0575a679c6fde749dd3b58ace6429
  syslinux-5.02-pre3.tar.xz
-d0c5a0891841623c8905864caadf58866d4b9f1f893725712c6813af6cb6d64f0c08f2a3783fda56fcb1cbcc1a0a73e65562339f5591f38ee5cb213b2d16c680
 update-extlinux.conf
-fe9ae74060214bf52bdd7178c0a50083a0ff7770c1f617a0020fbec17e6b933375dbc9cdaba8c52e30dfe19dcebbb025206230fc67995dd57fb2d121e5111573
 update-extlinux"
+07ca743c84e3a62bb50b608bbb86cf1e08fa474ed47738d9d975c7f3bd91128755ad8d0bd372fad3f1bf53a5e52f7b2edf231e5e80d143746c1cfa67f21b484d
 update-extlinux.conf
+e59c1de8d518521a00320f79bf869f7241f1c2abcffe7d54ec66a333ed0c99dadbfc2a19d0774e121b2ab5cb91b5df3d35ede64b280037ba7ce87affb820f525
 update-extlinux"

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---