From: Boris Derzhavets Subject: Re: pygrub: further improve grub2 support Date: Fri, 26 Mar 2010 03:41:10 -0700 (PDT) Message-ID: <735644.50499.qm@web56104.mail.re3.yahoo.com> References: <1268643382.8652.2811.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0492813266==" Return-path: In-Reply-To: <1268643382.8652.2811.camel@localhost.localdomain> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com, Ian Campbell List-Id: xen-devel@lists.xenproject.org --===============0492813266== Content-Type: multipart/alternative; boundary="0-890197913-1269600070=:50499" --0-890197913-1269600070=:50499 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable In Ubuntu 10.04 beta grub entry root looks like : =A0 set root=3D'(/dev/sda,1)'=A0 vs=A0 set=A0 root=3D(hd0,1) in 9.10 Standard trick with loading PV DomU via HVM image fails. Looks like "pygrub" cannot parse new root's notation Boris. P.S. Attempt just to replace with old one doesn't help in my case. --- On Mon, 3/15/10, Ian Campbell wrote: From: Ian Campbell Subject: [Xen-devel] pygrub: further improve grub2 support To: xen-devel@lists.xensource.com Date: Monday, March 15, 2010, 4:56 AM Round 2 (3?) in the arms race against the Debian Squeeze grub packages. =A0 =A0 =A0 * Improve syntax error messages to say what actually went wrong =A0 =A0 =A0 =A0 instead of giving an arbitrary and basically useless intege= r.=20 =A0 =A0 =A0 * Improve handling of quoted values used with the "set" command= , =A0 =A0 =A0 =A0 previously only the default variable was special cased to h= andle =A0 =A0 =A0 =A0 quoting.=20 =A0 =A0 =A0 * Allow for extra options to the menuentry command, syntax now =A0 =A0 =A0 =A0 appears to be =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 menuentry "TITLE" --option1= --option2 {...} Signed-off-by: Ian Campbell Please include in 3.4 as well. diff -r 4152a3ce90a7 tools/pygrub/src/GrubConf.py --- a/tools/pygrub/src/GrubConf.py=A0=A0=A0 Thu Mar 11 17:40:35 2010 +0000 +++ b/tools/pygrub/src/GrubConf.py=A0=A0=A0 Mon Mar 15 08:51:07 2010 +0000 @@ -220,7 +220,6 @@ =A0 =A0=A0=A0def _get_default(self): =A0 =A0 =A0 =A0=A0=A0return self._default =A0 =A0=A0=A0def _set_default(self, val): -=A0 =A0 =A0 =A0 val =3D val.strip("\"") =A0 =A0 =A0 =A0=A0=A0if val =3D=3D "saved": =A0 =A0 =A0 =A0 =A0 =A0=A0=A0self._default =3D 0 =A0 =A0 =A0 =A0=A0=A0else: @@ -300,7 +299,15 @@ =20 =A0 =A0 =A0 =A0=A0=A0if self.hasPassword(): =A0 =A0 =A0 =A0 =A0 =A0=A0=A0self.setPasswordAccess(False) -=A0 =A0=20 + +def grub2_handle_set(arg): +=A0 =A0 (com,arg) =3D grub_split(arg,2) +=A0 =A0 com=3D"set:" + com +=A0 =A0 m =3D re.match("([\"\'])(.*)\\1", arg) +=A0 =A0 if m is not None: +=A0 =A0 =A0 =A0 arg=3Dm.group(2)=20 +=A0 =A0 return (com,arg) + class Grub2Image(_GrubImage): =A0 =A0=A0=A0def __init__(self, title, lines): =A0 =A0 =A0 =A0=A0=A0_GrubImage.__init__(self, title, lines) @@ -309,9 +316,8 @@ =A0 =A0 =A0 =A0=A0=A0(com, arg) =3D grub_exact_split(line, 2) =20 =A0 =A0 =A0 =A0=A0=A0if com =3D=3D "set": -=A0 =A0 =A0 =A0 =A0 =A0 (com,arg) =3D grub_split(arg,2) -=A0 =A0 =A0 =A0 =A0 =A0 com=3D"set:" + com -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=20 +=A0 =A0 =A0 =A0 =A0 =A0 (com,arg) =3D grub2_handle_set(arg) +=A0 =A0 =A0 =A0 =A0 =A0=20 =A0 =A0 =A0 =A0=A0=A0if self.commands.has_key(com): =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if self.commands[com] is not None: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0setattr(self, self.commands[com], arg.= strip()) @@ -373,17 +379,17 @@ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0continue =20 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0# new image -=A0 =A0 =A0 =A0 =A0 =A0 title_match =3D re.match('^menuentry "(.*)" {', l) +=A0 =A0 =A0 =A0 =A0 =A0 title_match =3D re.match('^menuentry "(.*)" (.*){'= , l) =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if title_match: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if img is not None: -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error = 1 %d %s" % (len(img),img) +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error:= cannot nest menuentry (%d %s)" % (len(img),img) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0img =3D [] =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0title =3D title_match.group(1) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0continue =A0 =A0 =A0 =A0 =A0 =A0=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if l.startswith("}"): =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if img is None: -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error = 2 %d %s" % (len(img),img) +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error:= closing brace without menuentry" =20 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0self.add_image(Grub2Image(title, img)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0img =3D None @@ -396,8 +402,7 @@ =A0 =A0 =A0 =A0 =A0 =A0=A0=A0(com, arg) =3D grub_exact_split(l, 2) =A0 =A0 =A0 =A0=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if com =3D=3D "set": -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (com,arg) =3D grub_split(arg,2) -=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 com=3D"set:" + com +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (com,arg) =3D grub2_handle_set(arg) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if self.commands.has_key(com): =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0if self.commands[com] is not None: @@ -410,7 +415,7 @@ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0logging.warning("Unknown directive %s"= %(com,)) =A0 =A0 =A0 =A0 =A0 =A0=A0=A0 =A0 =A0 =A0 =A0=A0=A0if img is not None: -=A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error 3 %d %s" % (len(= img),img) +=A0 =A0 =A0 =A0 =A0 =A0 raise RuntimeError, "syntax error: end of file wit= h open menuentry(%d %s)" % (len(img),img) =20 =A0 =A0 =A0 =A0=A0=A0if self.hasPassword(): =A0 =A0 =A0 =A0 =A0 =A0=A0=A0self.setPasswordAccess(False) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel =0A=0A=0A --0-890197913-1269600070=:50499 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
In Ubuntu 10.04 beta grub entry root looks li= ke :

  set root=3D'(/dev/sda,1)'  vs  set  root= =3D(hd0,1) in 9.10

Standard trick with loading PV DomU via HVM image= fails.
Looks like "pygrub" cannot parse new root's notation

Bori= s.
P.S.
Attempt just to replace with old one
doesn't help in my ca= se.

--- On Mon, 3/15/10, Ian Campbell <Ian.Campbell@citrix.= com> wrote:

From: Ian Campbell &= lt;Ian.Campbell@citrix.com>
Subject: [Xen-devel] pygrub: further impr= ove grub2 support
To: xen-devel@lists.xensource.com
Date: Monday, Mar= ch 15, 2010, 4:56 AM


Round 2 (3?) in th= e arms race against the Debian Squeeze grub packages.

    =   * Improve syntax error messages to say what actually went wrong
  &n= bsp;     instead of giving an arbitrary and basically useless int= eger.
      * Improve handling of quoted values used wit= h the "set" command,
        previously only the def= ault variable was special cased to handle
        qu= oting.
      * Allow for extra options to the menuentry = command, syntax now
        appears to be
  =                      = ; menuentry "TITLE" --option1 --option2 {...}

Signed-off-by: Ian Cam= pbell <ian.campbell@citrix.com>

Pleas= e include in 3.4 as well.

diff -r 4152a3ce90a7 tools/pygrub/src/Grub= Conf.py
--- a/tools/pygrub/src/GrubConf.py    Thu Mar 11 17:40:35 2010 +0000
+++ b/tools/pygrub/src/GrubConf.py   = ; Mon Mar 15 08:51:07 2010 +0000
@@ -220,7 +220,6 @@
   &nb= sp; def _get_default(self):
         = return self._default
     def _set_default(self, val= ):
-        val =3D val.strip("\"")
   =      if val =3D=3D "saved":
      &n= bsp;      self._default =3D 0
      &= nbsp;  else:
@@ -300,7 +299,15 @@

     =    if self.hasPassword():
        &n= bsp;    self.setPasswordAccess(False)
-   
= +
+def grub2_handle_set(arg):
+    (com,arg) =3D grub_split= (arg,2)
+    com=3D"set:" + com
+    m =3D re.mat= ch("([\"\'])(.*)\\1", arg)
+    if m is not None:
+  &= nbsp;     arg=3Dm.group(2)
+    return (com,arg)
+ class Grub2Image(_GrubImage):
     def __init__(se= lf, title, lines):
         _GrubImage.__i= nit__(self, title, lines)
@@ -309,9 +316,8 @@
      &n= bsp;  (com, arg) =3D grub_exact_split(line, 2)

  &nb= sp;      if com =3D=3D "set":
-      =       (com,arg) =3D grub_split(arg,2)
-    &nbs= p;       com=3D"set:" + com
-        =        
+            = (com,arg) =3D grub2_handle_set(arg)
+          =  
         if self.commands.has_key(= com):
             if self.comma= nds[com] is not None:
                 setattr(self, self.commands[com], arg.strip())
@@ -37= 3,17 +379,17 @@
               &= nbsp; continue

            =  # new image
-            title_match= =3D re.match('^menuentry "(.*)" {', l)
+        &nb= sp;   title_match =3D re.match('^menuentry "(.*)" (.*){', l)
 =            if title_match:
  &n= bsp;              if img is not Non= e:
-                   = ; raise RuntimeError, "syntax error 1 %d %s" % (len(img),img)
+  &n= bsp;                 raise RuntimeE= rror, "syntax error: cannot nest menuentry (%d %s)" % (len(img),img)
&nb= sp;                img =3D []
                 t= itle =3D title_match.group(1)
            =      continue
          &nb= sp;  
             if = l.startswith("}"):
              &nbs= p;  if img is None:
-           =         raise RuntimeError, "syntax error 2 %d %s" % (= len(img),img)
+                &= nbsp;   raise RuntimeError, "syntax error: closing brace without menue= ntry"

                =  self.add_image(Grub2Image(title, img))
       =          img =3D None
@@ -396,8 +402,7 @@=
             (com, arg) =3D grub_exact_split(l, 2)
         
 = ;            if com =3D=3D "set":
-&n= bsp;               (com,arg) =3D grub_sp= lit(arg,2)
-                com= =3D"set:" + com
+               = (com,arg) =3D grub2_handle_set(arg)
          =        
          &nbs= p;  if self.commands.has_key(com):
       =          if self.commands[com] is not None:<= br>@@ -410,7 +415,7 @@
              =    logging.warning("Unknown directive %s" %(com,))
 =            
      &nb= sp;  if img is not None:
-            raise RuntimeError, "syntax error 3 %d %s" % (len(img),img)
+&nb= sp;           raise RuntimeError, "syntax error: e= nd of file with open menuentry(%d %s)" % (len(img),img)

  &nbs= p;      if self.hasPassword():
      =        self.setPasswordAccess(False)


_______________________________________________
Xen-devel mailing list=
Xen-devel@lists.xensource.com
<= a href=3D"http://lists.xensource.com/xen-devel" target=3D"_blank">http://li= sts.xensource.com/xen-devel
=0A=0A --0-890197913-1269600070=:50499-- --===============0492813266== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0492813266==--