WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [RFC] bootloader improvements - pygrub-nogrub

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [RFC] bootloader improvements - pygrub-nogrub
From: John Levon <levon@xxxxxxxxxxxxxxxxx>
Date: Thu, 9 Nov 2006 19:23:03 +0000
Delivery-date: Thu, 09 Nov 2006 11:23:39 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <20061109192017.GA16487@xxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20061109192017.GA16487@xxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.9i
# HG changeset patch
# User john.levon@xxxxxxx
# Date 1163095809 28800
# Node ID aebe98c33a6bc0cd633d915b9e0bad40718c29d6
# Parent  0da173ee886e13bd4116c7d085cd4a4704ffe279
Pass in kernel/ramdisk settings to pygrub; if specified, don't try to use
grub.conf; this allows hands-off bootloading in the absence of a grub.conf.
It's also useful for specifying temporary changes etc.

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -431,19 +431,56 @@ def get_entry_idx(cf, entry):
 
     return None
 
+def run_grub(file, isconfig, entry):
+    global g
+
+    def run_main(scr, *args):
+        global sel
+        global g
+        sel = g.run()
+
+    g = Grub(file, isconfig)
+    if interactive:
+        curses.wrapper(run_main)
+    else:
+        sel = g.cf.default
+
+    # set the entry to boot as requested
+    if entry is not None:
+        idx = get_entry_idx(g.cf, entry)
+        if idx is not None and idx > 0 and idx < len(g.cf.images):
+           sel = idx
+
+    if sel == -1:
+        print "No kernel image selected!"
+        sys.exit(1)
+
+    img = g.cf.images[sel]
+
+    grubcfg["kernel"] = img.kernel[1]
+    grubcfg["ramdisk"] = img.initrd[1]
+    grubcfg["args"] = img.args[1]
+
+    print "Going to boot %s" %(img.title)
+    print "  kernel: %s" % grubcfg["kernel"]
+    if img.initrd:
+        print "  initrd: %s" % grubcfg["ramdisk"]
+
+    if isconfig:
+        print "  args: %s" % grubcfg["args"]
+        sys.exit(0)
+        
+    return grubcfg
+
 if __name__ == "__main__":
     sel = None
     
-    def run_main(scr, *args):
-        global sel
-        sel = g.run()
-
     def usage():
-        print >> sys.stderr, "Usage: %s [-q|--quiet] [--output=] [--entry=] 
<image>" %(sys.argv[0],)
+        print >> sys.stderr, "Usage: %s [-q|--quiet] [--output=] [--kernel=] 
[--ramdisk=] [--args=] [--entry=] <image>" %(sys.argv[0],)
 
     try:
         opts, args = getopt.gnu_getopt(sys.argv[1:], 'qh::',
-                                   ["quiet", "help", "output=", "entry=",
+                                   ["quiet", "help", "output=", "entry=", 
"kernel=", "ramdisk=", "args=",
                                     "isconfig"])
     except getopt.GetoptError:
         usage()
@@ -458,6 +495,14 @@ if __name__ == "__main__":
     entry = None
     interactive = True
     isconfig = False
+
+    # what was passed in
+    incfg = { "kernel": None, "ramdisk": None, "args": None };
+    # what grub chose
+    chosencfg = { "kernel": None, "ramdisk": None, "args": None };
+    # what to boot
+    bootcfg = { "kernel": None, "ramdisk": None, "args": None };
+
     for o, a in opts:
         if o in ("-q", "--quiet"):
             interactive = False
@@ -466,6 +511,12 @@ if __name__ == "__main__":
             sys.exit()
         elif o in ("--output",):
             output = a
+        elif o in ("--kernel",):
+            incfg["kernel"] = a
+        elif o in ("--ramdisk",):
+            incfg["ramdisk"] = a
+        elif o in ("--args",):
+            incfg["args"] = a
         elif o in ("--entry",):
             entry = a
             # specifying the entry to boot implies non-interactive
@@ -473,37 +524,17 @@ if __name__ == "__main__":
         elif o in ("--isconfig",):
             isconfig = True
 
+
     if output is None or output == "-":
         fd = sys.stdout.fileno()
     else:
         fd = os.open(output, os.O_WRONLY)
 
-    g = Grub(file, isconfig)
-    if interactive:
-        curses.wrapper(run_main)
+    if not incfg["kernel"]:
+        chosencfg = run_grub(file, isconfig, entry)
     else:
-        sel = g.cf.default
-
-    # set the entry to boot as requested
-    if entry is not None:
-        idx = get_entry_idx(g.cf, entry)
-        if idx is not None and idx > 0 and idx < len(g.cf.images):
-            sel = idx
-
-    if sel == -1:
-        print "No kernel image selected!"
-        sys.exit(1)
-
-    img = g.cf.images[sel]
-    print "Going to boot %s" %(img.title)
-    print "  kernel: %s" %(img.kernel[1],)
-    if img.initrd:
-        print "  initrd: %s" %(img.initrd[1],)
-
-    if isconfig:
-        print "  args: %s" %(img.args,)
-        sys.exit(0)
-        
+        chosencfg = incfg
+     
     offset = 0
     if is_disk_image(file):
         offset = get_active_offset(file)
@@ -513,22 +544,26 @@ if __name__ == "__main__":
     # read the kernel and initrd onto the hostfs
     fs = fsimage.open(file, offset)
 
-    kernel = fs.open_file(img.kernel[1],).read()
-    (tfd, fn) = tempfile.mkstemp(prefix="boot_kernel.", dir="/var/lib/xen")
-    os.write(tfd, kernel)
+    data = fs.open_file(chosencfg["kernel"]).read()
+    (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.", 
dir="/var/lib/xen")
+    os.write(tfd, data)
     os.close(tfd)
-    sxp = "linux (boot_kernel %s)" %(fn,)
-
-    if img.initrd:
-        initrd = fs.open_file(img.initrd[1],).read()
-        (tfd, fn) = tempfile.mkstemp(prefix="boot_ramdisk.", 
dir="/var/lib/xen")
-        os.write(tfd, initrd)
+
+    if chosencfg["ramdisk"]:
+        data = fs.open_file(chosencfg["ramdisk"],).read()
+        (tfd, bootcfg["ramdisk"]) = tempfile.mkstemp(prefix="boot_ramdisk.", 
dir="/var/lib/xen")
+        os.write(tfd, data)
         os.close(tfd)
-        sxp += "(boot_ramdisk %s)" %(fn,)
-    else:
-        initrd = None
-    sxp += "(args '%s')" %(img.args,)
+
+    sxp = "linux (boot_kernel %s)" % bootcfg["kernel"]
+    if bootcfg["ramdisk"]:
+        sxp += "(boot_ramdisk %s)" % bootcfg["ramdisk"]
+    if incfg["kernel"]:
+        sxp += "(kernel %s)" % incfg["kernel"]
+    if incfg["ramdisk"]:
+        sxp += "(ramdisk %s)" % incfg["ramdisk"]
+    if chosencfg["args"]:
+        sxp += "(args \"%s\")" % chosencfg["args"]
 
     sys.stdout.flush()
     os.write(fd, sxp)
-    
diff --git a/tools/python/xen/xend/XendBootloader.py 
b/tools/python/xen/xend/XendBootloader.py
--- a/tools/python/xen/xend/XendBootloader.py
+++ b/tools/python/xen/xend/XendBootloader.py
@@ -46,6 +46,16 @@ def bootloader(blexec, disk, quiet = 0, 
     child = os.fork()
     if (not child):
         args = [ blexec ]
+        if imgcfg:
+            kernel = sxp.child_value(imgcfg, "kernel")
+            ramdisk = sxp.child_value(imgcfg, "ramdisk")
+            kargs = sxp.child_value(imgcfg, "args")
+            if kernel:
+                args.append("--kernel=%s" % kernel)
+            if ramdisk:
+                args.append("--ramdisk=%s" % ramdisk)
+            if kargs:
+                args.append("--args=%s" % kargs)
         if quiet:
             args.append("-q")
         args.append("--output=%s" % fifo)

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