Bug#470398: grub-pc: possible implementation

Felipe Sateler fsateler at gmail.com
Sun Mar 16 17:36:37 UTC 2008


Package: grub-pc
Version: 1.96+20080228-1
Followup-For: Bug #470398

The attached patch provides a possible implementation for an altoptions
mechanism. To add alternate options one must edit /etc/default/grub and
define and export some variables:
GRUB_ALTERNATIVES: this variable contains a space delimited sequence of
alternatives.
For each alternative listed in GRUB_ALTERNATIVES, define and export
GRUB_ALTERNATIVE_<alternative>_OPTS: this variable contains all extra
boot parameters.
GRUB_ALTERNATIVE_<alternative>_NAME: This variable contains the name of
the alternative. It will be displayed in the menu.

Obviously, the <alternative> value must case-sensitively match the value
listed in GRUB_ALTERNATIVES.

For example, the following /etc/default/grub:

--- start ---
# This file is sourced by update-grub, and its variables are propagated
# to its children in /etc/grub.d/
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=Debian
GRUB_CMDLINE_LINUX=quiet

export GRUB_ALTERNATIVES="BOOTCHART CACA"
export GRUB_ALTERNATIVE_BOOTCHART_OPTS="init=/sbin/bootchartd"
export GRUB_ALTERNATIVE_BOOTCHART_NAME="Bootchart"
export GRUB_ALTERNATIVE_CACA_OPTS="verbose"
export GRUB_ALTERNATIVE_CACA_NAME="Caca"
--- end ---

Will produce the following output from 10_linux:

--- start ---
menuentry "Debian GNU/Linux, linux 2.6.24-1-amd64" {
        linux   (hd0,6)/boot/vmlinuz-2.6.24-1-amd64 root=/dev/sda6 ro quiet
        initrd  (hd0,6)/boot/initrd.img-2.6.24-1-amd64
}
menuentry "Debian GNU/Linux, linux 2.6.24-1-amd64 (single-user mode)" {
        linux   (hd0,6)/boot/vmlinuz-2.6.24-1-amd64 root=/dev/sda6 ro single quiet
        initrd  (hd0,6)/boot/initrd.img-2.6.24-1-amd64
}
menuentry "Debian GNU/Linux, linux 2.6.24-1-amd64 (Bootchart)" {
        linux   (hd0,6)/boot/vmlinuz-2.6.24-1-amd64 root=/dev/sda6 ro quiet init=/sbin/bootchartd
        initrd  (hd0,6)/boot/initrd.img-2.6.24-1-amd64
}
menuentry "Debian GNU/Linux, linux 2.6.24-1-amd64 (Caca)" {
        linux   (hd0,6)/boot/vmlinuz-2.6.24-1-amd64 root=/dev/sda6 ro quiet verbose
        initrd  (hd0,6)/boot/initrd.img-2.6.24-1-amd64
}
--- end ---


Note that I only implemented one version on 10_linux. Perhaps variable
names need to be changed to allow for hurd or other kernels.


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.24-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages grub-pc depends on:
ii  debconf [debconf-2.0]    1.5.20          Debian configuration management sy
ii  grub-common              1.96+20080228-1 GRand Unified Bootloader, version 
ii  libc6                    2.7-9           GNU C Library: Shared libraries
ii  liblzo1                  1.08-3          data compression library (old vers
ii  libncurses5              5.6+20080203-1  Shared libraries for terminal hand

grub-pc recommends no packages.

-- debconf information:
* grub-pc/linux_cmdline:
* grub-pc/chainload_from_menu.lst: true
-------------- next part --------------
--- 10_linux.orig	2008-03-07 13:19:07.000000000 -0300
+++ /etc/grub.d/10_linux	2008-03-07 13:28:57.000000000 -0300
@@ -128,6 +128,24 @@
   cat << EOF
 }
 EOF
+  for alternative in $GRUB_ALTERNATIVES ; do
+    var_name=`echo GRUB_ALTERNATIVE_${alternative}_OPTS`
+    alt_options=`eval "echo \\$$var_name"`
+    var_name=`echo GRUB_ALTERNATIVE_${alternative}_NAME`
+    alt_name=`eval "echo \\$$var_name"`
+    cat << EOF
+menuentry "${OS}, linux ${version} (${alt_name})" {
+	linux	${grub_dirname}/${basename} root=${GRUB_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${alt_options}
+EOF
+    if test -n "${initrd}" ; then
+      cat << EOF
+	initrd	${grub_dirname}/${initrd}
+EOF
+    fi
+    cat << EOF
+}
+EOF
+  done
 
   list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
 done


More information about the Pkg-grub-devel mailing list