All of lore.kernel.org
 help / color / mirror / Atom feed
* Backport pygrub grub2 support to 3.4-testing
@ 2010-03-02  9:25 Ian Campbell
  2010-03-02 13:54 ` Boris Derzhavets
  2010-03-02 14:12 ` Boris Derzhavets
  0 siblings, 2 replies; 10+ messages in thread
From: Ian Campbell @ 2010-03-02  9:25 UTC (permalink / raw)
  To: xen-devel

  20485:086a6a0c3f37 pygrub: factor generic Grub functionality into GrubConf base classes
  20486:6e32b7a3e802 pygrub: track the title of an item as an independant field
  20487:c8caa281a75a pygrub: add basic support for parsing grub2 style grub.cfg file
  20585:2636e5619708 pygrub: improve grub 2 support

Can we pull these into xen-3.4-testing.hg? They make it possible to
install Debian Squeeze (which defaults to Grub 2) and boot it using
pygrub.

Ian.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02  9:25 Backport pygrub grub2 support to 3.4-testing Ian Campbell
@ 2010-03-02 13:54 ` Boris Derzhavets
  2010-03-02 14:00   ` Ian Campbell
  2010-03-02 14:12 ` Boris Derzhavets
  1 sibling, 1 reply; 10+ messages in thread
From: Boris Derzhavets @ 2010-03-02 13:54 UTC (permalink / raw)
  To: xen-devel, Ian Campbell


[-- Attachment #1.1: Type: text/plain, Size: 1083 bytes --]

> 20585:2636e5619708 pygrub: improve grub 2 support

I believe number is wrong :-
4 weeks ago:
  pygrub: improve grub 2 support
 
 
  changeset 20858:
  2636e5619708
Boris.

--- On Tue, 3/2/10, Ian Campbell <Ian.Campbell@citrix.com> wrote:

From: Ian Campbell <Ian.Campbell@citrix.com>
Subject: [Xen-devel] Backport pygrub grub2 support to 3.4-testing
To: "xen-devel" <xen-devel@lists.xensource.com>
Date: Tuesday, March 2, 2010, 4:25 AM

  20485:086a6a0c3f37 pygrub: factor generic Grub functionality into GrubConf base classes
  20486:6e32b7a3e802 pygrub: track the title of an item as an independant field
  20487:c8caa281a75a pygrub: add basic support for parsing grub2 style grub.cfg file
  20585:2636e5619708 pygrub: improve grub 2 support

Can we pull these into xen-3.4-testing.hg? They make it possible to
install Debian Squeeze (which defaults to Grub 2) and boot it using
pygrub.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel



      

[-- Attachment #1.2: Type: text/html, Size: 1871 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 13:54 ` Boris Derzhavets
@ 2010-03-02 14:00   ` Ian Campbell
  0 siblings, 0 replies; 10+ messages in thread
From: Ian Campbell @ 2010-03-02 14:00 UTC (permalink / raw)
  To: Boris Derzhavets; +Cc: xen-devel

On Tue, 2010-03-02 at 13:54 +0000, Boris Derzhavets wrote:
> > 20585:2636e5619708 pygrub: improve grub 2 support
> 
> I believe number is wrong :-
>            4 weeks ago:
>   pygrub: improve grub 2 support
>          changeset 20858:
> 2636e5619708
> 

The second number is the important one, the other is potentially only
locally relevant.

Ian.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02  9:25 Backport pygrub grub2 support to 3.4-testing Ian Campbell
  2010-03-02 13:54 ` Boris Derzhavets
@ 2010-03-02 14:12 ` Boris Derzhavets
  2010-03-02 14:22   ` Ian Campbell
  1 sibling, 1 reply; 10+ messages in thread
From: Boris Derzhavets @ 2010-03-02 14:12 UTC (permalink / raw)
  To: xen-devel, Ian Campbell


[-- Attachment #1.1: Type: text/plain, Size: 1091 bytes --]

Just backport "20485:086a6a0c3f37 pygrub: factor generic Grub functionality into GrubConf base classes"  fails . Some CS(s) with minor numbers seem to be required for consistency.

Boris.

--- On Tue, 3/2/10, Ian Campbell <Ian.Campbell@citrix.com> wrote:

From: Ian Campbell <Ian.Campbell@citrix.com>
Subject: [Xen-devel] Backport pygrub grub2 support to 3.4-testing
To: "xen-devel" <xen-devel@lists.xensource.com>
Date: Tuesday, March 2, 2010, 4:25 AM

  20485:086a6a0c3f37 pygrub: factor generic Grub functionality into GrubConf base classes
  20486:6e32b7a3e802 pygrub: track the title of an item as an independant field
  20487:c8caa281a75a pygrub: add basic support for parsing grub2 style grub.cfg file
  20585:2636e5619708 pygrub: improve grub 2 support

Can we pull these into xen-3.4-testing.hg? They make it possible to
install Debian Squeeze (which defaults to Grub 2) and boot it using
pygrub.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel



      

[-- Attachment #1.2: Type: text/html, Size: 1914 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 14:12 ` Boris Derzhavets
@ 2010-03-02 14:22   ` Ian Campbell
  2010-03-02 14:40     ` Keir Fraser
  0 siblings, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2010-03-02 14:22 UTC (permalink / raw)
  To: Boris Derzhavets; +Cc: xen-devel

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

On Tue, 2010-03-02 at 14:12 +0000, Boris Derzhavets wrote:
> Just backport "20485:086a6a0c3f37 pygrub: factor generic Grub
> functionality into GrubConf base classes"  fails . Some CS(s) with
> minor numbers seem to be required for consistency.

I've attached backported versions of the relevant commits.

Ian.

[-- Attachment #2: xen-unstable.hg-20485.086a6a0c3f37 --]
[-- Type: text/plain, Size: 8644 bytes --]

# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1258963549 0
# Node ID 086a6a0c3f377829408e77c4cc8ca7ead919bef0
# Parent  2864f194279092b827e4dd1eeea949a48010b142
pygrub: factor generic Grub functionality into GrubConf base classes
and inherit from these classes to implement Grub-legacy functionality.

Use a tuple of (parser-object,configuration-file) in pygrub to allow
for multiple parsers.

Makes way for grub2 support.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

Index: xen-3/tools/pygrub/src/GrubConf.py
===================================================================
--- xen-3.orig/tools/pygrub/src/GrubConf.py	2009-11-29 22:41:56.000000000 +0000
+++ xen-3/tools/pygrub/src/GrubConf.py	2009-11-29 22:42:45.000000000 +0000
@@ -78,7 +78,7 @@
         self._part = int(val)
     part = property(get_part, set_part)
 
-class GrubImage(object):
+class _GrubImage(object):
     def __init__(self, lines):
         self.reset(lines)
 
@@ -89,30 +89,14 @@
                 "  args: %s\n"
                 "  initrd: %s\n" %(self.title, self.root, self.kernel,
                                    self.args, self.initrd))
+    def _parse(self, lines):
+        map(self.set_from_line, lines)
 
     def reset(self, lines):
         self._root = self._initrd = self._kernel = self._args = None
         self.title = ""
         self.lines = []
-        map(self.set_from_line, lines)
-
-    def set_from_line(self, line, replace = None):
-        (com, arg) = grub_exact_split(line, 2)
-
-        if self.commands.has_key(com):
-            if self.commands[com] is not None:
-                setattr(self, self.commands[com], arg.strip())
-            else:
-                logging.info("Ignored image directive %s" %(com,))
-        else:
-            logging.warning("Unknown image directive %s" %(com,))
-
-        # now put the line in the list of lines
-        if replace is None:
-            self.lines.append(line)
-        else:
-            self.lines.pop(replace)
-            self.lines.insert(replace, line)
+        self._parse(lines)
 
     def set_root(self, val):
         self._root = GrubDiskPart(val)
@@ -141,6 +125,28 @@
         return self._initrd
     initrd = property(get_initrd, set_initrd)
 
+class GrubImage(_GrubImage):
+    def __init__(self, lines):
+        _GrubImage.__init__(self, lines)
+    
+    def set_from_line(self, line, replace = None):
+        (com, arg) = grub_exact_split(line, 2)
+
+        if self.commands.has_key(com):
+            if self.commands[com] is not None:
+                setattr(self, self.commands[com], arg.strip())
+            else:
+                logging.info("Ignored image directive %s" %(com,))
+        else:
+            logging.warning("Unknown image directive %s" %(com,))
+
+        # now put the line in the list of lines
+        if replace is None:
+            self.lines.append(line)
+        else:
+            self.lines.pop(replace)
+            self.lines.insert(replace, line)
+
     # set up command handlers
     commands = { "title": "title",
                  "root": "root",
@@ -149,9 +155,8 @@
                  "initrd": "initrd",
                  "chainloader": None,
                  "module": None}
-        
 
-class GrubConfigFile(object):
+class _GrubConfigFile(object):
     def __init__(self, fn = None):
         self.filename = fn
         self.images = []
@@ -162,47 +167,7 @@
             self.parse()
 
     def parse(self, buf = None):
-        if buf is None:
-            if self.filename is None:
-                raise ValueError, "No config file defined to parse!"
-
-            f = open(self.filename, 'r')
-            lines = f.readlines()
-            f.close()
-        else:
-            lines = buf.split("\n")
-
-        img = []
-        for l in lines:
-            l = l.strip()
-            # skip blank lines
-            if len(l) == 0:
-                continue
-            # skip comments
-            if l.startswith('#'):
-                continue
-            # new image
-            if l.startswith("title"):
-                if len(img) > 0:
-                    self.add_image(GrubImage(img))
-                img = [l]
-                continue
-                
-            if len(img) > 0:
-                img.append(l)
-                continue
-
-            (com, arg) = grub_exact_split(l, 2)
-            if self.commands.has_key(com):
-                if self.commands[com] is not None:
-                    setattr(self, self.commands[com], arg.strip())
-                else:
-                    logging.info("Ignored directive %s" %(com,))
-            else:
-                logging.warning("Unknown directive %s" %(com,))
-                
-        if len(img) > 0:
-            self.add_image(GrubImage(img))
+        raise RuntimeError, "unimplemented parse function"   
 
     def set(self, line):
         (com, arg) = grub_exact_split(line, 2)
@@ -248,6 +213,52 @@
         commands[c] = None
     del c
 
+class GrubConfigFile(_GrubConfigFile):
+    def __init__(self, fn = None):
+        _GrubConfigFile.__init__(self,fn)
+        
+    def parse(self, buf = None):
+        if buf is None:
+            if self.filename is None:
+                raise ValueError, "No config file defined to parse!"
+
+            f = open(self.filename, 'r')
+            lines = f.readlines()
+            f.close()
+        else:
+            lines = buf.split("\n")
+
+        img = []
+        for l in lines:
+            l = l.strip()
+            # skip blank lines
+            if len(l) == 0:
+                continue
+            # skip comments
+            if l.startswith('#'):
+                continue
+            # new image
+            if l.startswith("title"):
+                if len(img) > 0:
+                    self.add_image(GrubImage(img))
+                img = [l]
+                continue
+                
+            if len(img) > 0:
+                img.append(l)
+                continue
+
+            (com, arg) = grub_exact_split(l, 2)
+            if self.commands.has_key(com):
+                if self.commands[com] is not None:
+                    setattr(self, self.commands[com], arg.strip())
+                else:
+                    logging.info("Ignored directive %s" %(com,))
+            else:
+                logging.warning("Unknown directive %s" %(com,))
+                
+        if len(img) > 0:
+            self.add_image(GrubImage(img))
 
 if __name__ == "__main__":
     if sys.argv < 2:
Index: xen-3/tools/pygrub/src/pygrub
===================================================================
--- xen-3.orig/tools/pygrub/src/pygrub	2009-11-29 22:41:57.000000000 +0000
+++ xen-3/tools/pygrub/src/pygrub	2009-11-29 22:42:19.000000000 +0000
@@ -373,17 +373,17 @@
             raise RuntimeError, "Unable to access %s" %(fn,)
 
         if platform.machine() == 'ia64':
-            self.cf = grub.LiloConf.LiloConfigFile()
-            # common distributions
-            file_list = ("/efi/debian/elilo.conf", "/efi/gentoo/elilo.conf", 
-                         "/efi/redflag/elilo.conf", "/efi/redhat/elilo.conf", 
-                         "/efi/SuSE/elilo.conf",)
-            # fallbacks
-            file_list += ("/efi/boot/elilo.conf", "/elilo.conf",)
+            cfg_list = map(lambda x: (x,grub.LiloConf.LiloConfigFile), 
+                           # common distributions
+                           ["/efi/debian/elilo.conf", "/efi/gentoo/elilo.conf", 
+                            "/efi/redflag/elilo.conf", "/efi/redhat/elilo.conf", 
+                            "/efi/SuSE/elilo.conf",] + 
+                           # fallbacks
+                           ["/efi/boot/elilo.conf", "/elilo.conf",])
         else:
-            self.cf = grub.GrubConf.GrubConfigFile()
-            file_list = ("/boot/grub/menu.lst", "/boot/grub/grub.conf",
-                         "/grub/menu.lst", "/grub/grub.conf")
+            cfg_list = map(lambda x: (x,grub.GrubConf.GrubConfigFile),
+                           ["/boot/grub/menu.lst", "/boot/grub/grub.conf",
+                            "/grub/menu.lst", "/grub/grub.conf"])
 
         if not fs:
             # set the config file and parse it
@@ -391,8 +391,10 @@
             self.cf.parse()
             return
 
-        for f in file_list:
+        for f,parser in cfg_list:
             if fs.file_exists(f):
+                print >>sys.stderr, "Using %s to parse %s" % (parser,f)
+                self.cf = parser()
                 self.cf.filename = f
                 break
         if self.cf.filename is None:

[-- Attachment #3: xen-unstable.hg-20486.6e32b7a3e802 --]
[-- Type: text/plain, Size: 4385 bytes --]

# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1258963579 0
# Node ID 6e32b7a3e80202ed6c4d09a1211e14c786cb3731
# Parent  086a6a0c3f377829408e77c4cc8ca7ead919bef0
pygrub: track the title of an item as an independant field
separate to the other fields.

This makes the list of lines within a GrubImage 0 based rather than 1
based therefore adjust the user interface parts to suit.

This is in preparation for grub2 support where the syntax for the item
title does not fit the existing usage.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 1faf3349d914 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py	Mon Nov 23 08:05:49 2009 +0000
+++ b/tools/pygrub/src/GrubConf.py	Tue Jan 12 12:01:26 2010 +0000
@@ -79,8 +79,9 @@
     part = property(get_part, set_part)
 
 class _GrubImage(object):
-    def __init__(self, lines):
+    def __init__(self, title, lines):
         self.reset(lines)
+        self.title = title.strip()
 
     def __repr__(self):
         return ("title: %s\n" 
@@ -94,7 +95,6 @@
 
     def reset(self, lines):
         self._root = self._initrd = self._kernel = self._args = None
-        self.title = ""
         self.lines = []
         self._parse(lines)
 
@@ -126,8 +126,8 @@
     initrd = property(get_initrd, set_initrd)
 
 class GrubImage(_GrubImage):
-    def __init__(self, lines):
-        _GrubImage.__init__(self, lines)
+    def __init__(self, title, lines):
+        _GrubImage.__init__(self, title, lines)
     
     def set_from_line(self, line, replace = None):
         (com, arg) = grub_exact_split(line, 2)
@@ -148,8 +148,7 @@
             self.lines.insert(replace, line)
 
     # set up command handlers
-    commands = { "title": "title",
-                 "root": "root",
+    commands = { "root": "root",
                  "rootnoverify": "root",
                  "kernel": "kernel",
                  "initrd": "initrd",
@@ -228,7 +227,8 @@
         else:
             lines = buf.split("\n")
 
-        img = []
+        img = None
+        title = ""
         for l in lines:
             l = l.strip()
             # skip blank lines
@@ -239,12 +239,13 @@
                 continue
             # new image
             if l.startswith("title"):
-                if len(img) > 0:
-                    self.add_image(GrubImage(img))
-                img = [l]
+                if img is not None:
+                    self.add_image(GrubImage(title, img))
+                img = []
+                title = l[6:]
                 continue
                 
-            if len(img) > 0:
+            if img is not None:
                 img.append(l)
                 continue
 
@@ -257,8 +258,8 @@
             else:
                 logging.warning("Unknown directive %s" %(com,))
                 
-        if len(img) > 0:
-            self.add_image(GrubImage(img))
+        if img:
+            self.add_image(GrubImage(title, img))
 
 if __name__ == "__main__":
     if sys.argv < 2:
diff -r 1faf3349d914 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub	Mon Nov 23 08:05:49 2009 +0000
+++ b/tools/pygrub/src/pygrub	Tue Jan 12 12:01:26 2010 +0000
@@ -259,13 +259,13 @@
             self.text_win.move(y - 1, x - 1)
             self.text_win.noutrefresh()
 
-        curline = 1
+        curline = 0
         img = copy.deepcopy(origimg)
         while 1:
             draw()
             self.entry_win.erase()
             self.entry_win.box()
-            for idx in range(1, len(img.lines)):
+            for idx in range(0, len(img.lines)):
                 # current line should be highlighted
                 if idx == curline:
                     self.entry_win.attron(curses.A_REVERSE)
@@ -275,7 +275,7 @@
                 if len(l) > 70:
                     l = l[:69] + ">"
                     
-                self.entry_win.addstr(idx, 2, l)
+                self.entry_win.addstr(idx + 1, 2, l)
                 if idx == curline:
                     self.entry_win.attroff(curses.A_REVERSE)
             self.entry_win.noutrefresh()
@@ -308,8 +308,8 @@
                     return
                 
             # bound at the top and bottom
-            if curline < 1:
-                curline = 1
+            if curline < 0:
+                curline = 0
             elif curline >= len(img.lines):
                 curline = len(img.lines) - 1
 

[-- Attachment #4: xen-unstable.hg-20487.c8caa281a75a --]
[-- Type: text/plain, Size: 6011 bytes --]

# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1258963614 0
# Node ID c8caa281a75ab3ff4a246d357ad83e4959b8489e
# Parent  6e32b7a3e80202ed6c4d09a1211e14c786cb3731
pygrub: add basic support for parsing grub2 style grub.cfg file

This represents a very simplistic aproach to parsing these file.  It
is basically sufficient to parse the files produced by Debian
Squeeze's version of update-grub. The actual grub.cfg syntax is much
more expresive but not apparently documented apart from a few
examples...

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

Index: xen-3/tools/pygrub/src/GrubConf.py
===================================================================
--- xen-3.orig/tools/pygrub/src/GrubConf.py	2009-11-29 22:42:55.000000000 +0000
+++ xen-3/tools/pygrub/src/GrubConf.py	2009-11-29 22:43:21.000000000 +0000
@@ -14,6 +14,7 @@
 
 import os, sys
 import logging
+import re
 
 def grub_split(s, maxsplit = -1):
     eq = s.find('=')
@@ -261,9 +262,122 @@
         if img:
             self.add_image(GrubImage(title, img))
 
+class Grub2Image(_GrubImage):
+    def __init__(self, title, lines):
+        _GrubImage.__init__(self, title, lines)
+
+    def set_from_line(self, line, replace = None):
+        (com, arg) = grub_exact_split(line, 2)
+
+        if com == "set":
+            (com,arg) = grub_split(arg,2)
+            com="set:" + com
+                
+        if self.commands.has_key(com):
+            if self.commands[com] is not None:
+                setattr(self, self.commands[com], arg.strip())
+            else:
+                logging.info("Ignored image directive %s" %(com,))
+        else:
+            logging.warning("Unknown image directive %s" %(com,))
+
+        # now put the line in the list of lines
+        if replace is None:
+            self.lines.append(line)
+        else:
+            self.lines.pop(replace)
+            self.lines.insert(replace, line)
+                
+    commands = {'set:root': 'root',
+                'linux': 'kernel',
+                'initrd': 'initrd',
+                'insmod': None,
+                'search': None}
+    
+class Grub2ConfigFile(_GrubConfigFile):
+    def __init__(self, fn = None):
+        _GrubConfigFile.__init__(self, fn)
+        
+    def parse(self, buf = None):
+        if buf is None:
+            if self.filename is None:
+                raise ValueError, "No config file defined to parse!"
+
+            f = open(self.filename, 'r')
+            lines = f.readlines()
+            f.close()
+        else:
+            lines = buf.split("\n")
+
+        img = None
+        title = ""
+        for l in lines:
+            l = l.strip()
+            # skip blank lines
+            if len(l) == 0:
+                continue
+            # skip comments
+            if l.startswith('#'):
+                continue
+            # new image
+            title_match = re.match('^menuentry "(.*)" {', l)
+            if title_match:
+                if img is not None:
+                    raise RuntimeError, "syntax error 1 %d %s" % (len(img),img)
+                img = []
+                title = title_match.group(1)
+                continue
+            
+            if l.startswith("}"):
+                if img is None:
+                    raise RuntimeError, "syntax error 2 %d %s" % (len(img),img)
+
+                self.add_image(Grub2Image(title, img))
+                img = None
+                continue
+
+            if img is not None:
+                img.append(l)
+                continue
+
+            (com, arg) = grub_exact_split(l, 2)
+        
+            if com == "set":
+                (com,arg) = grub_split(arg,2)
+                com="set:" + com
+                
+            if self.commands.has_key(com):
+                if self.commands[com] is not None:
+                    setattr(self, self.commands[com], arg.strip())
+                else:
+                    logging.info("Ignored directive %s" %(com,))
+            else:
+                logging.warning("Unknown directive %s" %(com,))
+            
+        if img is not None:
+            raise RuntimeError, "syntax error 3 %d %s" % (len(img),img)
+
+    commands = {'set:default': 'default',
+                'set:root': 'root',
+                'set:timeout': 'timeout',
+                'set:gfxmode': None,
+                'set:menu_color_normal': None,
+                'set:menu_color_highlight': None,
+                'terminal': None,
+                'insmod': None,
+                'search': None,
+                'if': None,
+                'fi': None,
+                }
+        
 if __name__ == "__main__":
-    if sys.argv < 2:
-        raise RuntimeError, "Need a grub.conf to read"
-    g = GrubConfigFile(sys.argv[1])
+    if sys.argv < 3:
+        raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read"
+    if sys.argv[1] == "grub":
+        g = GrubConfigFile(sys.argv[2])
+    elif sys.argv[1] == "grub2":
+        g = Grub2ConfigFile(sys.argv[2])
+    else:
+        raise RuntimeError, "Unknown config type %s" % sys.argv[1]
     for i in g.images:
         print i #, i.title, i.root, i.kernel, i.args, i.initrd
Index: xen-3/tools/pygrub/src/pygrub
===================================================================
--- xen-3.orig/tools/pygrub/src/pygrub	2009-11-29 22:42:55.000000000 +0000
+++ xen-3/tools/pygrub/src/pygrub	2009-11-29 22:43:02.000000000 +0000
@@ -383,7 +383,9 @@
         else:
             cfg_list = map(lambda x: (x,grub.GrubConf.GrubConfigFile),
                            ["/boot/grub/menu.lst", "/boot/grub/grub.conf",
-                            "/grub/menu.lst", "/grub/grub.conf"])
+                            "/grub/menu.lst", "/grub/grub.conf"]) + \
+                       map(lambda x: (x,grub.GrubConf.Grub2ConfigFile),
+                           ["/boot/grub/grub.cfg"])
 
         if not fs:
             # set the config file and parse it

[-- Attachment #5: xen-unstable.hg-20858.2636e5619708 --]
[-- Type: text/plain, Size: 3345 bytes --]

# HG changeset patch
# User Keir Fraser <keir.fraser@citrix.com>
# Date 1264521280 0
# Node ID 2636e561970898517def148c19e04581b12dc860
# Parent  66587cc5f1e1217c54a5483ce68b9ae6dbeca44a
pygrub: improve grub 2 support

* The "default" value can be a quoted string (containing an integer)
  so strip the quotes before interpreting.
* The "set" command takes a variable with an arbitrary name so instead
  of whitelisting the ones to ignore simply silently accept any set
  command with an unknown variable.
* Ignore the echo command.
* Handle the function { ... } syntax. Previously pygrub would error
  out with a syntax error on the closing "}" because it thought it was
  the closing bracket of a menuentry.

This makes pygrub2 work with the configuration files generated by
Debian Squeeze today.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 66587cc5f1e1 -r 2636e5619708 tools/pygrub/src/GrubConf.py
--- a/tools/pygrub/src/GrubConf.py	Tue Jan 26 15:54:09 2010 +0000
+++ b/tools/pygrub/src/GrubConf.py	Tue Jan 26 15:54:40 2010 +0000
@@ -219,6 +219,7 @@
     def _get_default(self):
         return self._default
     def _set_default(self, val):
+        val = val.strip("\"")
         if val == "saved":
             self._default = 0
         else:
@@ -315,6 +316,8 @@
                 setattr(self, self.commands[com], arg.strip())
             else:
                 logging.info("Ignored image directive %s" %(com,))
+        elif com.startswith('set:'):
+            pass
         else:
             logging.warning("Unknown image directive %s" %(com,))
 
@@ -328,6 +331,7 @@
     commands = {'set:root': 'root',
                 'linux': 'kernel',
                 'initrd': 'initrd',
+                'echo': None,
                 'insmod': None,
                 'search': None}
     
@@ -346,6 +350,7 @@
         else:
             lines = buf.split("\n")
 
+        in_function = False
         img = None
         title = ""
         for l in lines:
@@ -356,6 +361,16 @@
             # skip comments
             if l.startswith('#'):
                 continue
+
+            # skip function declarations
+            if l.startswith('function'):
+                in_function = True
+                continue
+            if in_function:
+                if l.startswith('}'):
+                    in_function = False
+                continue
+
             # new image
             title_match = re.match('^menuentry "(.*)" {', l)
             if title_match:
@@ -388,6 +403,8 @@
                     setattr(self, self.commands[com], arg.strip())
                 else:
                     logging.info("Ignored directive %s" %(com,))
+            elif com.startswith('set:'):
+                pass
             else:
                 logging.warning("Unknown directive %s" %(com,))
             
@@ -400,11 +417,10 @@
     commands = {'set:default': 'default',
                 'set:root': 'root',
                 'set:timeout': 'timeout',
-                'set:gfxmode': None,
-                'set:menu_color_normal': None,
-                'set:menu_color_highlight': None,
                 'terminal': None,
                 'insmod': None,
+                'load_env': None,
+                'save_env': None,
                 'search': None,
                 'if': None,
                 'fi': None,

[-- Attachment #6: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 14:22   ` Ian Campbell
@ 2010-03-02 14:40     ` Keir Fraser
  2010-03-02 14:41       ` Ian Campbell
  0 siblings, 1 reply; 10+ messages in thread
From: Keir Fraser @ 2010-03-02 14:40 UTC (permalink / raw)
  To: Ian Campbell, Boris Derzhavets; +Cc: xen-devel

On 02/03/2010 14:22, "Ian Campbell" <Ian.Campbell@citrix.com> wrote:

> On Tue, 2010-03-02 at 14:12 +0000, Boris Derzhavets wrote:
>> Just backport "20485:086a6a0c3f37 pygrub: factor generic Grub
>> functionality into GrubConf base classes"  fails . Some CS(s) with
>> minor numbers seem to be required for consistency.
> 
> I've attached backported versions of the relevant commits.

I already backported and applied. All but the first applied cleanly.

 -- Keir

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 14:40     ` Keir Fraser
@ 2010-03-02 14:41       ` Ian Campbell
  2010-03-02 18:35         ` Boris Derzhavets
  0 siblings, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2010-03-02 14:41 UTC (permalink / raw)
  To: Keir Fraser; +Cc: Boris Derzhavets, xen-devel

On Tue, 2010-03-02 at 14:40 +0000, Keir Fraser wrote:
> On 02/03/2010 14:22, "Ian Campbell" <Ian.Campbell@citrix.com> wrote:
> 
> > On Tue, 2010-03-02 at 14:12 +0000, Boris Derzhavets wrote:
> >> Just backport "20485:086a6a0c3f37 pygrub: factor generic Grub
> >> functionality into GrubConf base classes"  fails . Some CS(s) with
> >> minor numbers seem to be required for consistency.
> > 
> > I've attached backported versions of the relevant commits.
> 
> I already backported and applied. All but the first applied cleanly.

Smashing, cheers!

Ian.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 14:41       ` Ian Campbell
@ 2010-03-02 18:35         ` Boris Derzhavets
  2010-03-02 19:24           ` Keir Fraser
  0 siblings, 1 reply; 10+ messages in thread
From: Boris Derzhavets @ 2010-03-02 18:35 UTC (permalink / raw)
  To: Keir Fraser, Ian Campbell; +Cc: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 3367 bytes --]

   Under Xen 4.0-rc4 (rc5) i can create  Ubuntu Karmic Server HVM DomU with image, say  on /dev/sdb5, and immediately load Karmic PV DomU via
/usr/local/bin/pygrub on /dev/sdb5 (/dev/xvda1 mounted on "/", /dev/xvda2 - swap).
  Fresh clone Xen 3.4.3 doesn't allow me to reproduce this procedure.
Bootloader returns no data, and i still have to copy kernel and ramdisk
to Dom0 add /etc/init/hvc0 at DomU (edited as usual)  and then load Karmic Server PV DomU via profile :-

name="KarmicPV"
memory=2048
kernel="./vmlinuz-2.6.31-14-server"
ramdisk="./initrd.img-2.6.31-14-server"
disk=['phy:/dev/sdb5,xvda,w']
extra="root=/dev/xvda1 ro console=hvc0"
vif= [ 'bridge=eth0']

Profile :

name="KarmicPV"
memory=2048
bootloader="/usr/local/bin/pygrub"
disk=['phy:/dev/sdb5,xvda,w']
vif= ['bridge=eth0']
vfb= ['vnc=1,vncunused=1']

doesn't work ( pygrub returns no data).

Xen has been built via directory :-

root@ServerKoala:/usr/src# cd xen-3.4-testing.hg
root@ServerKoala:/usr/src/xen-3.4-testing.hg# hg log |more
changeset:   19912:faf6902fde2e
tag:         tip
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Tue Mar 02 13:56:58 2010 +0000
summary:     Update Xen version to 3.4.3-rc4-pre

changeset:   19911:d016a6777167
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Tue Mar 02 13:56:25 2010 +0000
summary:     pygrub: factor generic Grub functionality into GrubConf base classes

changeset:   19910:2b0908b101de
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Tue Mar 02 13:49:21 2010 +0000
summary:     x86/acpi: Add a missing CR in printk

changeset:   19909:cfd7f75ea9bc
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Mon Mar 01 16:51:31 2010 +0000
summary:     Added tag 3.4.3-rc3 for changeset 8e843b06f917

changeset:   19908:8e843b06f917
tag:         3.4.3-rc3
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Mon Mar 01 16:51:19 2010 +0000
summary:     Update Xen version to 3.4.3-rc3

changeset:   19907:1cdf837cd5ef
user:        Keir Fraser <keir.fraser@citrix.com>
date:        Mon Mar 01 12:01:10 2010 +0000
summary:     New release of C/S 19894 "Disable memory mapping warnings when stub

. . . . . . . . .


Boris.

--- On Tue, 3/2/10, Ian Campbell <Ian.Campbell@citrix.com> wrote:

From: Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [Xen-devel] Backport pygrub grub2 support to 3.4-testing
To: "Keir Fraser" <Keir.Fraser@eu.citrix.com>
Cc: "Boris Derzhavets" <bderzhavets@yahoo.com>, "xen-devel" <xen-devel@lists.xensource.com>
Date: Tuesday, March 2, 2010, 9:41 AM

On Tue, 2010-03-02 at 14:40 +0000, Keir Fraser wrote:
> On 02/03/2010 14:22, "Ian Campbell" <Ian.Campbell@citrix.com> wrote:
> 
> > On Tue, 2010-03-02 at 14:12 +0000, Boris Derzhavets wrote:
> >> Just backport "20485:086a6a0c3f37 pygrub: factor generic Grub
> >> functionality into GrubConf base classes"  fails . Some CS(s) with
> >> minor numbers seem to be required for consistency.
> > 
> > I've attached backported versions of the relevant commits.
> 
> I already backported and applied. All but the first applied cleanly.

Smashing, cheers!

Ian.



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel



      

[-- Attachment #1.2: Type: text/html, Size: 4949 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 18:35         ` Boris Derzhavets
@ 2010-03-02 19:24           ` Keir Fraser
  2010-03-02 22:12             ` Boris Derzhavets
  0 siblings, 1 reply; 10+ messages in thread
From: Keir Fraser @ 2010-03-02 19:24 UTC (permalink / raw)
  To: Boris Derzhavets, Ian Campbell; +Cc: xen-devel

On 02/03/2010 18:35, "Boris Derzhavets" <bderzhavets@yahoo.com> wrote:

>    Under Xen 4.0-rc4 (rc5) i can create  Ubuntu Karmic Server HVM DomU with
> image, say  on /dev/sdb5, and immediately load Karmic PV DomU via
> /usr/local/bin/pygrub on /dev/sdb5 (/dev/xvda1 mounted on "/", /dev/xvda2 -
> swap).
>   Fresh clone Xen 3.4.3 doesn't allow me to reproduce this procedure.
> Bootloader returns no data, and i still have to copy kernel and ramdisk
> to Dom0 add /etc/init/hvc0 at DomU (edited as usual)  and then load Karmic
> Server PV DomU via profile :-

Looks like my backport of the patches was broken. Comparing with Ian's, I've
checked in a fix-up patch as changeset 19913. So try refreshing your 3.4
tree and rebuilding.

 -- Keir

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Backport pygrub grub2 support to 3.4-testing
  2010-03-02 19:24           ` Keir Fraser
@ 2010-03-02 22:12             ` Boris Derzhavets
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Derzhavets @ 2010-03-02 22:12 UTC (permalink / raw)
  To: Ian Campbell, Keir Fraser; +Cc: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 1359 bytes --]

Yes, now fresh clone Xen 3.4.3 supports GRUB 2.

Thanks.
Boris.

--- On Tue, 3/2/10, Keir Fraser <keir.fraser@eu.citrix.com> wrote:

From: Keir Fraser <keir.fraser@eu.citrix.com>
Subject: Re: [Xen-devel] Backport pygrub grub2 support to 3.4-testing
To: "Boris Derzhavets" <bderzhavets@yahoo.com>, "Ian Campbell" <Ian.Campbell@eu.citrix.com>
Cc: "xen-devel" <xen-devel@lists.xensource.com>
Date: Tuesday, March 2, 2010, 2:24 PM

On 02/03/2010 18:35, "Boris Derzhavets" <bderzhavets@yahoo.com> wrote:

>    Under Xen 4.0-rc4 (rc5) i can create  Ubuntu Karmic Server HVM DomU with
> image, say  on /dev/sdb5, and immediately load Karmic PV DomU via
> /usr/local/bin/pygrub on /dev/sdb5 (/dev/xvda1 mounted on "/", /dev/xvda2 -
> swap).
>   Fresh clone Xen 3.4.3 doesn't allow me to reproduce this procedure.
> Bootloader returns no data, and i still have to copy kernel and ramdisk
> to Dom0 add /etc/init/hvc0 at DomU (edited as usual)  and then load Karmic
> Server PV DomU via profile :-

Looks like my backport of the patches was broken. Comparing with Ian's, I've
checked in a fix-up patch as changeset 19913. So try refreshing your 3.4
tree and rebuilding.

 -- Keir



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel



      

[-- Attachment #1.2: Type: text/html, Size: 2071 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-02 22:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-02  9:25 Backport pygrub grub2 support to 3.4-testing Ian Campbell
2010-03-02 13:54 ` Boris Derzhavets
2010-03-02 14:00   ` Ian Campbell
2010-03-02 14:12 ` Boris Derzhavets
2010-03-02 14:22   ` Ian Campbell
2010-03-02 14:40     ` Keir Fraser
2010-03-02 14:41       ` Ian Campbell
2010-03-02 18:35         ` Boris Derzhavets
2010-03-02 19:24           ` Keir Fraser
2010-03-02 22:12             ` Boris Derzhavets

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.