[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] Pass in kernel/ramdisk settings to pygrub; if specified, don't try to use
# HG changeset patch # User Tim Deegan <Tim.Deegan@xxxxxxxxxxxxx> # Date 1168349080 0 # Node ID 6638763ee12ce579d299b5b525905e6c8077eb1e # Parent 2dba70eb5bd5902837ed1e56d4eabd636f364a32 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> --- tools/pygrub/src/pygrub | 118 ++++++++++++++++++++------------ tools/python/xen/xend/XendBootloader.py | 6 + 2 files changed, 82 insertions(+), 42 deletions(-) diff -r 2dba70eb5bd5 -r 6638763ee12c tools/pygrub/src/pygrub --- a/tools/pygrub/src/pygrub Tue Jan 09 13:24:40 2007 +0000 +++ b/tools/pygrub/src/pygrub Tue Jan 09 13:24:40 2007 +0000 @@ -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,23 +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.", + data = fs.open_file(chosencfg["kernel"]).read() + (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.", dir="/var/run/xend/boot") - os.write(tfd, kernel) + os.write(tfd, data) os.close(tfd) - sxp = "linux (kernel %s)" %(fn,) - - if img.initrd: - initrd = fs.open_file(img.initrd[1],).read() - (tfd, fn) = tempfile.mkstemp(prefix="boot_ramdisk.", + + if chosencfg["ramdisk"]: + data = fs.open_file(chosencfg["ramdisk"],).read() + (tfd, bootcfg["ramdisk"]) = tempfile.mkstemp(prefix="boot_ramdisk.", dir="/var/run/xend/boot") - os.write(tfd, initrd) + os.write(tfd, data) os.close(tfd) - sxp += "(ramdisk %s)" %(fn,) else: initrd = None - sxp += "(args '%s')" %(img.args,) + + sxp = "linux (kernel %s)" % bootcfg["kernel"] + if bootcfg["ramdisk"]: + sxp += "(ramdisk %s)" % bootcfg["ramdisk"] + if chosencfg["args"]: + sxp += "(args \"%s\")" % chosencfg["args"] sys.stdout.flush() os.write(fd, sxp) diff -r 2dba70eb5bd5 -r 6638763ee12c tools/python/xen/xend/XendBootloader.py --- a/tools/python/xen/xend/XendBootloader.py Tue Jan 09 13:24:40 2007 +0000 +++ b/tools/python/xen/xend/XendBootloader.py Tue Jan 09 13:24:40 2007 +0000 @@ -53,6 +53,12 @@ def bootloader(blexec, disk, quiet = Fal child = os.fork() if (not child): args = [ blexec ] + if kernel: + args.append("--kernel=%s" % kernel) + if ramdisk: + args.append("--ramdisk=%s" % ramdisk) + if kernel_args: + args.append("--args=%s" % kernel_args) if quiet: args.append("-q") args.append("--output=%s" % fifo) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |