Hi again, 

You'll find attached my second set of patches for an inclusion in grub-pc (an 
inclusion in any xen-* package would need a different handling of the variables 
in /etc/default/grub )

* grub-pc_00_allow_xen.patch
        Moves some functionality of /etc/grub.d/10_linux into /etc/grub.d/common

* grub-pc_01_allow_xen.patch
        Creates 08_xen which parses "correctly" (AFAIK) the kernel config's to 
know
        which ones can be dom0's.

* grub-pc_02_allow_xen.patch
        Alters the /etc/default/grub and /usr/sbin/update-grub to handle the 
Xen 
variables.

I hope that these patches are in a more acceptable form.

Best regards, 

OdyX

-- 
Didier Raboud, proud Debian user.
CH-1802 Corseaux
[EMAIL PROTECTED]
diff -Naur etc/grub.d/10_linux /etc/grub.d/10_linux
--- etc/grub.d/10_linux	2008-11-10 16:27:12.000000000 +0100
+++ /etc/grub.d/10_linux	2008-11-17 21:24:54.000000000 +0100
@@ -21,6 +21,8 @@
 libdir=${exec_prefix}/lib
 . ${libdir}/grub/update-grub_lib
 
+. /etc/grub.d/common
+
 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
   OS=GNU/Linux
 else
@@ -29,64 +31,10 @@
 
 # loop-AES arranges things so that /dev/loop/X can be our root device, but
 # the initrds that Linux uses don't like that.
-case ${GRUB_DEVICE} in
-  /dev/loop/*|/dev/loop[0-9])
-    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
-  ;;
-esac
-
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || [ "`grub-probe -t abstraction --device ${GRUB_DEVICE}`" != "" ] ; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
-
-test_numeric ()
-{
-  local a=$1
-  local cmp=$2
-  local b=$3
-  if [ "$a" = "$b" ] ; then
-    case $cmp in
-      ge|eq|le) return 0 ;;
-      gt|lt) return 1 ;;
-    esac
-  fi
-  if [ "$cmp" = "lt" ] ; then
-    c=$a
-    a=$b
-    b=$c
-  fi
-  if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then
-    return 0
-  else
-    return 1
-  fi
-}
+GRUB_DEVICE=`check_loop "${GRUB_DEVICE}"`
 
-test_gt ()
-{
-  local a=`echo $1 | sed -e "s,.*/vmlinu[zx]-,,g;s/[._-]\(pre\|rc\|test\|git\|old\)/~\1/g"`
-  local b=`echo $2 | sed -e "s,.*/vmlinu[zx]-,,g;s/[._-]\(pre\|rc\|test\|git\|old\)/~\1/g"`
-  if [ "x$b" = "x" ] ; then
-    return 0
-  fi
-  dpkg --compare-versions "$a" gt "$b"
-  return $?
-}
+LINUX_ROOT_DEVICE=`root_device_uuid "${GRUB_DEVICE_UUID}" "${GRUB_DISABLE_LINUX_UUID}" "${GRUB_DEVICE}"`
 
-find_latest ()
-{
-  local a=""
-  for i in $@ ; do
-    if test_gt "$i" "$a" ; then
-      a="$i"
-    fi
-  done
-  echo "$a"
-}
 
 list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
         if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
diff -Naur etc/grub.d/common /etc/grub.d/common
--- etc/grub.d/common	1970-01-01 01:00:00.000000000 +0100
+++ /etc/grub.d/common	2008-11-17 21:23:19.000000000 +0100
@@ -0,0 +1,89 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
+test_numeric ()
+{
+  local a=$1
+  local cmp=$2
+  local b=$3
+  if [ "$a" = "$b" ] ; then
+    case $cmp in
+      ge|eq|le) return 0 ;;
+      gt|lt) return 1 ;;
+    esac
+  fi
+  if [ "$cmp" = "lt" ] ; then
+    c=$a
+    a=$b
+    b=$c
+  fi
+  if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then
+    return 0
+  else
+    return 1
+  fi
+}
+
+test_gt ()
+{
+  local a=`echo $1 | sed -e "s,.*/vmlinu[zx]-,,g;s/[._-]\(pre\|rc\|test\|git\|old\)/~\1/g"`
+  local b=`echo $2 | sed -e "s,.*/vmlinu[zx]-,,g;s/[._-]\(pre\|rc\|test\|git\|old\)/~\1/g"`
+  if [ "x$b" = "x" ] ; then
+    return 0
+  fi
+  dpkg --compare-versions "$a" gt "$b"
+  return $?
+}
+
+find_latest ()
+{
+  local a=""
+  for i in $@ ; do
+    if test_gt "$i" "$a" ; then
+      a="$i"
+    fi
+  done
+  echo "$a"
+}
+
+# loop-AES arranges things so that /dev/loop/X can be our root device, but
+# the initrds that Linux uses don't like that.
+check_loop ()
+{
+  case $1 in 
+    /dev/loop/*|/dev/loop[0-9])
+      echo `losetup $1 | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`;;
+    *)
+      echo $1;;
+  esac
+}
+
+root_device_uuid()
+{
+  local device_uuid=$1
+  local disable_uuid=$2
+  local grub_device=$3
+
+  if [ "x${device_uuid}" = "x" ] || [ "x${disable_uuid}" = "xtrue" ] \
+      || ! test -e "/dev/disk/by-uuid/${device_uuid}" \
+      || [ "`grub-probe -t abstraction --device ${grub_device}`" != "" ] ; then
+    echo ${grub_device}
+  else
+    echo "UUID=${device_uuid}"
+  fi
+}
diff -Naur etc/grub.d/09_xen /etc/grub.d/09_xen
--- etc/grub.d/09_xen	1970-01-01 01:00:00.000000000 +0100
+++ /etc/grub.d/09_xen	2008-11-17 22:28:10.000000000 +0100
@@ -0,0 +1,124 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+. ${libdir}/grub/update-grub_lib
+
+. /etc/grub.d/common
+
+if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
+  OS=Xen
+else
+  OS="${GRUB_DISTRIBUTOR} Xen"
+fi
+
+# loop-AES arranges things so that /dev/loop/X can be our root device, but
+# the initrds that Linux uses don't like that.
+GRUB_DEVICE=`check_loop ${GRUB_DEVICE}`
+
+XEN_ROOT_DEVICE=`root_device_uuid "${GRUB_DEVICE_UUID}" "${GRUB_DISABLE_XEN_UUID}" "${GRUB_DEVICE}"`
+
+xen_list=`for i in /boot/xen-*.gz /xen-*.gz ; do
+		if grub_file_is_not_garbage "$i" ; then
+			echo -n "$i ";
+		fi
+	done`
+
+if [ "x$xen_list" != "x" ] ; then
+  prepare_grub_to_access_device ${GRUB_DEVICE_BOOT}
+fi
+
+while [ "x$xen_list" != "x" ] ; do
+  xen=`find_latest $xen_list`
+  echo "Found Xen hypervisor image: $xen" >&2
+  basename_x=`basename $xen`
+  dirname_x=`dirname $xen`
+  rel_dirname_x=`make_system_path_relative_to_its_root $dirname_x`
+  version_x=`echo $basename_x | sed -e "s,^[^0-9]*-,,g" | sed -e "s,.gz,,g"`
+  alt_version_x=`echo $version_x | sed -e "s,\.old$,,g"`
+
+  xen_configfiles=`grep -l 'CONFIG_XEN_PRIVILEGED_GUEST=y' /boot/config-*`
+
+  for i in $xen_configfiles ; do
+    i=`echo $i | sed -e "s,/boot/config-,/boot/vmlinuz-,g"`;
+    if grub_file_is_not_garbage "$i"; then
+      list="$list $i";
+    fi
+  done
+
+  while [ "x$list" != "x" ] ; do
+    linux=`find_latest $list`
+    echo "\tFound linux image: $linux" >&2
+    basename=`basename $linux`
+    dirname=`dirname $linux`
+    rel_dirname=`make_system_path_relative_to_its_root $dirname`
+    version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
+    alt_version=`echo $version | sed -e "s,\.old$,,g"`
+    linux_root_device_thisversion="${XEN_ROOT_DEVICE}"
+
+    initrd=
+    for i in "initrd.img-${version}" "initrd-${version}.img" \
+  	   "initrd.img-${alt_version}" "initrd-${alt_version}.img"; do
+      if test -e "${dirname}/${i}" ; then
+        initrd="$i"
+        break
+      fi
+    done
+    if test -n "${initrd}" ; then
+      echo "\tFound initrd image: ${dirname}/${initrd}" >&2
+    else
+      # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
+      linux_root_device_thisversion=${GRUB_DEVICE}
+    fi
+
+    cat << EOF
+menuentry "${OS} hypervisor ${version_x}, linux ${version}" {
+	multiboot	${rel_dirname_x}/${basename_x} ${GRUB_CMDLINE_XEN}
+	module		${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}
+EOF
+  if test -n "${initrd}" ; then
+    cat << EOF
+	module		${rel_dirname}/${initrd}
+EOF
+  fi
+  cat << EOF
+}
+EOF
+
+  cat << EOF
+menuentry "${OS} hypervisor ${version_x}, linux ${version} (single-user mode)" {
+	multiboot       ${rel_dirname_x}/${basename_x} ${GRUB_CMDLINE_XEN}
+	module		${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro single ${GRUB_CMDLINE_LINUX}
+EOF
+  if test -n "${initrd}" ; then
+    cat << EOF
+	module		${rel_dirname}/${initrd}
+EOF
+  fi
+  cat << EOF
+}
+EOF
+
+  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
+done
+
+  xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $xen | tr '\n' ' '`
+done
diff -Naur etc/default/grub default-grub
--- etc/default/grub	2008-06-29 19:08:18.000000000 +0200
+++ /etc/default/grub	2008-11-17 22:37:50.000000000 +0100
@@ -10,3 +10,10 @@
 
 # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
 #GRUB_DISABLE_LINUX_UUID=true
+
+# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Xen
+#GRUB_DISABLE_XEN_UUID=true
+
+# Alter your Xen options (if existant)
+#GRUB_CMDLINE_XEN='dom0_mem=128M vga=ask'
+
diff -Naur usr/sbin/update-grub /usr/sbin/update-grub
--- usr/sbin/update-grub	2008-11-10 16:27:12.000000000 +0100
+++ /usr/sbin/update-grub	2008-11-17 15:36:07.000000000 +0100
@@ -152,7 +152,7 @@
 export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES
 
 # These are optional, user-defined variables.
-export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID
+export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_CMDLINE_XEN GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_DISABLE_XEN_UUID
 
 exec > ${grub_cfg}.new
 

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to