[xen] make pygrub work better with GPT partitions and grub2 on guest

myoung myoung at fedoraproject.org
Thu Oct 13 23:02:12 UTC 2011


commit a6bf624e71c7d84dd8bcb397a0d725aef7f87601
Author: Michael Young <m.a.young at durham.ac.uk>
Date:   Fri Oct 14 00:00:23 2011 +0100

    make pygrub work better with GPT partitions and grub2 on guest

 pygrubfix2.patch |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xen.spec         |    7 ++++-
 2 files changed, 88 insertions(+), 1 deletions(-)
---
diff --git a/pygrubfix2.patch b/pygrubfix2.patch
new file mode 100644
index 0000000..8bd40c7
--- /dev/null
+++ b/pygrubfix2.patch
@@ -0,0 +1,82 @@
+--- xen-4.1.2/tools/pygrub/src/pygrub.orig	2011-10-13 18:56:41.000000000 +0100
++++ xen-4.1.2/tools/pygrub/src/pygrub	2011-10-13 20:46:58.000000000 +0100
+@@ -78,9 +78,17 @@
+ def get_fs_offset_gpt(file):
+     fd = os.open(file, os.O_RDONLY)
+     # assume the first partition is an EFI system partition.
+-    os.lseek(fd, SECTOR_SIZE * 2, 0)
++    os.lseek(fd, SECTOR_SIZE, 0)
+     buf = os.read(fd, 512)
+-    return struct.unpack("<Q", buf[32:40])[0] * SECTOR_SIZE
++    partcount = struct.unpack("<L", buf[80:84])[0]
++    partsize = struct.unpack("<L", buf[84:88])[0]
++    i = partcount
++    offsets = []
++    while i>0:
++        buf = os.read(fd, partsize)
++        offsets.append(struct.unpack("<Q", buf[32:40])[0] * SECTOR_SIZE)
++        i -= 1
++    return offsets
+ 
+ FDISK_PART_SOLARIS=0xbf
+ FDISK_PART_SOLARIS_OLD=0x82
+@@ -116,7 +124,9 @@
+                 continue # no solaris magic at that offset, ignore partition
+ 
+         if type == FDISK_PART_GPT:
+-            offset = get_fs_offset_gpt(file)
++            for offset in get_fs_offset_gpt(file):
++                part_offs.append(offset)
++            break
+ 
+         # Active partition has 0x80 as the first byte.
+         # If active, prepend to front of list, otherwise append to back.
+@@ -394,7 +404,8 @@
+                            ["/boot/grub/menu.lst", "/boot/grub/grub.conf",
+                             "/grub/menu.lst", "/grub/grub.conf"]) + \
+                        map(lambda x: (x,grub.GrubConf.Grub2ConfigFile),
+-                           ["/boot/grub/grub.cfg", "/grub/grub.cfg"]) + \
++                           ["/boot/grub/grub.cfg", "/grub/grub.cfg",
++                            "/boot/grub2/grub.cfg", "/grub2/grub.cfg"]) + \
+                        map(lambda x: (x,grub.ExtLinuxConf.ExtLinuxConfigFile),
+                            ["/boot/isolinux/isolinux.cfg",
+                             "/boot/extlinux.conf"])
+--- xen-4.1.2/tools/pygrub/src/GrubConf.py.orig	2011-10-08 19:42:10.000000000 +0100
++++ xen-4.1.2/tools/pygrub/src/GrubConf.py	2011-10-13 20:53:13.000000000 +0100
+@@ -79,6 +79,8 @@
+         val = val.replace("(", "").replace(")", "")
+         if val[:5] == "msdos":
+             val = val[5:]
++        if val[:3] == "gpt":
++            val = val[3:]
+         self._part = int(val)
+     part = property(get_part, set_part)
+ 
+@@ -368,6 +370,7 @@
+         in_function = False
+         img = None
+         title = ""
++        menu_level=0
+         for l in lines:
+             l = l.strip()
+             # skip blank lines
+@@ -394,10 +397,17 @@
+                 img = []
+                 title = title_match.group(1)
+                 continue
+-            
++
++            if l.startswith("submenu"):
++                menu_level += 1
++
+             if l.startswith("}"):
+                 if img is None:
+-                    raise RuntimeError, "syntax error: closing brace without menuentry"
++                    if menu_level > 0:
++                        menu_level -= 1
++                        continue
++                    else:
++                        raise RuntimeError, "syntax error: closing brace without menuentry"
+ 
+                 self.add_image(Grub2Image(title, img))
+                 img = None
diff --git a/xen.spec b/xen.spec
index 18c7e99..1cd2666 100644
--- a/xen.spec
+++ b/xen.spec
@@ -6,7 +6,7 @@
 Summary: Xen is a virtual machine monitor
 Name:    xen
 Version: 4.1.1
-Release: 6%{?dist}
+Release: 7%{?dist}
 Group:   Development/Libraries
 License: GPLv2+ and LGPLv2+ and BSD
 URL:     http://xen.org/
@@ -48,6 +48,7 @@ Patch26: localgcc46fix.patch
 Patch28: pygrubfix.patch
 Patch29: xen-4.1-testing.23104.patch
 Patch30: xen-4.1-testing.23112.patch
+Patch31: pygrubfix2.patch
 
 Patch100: xen-configure-xend.patch
 
@@ -175,6 +176,7 @@ to build the xen packages.
 %patch28 -p1
 %patch29 -p1
 %patch30 -p1
+%patch31 -p1
 
 %patch100 -p1
 
@@ -562,6 +564,9 @@ rm -rf %{buildroot}
 %doc licensedir/*
 
 %changelog
+* Thu Oct 13 2011 Michael Young <m.a.young at durham.ac.uk> - 4.1.1-7
+- make pygrub work better with GPT partitions and grub2 on guest
+
 * Thu Sep 29 2011 Michael Young <m.a.young at durham.ac.uk> - 4.1.1-5 4.1.1-6
 - improve systemd functionality
 


More information about the scm-commits mailing list