Skip to contentSkip to conversation

pygrub: fix extlinux parsing

PATCH In review Roger Pau Monne 3 participants 5 messages Jan 3, 2012 – Jan 10, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pygrub: fix extlinux parsing

# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325592706 -3600
# Node ID 6fcc1c479ee68f27233a55ec45a618e0f7cf5d6f # Parent 3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsing

pygrub was unable to parse extlinux config files correctly, exactly the ones like:

LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet

This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.

tools/pygrub/examples/alpine-linux-2.3.2.extlinux new file +11 -0
diff -r 3e02aa9670b3 -r 6fcc1c479ee6 tools/pygrub/examples/alpine-linux-2.3.2.extlinux
@@ -0,0 +1,11 @@
+DEFAULT menu.c32
+PROMPT 0
+MENU TITLE Alpine/Linux Boot Menu
+MENU HIDDEN
+MENU AUTOBOOT Alpine will be booted automatically in # seconds.
+TIMEOUT 30
+LABEL grsec
+  MENU DEFAULT
+  MENU LABEL Linux 3.0.10-grsec
+  KERNEL vmlinuz-3.0.10-grsec
+  APPEND initrd=initramfs-3.0.10-grsec root=UUID=a97ffe64-430f-4fd3-830e-4736d9a27af0 modules=sd-mod,usb-storage,ext4 quiet
tools/pygrub/src/ExtLinuxConf.py +10 -1
diff -r 3e02aa9670b3 -r 6fcc1c479ee6 tools/pygrub/src/ExtLinuxConf.py
@@ -60,6 +60,13 @@ class ExtLinuxImage(object):
 
                 # Bypass regular self.commands handling
                 com = None
+            elif arg.find("initrd="):
+                # find initrd image in append line
+                args = arg.strip().split(" ")
+                for a in args:
+                    if a.lower().startswith("initrd="):
+                        setattr(self, "initrd", a.replace("initrd=", ""))
+                        arg = arg.replace(a, "")
 
         if com is not None and self.commands.has_key(com):
             if self.commands[com] is not None:
@@ -86,10 +93,12 @@ class ExtLinuxImage(object):
         self._args = args
     def get_kernel(self):
         return self._kernel
+    def set_args(self, val):
+        self._args = val
     def get_args(self):
         return self._args
     kernel = property(get_kernel, set_kernel)
-    args = property(get_args)
+    args = property(get_args, set_args)
 
     def set_initrd(self, val):
         self._initrd = (None,val)
Acked-by on v2 1/1
#1 lore raw
Quoted 16 lines · Roger Pau Monne

# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325592706 -3600
# Node ID 6fcc1c479ee68f27233a55ec45a618e0f7cf5d6f # Parent 3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsing

pygrub was unable to parse extlinux config files correctly, exactly the ones like:

LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet

Quoted 4 lines

This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.

Quoted 47 lines

diff -r 3e02aa9670b3 -r 6fcc1c479ee6 tools/pygrub/examples/alpine-linux-2.3.2.extlinux

tools/pygrub/examples/alpine-linux-2.3.2.extlinux new file +11 -0
@@ -0,0 +1,11 @@
+DEFAULT menu.c32
+PROMPT 0
+MENU TITLE Alpine/Linux Boot Menu
+MENU HIDDEN
+MENU AUTOBOOT Alpine will be booted automatically in # seconds.
+TIMEOUT 30
+LABEL grsec
+  MENU DEFAULT
+  MENU LABEL Linux 3.0.10-grsec
+  KERNEL vmlinuz-3.0.10-grsec
+  APPEND initrd=initramfs-3.0.10-grsec root=UUID=a97ffe64-430f-4fd3-830e-4736d9a27af0 modules=sd-mod,usb-storage,ext4 quiet

diff -r 3e02aa9670b3 -r 6fcc1c479ee6 tools/pygrub/src/ExtLinuxConf.py

tools/pygrub/src/ExtLinuxConf.py +10 -1
@@ -60,6 +60,13 @@ class ExtLinuxImage(object):
 
                 # Bypass regular self.commands handling
                 com = None
+            elif arg.find("initrd="):
+                # find initrd image in append line
+                args = arg.strip().split(" ")
+                for a in args:
+                    if a.lower().startswith("initrd="):
+                        setattr(self, "initrd", a.replace("initrd=", ""))
+                        arg = arg.replace(a, "")
 
         if com is not None and self.commands.has_key(com):
             if self.commands[com] is not None:
@@ -86,10 +93,12 @@ class ExtLinuxImage(object):
         self._args = args
     def get_kernel(self):
         return self._kernel
+    def set_args(self, val):
+        self._args = val
     def get_args(self):
         return self._args
     kernel = property(get_kernel, set_kernel)
-    args = property(get_args)
+    args = property(get_args, set_args)
 
     def set_initrd(self, val):
         self._initrd = (None,val)
#2 lore raw

2012/1/3 Ian Campbell <[email protected]>:

Quoted 17 lines · Roger Pau Monne
Quoted 16 lines

# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325592706 -3600
# Node ID 6fcc1c479ee68f27233a55ec45a618e0f7cf5d6f # Parent  3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsing

pygrub was unable to parse extlinux config files correctly, exactly the ones like:

LABEL grsec
  KERNEL vmlinuz-3.0.10-grsec
  APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet

Quoted 6 lines
Quoted 4 lines

This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.

Can this patch be backported to 4.1 at least (I don't think 4.0 is necessary)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

Roger Pau Monné writes ("Re: [Xen-devel] [PATCH v2] pygrub: fix extlinux parsing> Can this patch be backported to 4.1 at least (I don't think 4.0 is necessary)

Done.

Ian.