ia64/xen-unstable

changeset 13336:6638763ee12c

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@sun.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Tue Jan 09 13:24:40 2007 +0000 (2007-01-09)
parents 2dba70eb5bd5
children ac626903f46b
files tools/pygrub/src/pygrub tools/python/xen/xend/XendBootloader.py
line diff
     1.1 --- a/tools/pygrub/src/pygrub	Tue Jan 09 13:24:40 2007 +0000
     1.2 +++ b/tools/pygrub/src/pygrub	Tue Jan 09 13:24:40 2007 +0000
     1.3 @@ -431,19 +431,56 @@ def get_entry_idx(cf, entry):
     1.4  
     1.5      return None
     1.6  
     1.7 +def run_grub(file, isconfig, entry):
     1.8 +    global g
     1.9 +
    1.10 +    def run_main(scr, *args):
    1.11 +        global sel
    1.12 +        global g
    1.13 +        sel = g.run()
    1.14 +
    1.15 +    g = Grub(file, isconfig)
    1.16 +    if interactive:
    1.17 +        curses.wrapper(run_main)
    1.18 +    else:
    1.19 +        sel = g.cf.default
    1.20 +
    1.21 +    # set the entry to boot as requested
    1.22 +    if entry is not None:
    1.23 +        idx = get_entry_idx(g.cf, entry)
    1.24 +        if idx is not None and idx > 0 and idx < len(g.cf.images):
    1.25 +           sel = idx
    1.26 +
    1.27 +    if sel == -1:
    1.28 +        print "No kernel image selected!"
    1.29 +        sys.exit(1)
    1.30 +
    1.31 +    img = g.cf.images[sel]
    1.32 +
    1.33 +    grubcfg["kernel"] = img.kernel[1]
    1.34 +    grubcfg["ramdisk"] = img.initrd[1]
    1.35 +    grubcfg["args"] = img.args[1]
    1.36 +
    1.37 +    print "Going to boot %s" %(img.title)
    1.38 +    print "  kernel: %s" % grubcfg["kernel"]
    1.39 +    if img.initrd:
    1.40 +        print "  initrd: %s" % grubcfg["ramdisk"]
    1.41 +
    1.42 +    if isconfig:
    1.43 +        print "  args: %s" % grubcfg["args"]
    1.44 +        sys.exit(0)
    1.45 +        
    1.46 +    return grubcfg
    1.47 +
    1.48  if __name__ == "__main__":
    1.49      sel = None
    1.50      
    1.51 -    def run_main(scr, *args):
    1.52 -        global sel
    1.53 -        sel = g.run()
    1.54 -
    1.55      def usage():
    1.56 -        print >> sys.stderr, "Usage: %s [-q|--quiet] [--output=] [--entry=] <image>" %(sys.argv[0],)
    1.57 +        print >> sys.stderr, "Usage: %s [-q|--quiet] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] <image>" %(sys.argv[0],)
    1.58  
    1.59      try:
    1.60          opts, args = getopt.gnu_getopt(sys.argv[1:], 'qh::',
    1.61 -                                   ["quiet", "help", "output=", "entry=",
    1.62 +                                   ["quiet", "help", "output=", "entry=", "kernel=", "ramdisk=", "args=",
    1.63                                      "isconfig"])
    1.64      except getopt.GetoptError:
    1.65          usage()
    1.66 @@ -458,6 +495,14 @@ if __name__ == "__main__":
    1.67      entry = None
    1.68      interactive = True
    1.69      isconfig = False
    1.70 +
    1.71 +    # what was passed in
    1.72 +    incfg = { "kernel": None, "ramdisk": None, "args": None };
    1.73 +    # what grub chose
    1.74 +    chosencfg = { "kernel": None, "ramdisk": None, "args": None };
    1.75 +    # what to boot
    1.76 +    bootcfg = { "kernel": None, "ramdisk": None, "args": None };
    1.77 +
    1.78      for o, a in opts:
    1.79          if o in ("-q", "--quiet"):
    1.80              interactive = False
    1.81 @@ -466,6 +511,12 @@ if __name__ == "__main__":
    1.82              sys.exit()
    1.83          elif o in ("--output",):
    1.84              output = a
    1.85 +        elif o in ("--kernel",):
    1.86 +            incfg["kernel"] = a
    1.87 +        elif o in ("--ramdisk",):
    1.88 +            incfg["ramdisk"] = a
    1.89 +        elif o in ("--args",):
    1.90 +            incfg["args"] = a
    1.91          elif o in ("--entry",):
    1.92              entry = a
    1.93              # specifying the entry to boot implies non-interactive
    1.94 @@ -473,37 +524,17 @@ if __name__ == "__main__":
    1.95          elif o in ("--isconfig",):
    1.96              isconfig = True
    1.97  
    1.98 +
    1.99      if output is None or output == "-":
   1.100          fd = sys.stdout.fileno()
   1.101      else:
   1.102          fd = os.open(output, os.O_WRONLY)
   1.103  
   1.104 -    g = Grub(file, isconfig)
   1.105 -    if interactive:
   1.106 -        curses.wrapper(run_main)
   1.107 +    if not incfg["kernel"]:
   1.108 +        chosencfg = run_grub(file, isconfig, entry)
   1.109      else:
   1.110 -        sel = g.cf.default
   1.111 -
   1.112 -    # set the entry to boot as requested
   1.113 -    if entry is not None:
   1.114 -        idx = get_entry_idx(g.cf, entry)
   1.115 -        if idx is not None and idx > 0 and idx < len(g.cf.images):
   1.116 -            sel = idx
   1.117 -
   1.118 -    if sel == -1:
   1.119 -        print "No kernel image selected!"
   1.120 -        sys.exit(1)
   1.121 -
   1.122 -    img = g.cf.images[sel]
   1.123 -    print "Going to boot %s" %(img.title)
   1.124 -    print "  kernel: %s" %(img.kernel[1],)
   1.125 -    if img.initrd:
   1.126 -        print "  initrd: %s" %(img.initrd[1],)
   1.127 -
   1.128 -    if isconfig:
   1.129 -        print "  args: %s" %(img.args,)
   1.130 -        sys.exit(0)
   1.131 -        
   1.132 +        chosencfg = incfg
   1.133 +     
   1.134      offset = 0
   1.135      if is_disk_image(file):
   1.136          offset = get_active_offset(file)
   1.137 @@ -513,23 +544,26 @@ if __name__ == "__main__":
   1.138      # read the kernel and initrd onto the hostfs
   1.139      fs = fsimage.open(file, offset)
   1.140  
   1.141 -    kernel = fs.open_file(img.kernel[1],).read()
   1.142 -    (tfd, fn) = tempfile.mkstemp(prefix="boot_kernel.",
   1.143 +    data = fs.open_file(chosencfg["kernel"]).read()
   1.144 +    (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.",
   1.145          dir="/var/run/xend/boot")
   1.146 -    os.write(tfd, kernel)
   1.147 +    os.write(tfd, data)
   1.148      os.close(tfd)
   1.149 -    sxp = "linux (kernel %s)" %(fn,)
   1.150  
   1.151 -    if img.initrd:
   1.152 -        initrd = fs.open_file(img.initrd[1],).read()
   1.153 -        (tfd, fn) = tempfile.mkstemp(prefix="boot_ramdisk.",
   1.154 +    if chosencfg["ramdisk"]:
   1.155 +        data = fs.open_file(chosencfg["ramdisk"],).read()
   1.156 +        (tfd, bootcfg["ramdisk"]) = tempfile.mkstemp(prefix="boot_ramdisk.",
   1.157              dir="/var/run/xend/boot")
   1.158 -        os.write(tfd, initrd)
   1.159 +        os.write(tfd, data)
   1.160          os.close(tfd)
   1.161 -        sxp += "(ramdisk %s)" %(fn,)
   1.162      else:
   1.163          initrd = None
   1.164 -    sxp += "(args '%s')" %(img.args,)
   1.165 +
   1.166 +    sxp = "linux (kernel %s)" % bootcfg["kernel"]
   1.167 +    if bootcfg["ramdisk"]:
   1.168 +        sxp += "(ramdisk %s)" % bootcfg["ramdisk"]
   1.169 +    if chosencfg["args"]:
   1.170 +        sxp += "(args \"%s\")" % chosencfg["args"]
   1.171  
   1.172      sys.stdout.flush()
   1.173      os.write(fd, sxp)
     2.1 --- a/tools/python/xen/xend/XendBootloader.py	Tue Jan 09 13:24:40 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendBootloader.py	Tue Jan 09 13:24:40 2007 +0000
     2.3 @@ -53,6 +53,12 @@ def bootloader(blexec, disk, quiet = Fal
     2.4      child = os.fork()
     2.5      if (not child):
     2.6          args = [ blexec ]
     2.7 +        if kernel:
     2.8 +            args.append("--kernel=%s" % kernel)
     2.9 +        if ramdisk:
    2.10 +            args.append("--ramdisk=%s" % ramdisk)
    2.11 +        if kernel_args:
    2.12 +            args.append("--args=%s" % kernel_args)
    2.13          if quiet:
    2.14              args.append("-q")
    2.15          args.append("--output=%s" % fifo)