Bug#547705: grub-pc: Screws up "default" entry in menu.lst when updatedefaultentry is false

Matthijs Kooijman matthijs at stdin.nl
Mon Sep 21 17:28:45 UTC 2009


Package: grub-pc
Version: 1.97~beta3-1
Severity: normal

Hi,

I've upgraded grub to grub-pc, which does some magic chainloading (on my
request). However, this screwed up my default entry in menu.lst, which
used to read "default saved" and now reads "default 0saved".

>From following the logic in /usr/lib/grub-legacy/update-grub, it seems
this is caused by updatedefaultentry not being set.

The following code parses the current default entry, including the setting of
use_grub_set_default. Note that this does not happen when updatedefaultentry is
false.

	#Finding the value the default line
	use_grub_set_default="false"
	if test "$updatedefaultentry" = "true" ; then
		defaultEntryNumber=$(sed -ne 's/^[[:blank:]]*default[[:blank:]]*\(.*\).*/\1/p' $menu)

		if [ "$defaultEntryNumber" = "saved" ] ; then
			defaultEntryNumber=$(sed 'q' "$grub_dir/default")
			use_grub_set_default="true"
		fi

		if test -n "$defaultEntryNumber"; then
			defaultEntryNumberPlusOne=$(expr $defaultEntryNumber \+ 1);
			defaultEntry=$(grep "^[[:blank:]]*title" $menu | sed -ne "${defaultEntryNumberPlusOne}p" | sed -ne ";s/^[[:blank:]]*title[[:blank:]]*//p")
			defaultEntry=$(echo $defaultEntry | sed -e "s/[[:blank:]]*$//") # don't trust trailing blanks   
		else
			notChangeDefault="yes"
		fi
	else
			notChangeDefault="yes"
	fi

Further down, the default number is updated in the generated menu.lst file. The
actual code for the non-grub2 case is removed. Note that if grub 2 is not being
installed, the default is not changed when notChangeDefault is set, which is
the case if updatedefaultentry is false (see the final else clause above).

	#Updating the default number
	if [ "$LET_US_TRY_GRUB_2" = "true" ] && test -f /boot/grub/core.img ; then
		set_default_value "0"
	elif test -z "$notChangeDefault"; then
		[ Code removed ]
	fi

This code uses the set_default_value function, which looks like:

	# Function to update the default value
	set_default_value() {
		if [ "$use_grub_set_default" = "true" ] ; then
			if [ -f /usr/lib/grub-legacy/grub-set-default ] ; then
				/usr/lib/grub-legacy/grub-set-default $1
			else
				grub-set-default $1
			fi
		else
			value="$1"
			newmenu=$(tempfile)
			sed -e "s/^[[:blank:]]*default[[:blank:]]*[[:digit:]]*\(.*\)/default         ${value}\1/;b" $menu > $newmenu
			cat $newmenu > $menu
			rm -f $newmenu
			unset newmenu
		fi
	}

Here, the second half of the if contains a sed that matches numbers only (which
seems to make sense, since it only runs if use_grub_set_default is false,
right?). However, this breaks when the default config is "saved" and not a
number, which can occur as shown above.

To fix this, I'd probably change the first snippet above, to not check for
updatedefaultentry if LET_US_TRY_GRUB_2 is set. This might get complicated,
though, so perhaps something more elegant can be done?

Gr.

Matthijs

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

Kernel: Linux 2.6.31-rc8 (PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages grub-pc depends on:
ii  debconf [debconf-2.0]       1.5.27       Debian configuration management sy
ii  grub-common                 1.97~beta3-1 GRand Unified Bootloader, version 
ii  libc6                       2.9-26       GNU C Library: Shared libraries
ii  ucf                         3.0022       Update Configuration File: preserv

grub-pc recommends no packages.

Versions of packages grub-pc suggests:
ii  desktop-base                  5.0.5      common files for the Debian Deskto
ii  genisoimage                   9:1.1.9-1  Creates ISO-9660 CD-ROM filesystem

-- debconf information excluded





More information about the Pkg-grub-devel mailing list