Fix pygrub path on Solaris
PATCH 1/7 Fix pygrub path on Solaris
Fix for pygrub path on Solaris.
tools/python/xen/xend/XendDomainInfo.py +2 -2
@@ -37,7 +37,7 @@ from xen.util.blkif import blkdev_uname_ from xen.util.blkif import blkdev_uname_to_file from xen.util import security -from xen.xend import balloon, sxp, uuid, image, arch +from xen.xend import balloon, sxp, uuid, image, arch, osdep from xen.xend import XendOptions, XendNode, XendConfig from xen.xend.XendConfig import scrub_password
@@ -1547,7 +1547,7 @@ class XendDomainInfo: else: # Boot using bootloader if not blexec or blexec == 'pygrub': - blexec = '/usr/bin/pygrub' + blexec = osdep.pygrub_path blcfg = None for (devtype, devinfo) in self.info.all_devices_sxpr():
tools/python/xen/xend/osdep.py +5 -0
@@ -29,8 +29,13 @@ _xend_autorestart = { "SunOS": False, } +_pygrub_path = { + "SunOS": "/usr/lib/xen/bin/pygrub" +} + def _get(var, default=None): return var.get(os.uname()[0], default) scripts_dir = _get(_scripts_dir, "/etc/xen/scripts") xend_autorestart = _get(_xend_autorestart) +pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
PATCH 2/7 don't use menu.lst if not needed
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.
tools/pygrub/src/pygrub +76 -42
@@ -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)
tools/python/xen/xend/XendBootloader.py +6 -0
@@ -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)
PATCH 3/7 Auto-load Solaris via bootloader
In reply to John LevonSniff for Solaris if not specified. This allows Solaris domU's to automatically boot correctly without fiddling with domain configs.
tools/pygrub/src/pygrub +97 -63
@@ -13,7 +13,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -import os, sys, string, struct, tempfile +import os, sys, string, struct, tempfile, re import copy import logging
@@ -65,6 +65,15 @@ def get_active_offset(file): # the first partition P1 = 446 return struct.unpack("<L", buf[P1+8:P1+12])[0] * SECTOR_SIZE + +def open_fs(file): + offset = 0 + if is_disk_image(file): + offset = get_active_offset(file) + if offset == -1: + raise RuntimeError, "Unable to find active partition on disk" + + return fsimage.open(file, offset) class GrubLineEditor(curses.textpad.Textbox): def __init__(self, screen, startx, starty, line = ""):
@@ -143,12 +152,12 @@ class GrubLineEditor(curses.textpad.Text class Grub: - def __init__(self, file, isconfig = False): + def __init__(self, file, fs = None): self.screen = None self.entry_win = None self.text_win = None if file: - self.read_config(file, isconfig) + self.read_config(file, fs) def draw_main_windows(self): if self.screen is None: #only init stuff once
@@ -295,8 +304,8 @@ class Grub: # else, we cancelled and should just go back break - def read_config(self, fn, isConfig = False): - """Read the given file to parse the config. If isconfig, then + def read_config(self, fn, fs = None): + """Read the given file to parse the config. If fs = None, then we're being given a raw config file rather than a disk image.""" if not os.access(fn, os.R_OK):
@@ -304,38 +313,25 @@ class Grub: self.cf = grub.GrubConf.GrubConfigFile() - if isConfig: + if not fs: # set the config file and parse it self.cf.filename = fn self.cf.parse() return - offset = 0 - if is_disk_image(fn): - offset = get_active_offset(fn) - if offset == -1: - raise RuntimeError, "Unable to find active partition on disk" - - # open the image and read the grub config - fs = fsimage.open(fn, offset) - - if fs is not None: - grubfile = None - for f in ("/boot/grub/menu.lst", "/boot/grub/grub.conf", - "/grub/menu.lst", "/grub/grub.conf"): - if fs.file_exists(f): - grubfile = f - break - if grubfile is None: - raise RuntimeError, "we couldn't find grub config file in the image provided." - f = fs.open_file(grubfile) - buf = f.read() - del f - del fs - # then parse the grub config - self.cf.parse(buf) - else: - raise RuntimeError, "Unable to read filesystem" + grubfile = None + for f in ("/boot/grub/menu.lst", "/boot/grub/grub.conf", + "/grub/menu.lst", "/grub/grub.conf"): + if fs.file_exists(f): + grubfile = f + break + if grubfile is None: + raise RuntimeError, "we couldn't find grub config file in the image provided." + f = fs.open_file(grubfile) + buf = f.read() + del f + # then parse the grub config + self.cf.parse(buf) def run(self): timeout = int(self.cf.timeout)
@@ -431,15 +427,16 @@ def get_entry_idx(cf, entry): return None -def run_grub(file, isconfig, entry): +def run_grub(file, entry, fs): global g + global sel def run_main(scr, *args): global sel global g sel = g.run() - g = Grub(file, isconfig) + g = Grub(file, fs) if interactive: curses.wrapper(run_main) else:
@@ -457,21 +454,57 @@ def run_grub(file, isconfig, entry): img = g.cf.images[sel] + grubcfg = { "kernel": None, "ramdisk": None, "args": None } + 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) - + grubcfg["ramdisk"] = img.initrd[1] + if img.args: + grubcfg["args"] = img.args + return grubcfg +# If nothing has been specified, look for a Solaris domU. If found, perform the +# necessary tweaks. +def sniff_solaris(fs, cfg): + if not fs.file_exists("/platform/i86xen/kernel/unix"): + return cfg + + # darned python + longmode = (sys.maxint != 2147483647L) + if not longmode: + longmode = os.uname()[4] == "x86_64" + if not longmode: + if (os.access("/usr/bin/isainfo", os.R_OK) and + os.popen("/usr/bin/isainfo -b").read() == "64\n"): + longmode = True + + if not cfg["kernel"]: + cfg["kernel"] = "/platform/i86xen/kernel/unix" + cfg["ramdisk"] = "/platform/i86pc/boot_archive" + if longmode: + cfg["kernel"] = "/platform/i86xen/kernel/amd64/unix" + cfg["ramdisk"] = "/platform/i86pc/amd64/boot_archive" + + # Unpleasant. Typically we'll have 'root=foo -k' or 'root=foo /kernel -k', + # and we need to maintain Xen properties (root= and ip=) and the kernel + # before any user args. + + xenargs = "" + userargs = "" + + if not cfg["args"]: + cfg["args"] = cfg["kernel"] + else: + for arg in cfg["args"].split(): + if re.match("^root=", arg) or re.match("^ip=", arg): + xenargs += arg + " " + elif arg != cfg["kernel"]: + userargs += arg + " " + cfg["args"] = xenargs + " " + cfg["kernel"] + " " + userargs + + return cfg + if __name__ == "__main__": sel = None
@@ -497,11 +530,11 @@ if __name__ == "__main__": isconfig = False # what was passed in - incfg = { "kernel": None, "ramdisk": None, "args": None }; - # what grub chose - chosencfg = { "kernel": None, "ramdisk": None, "args": None }; + incfg = { "kernel": None, "ramdisk": None, "args": None } + # what grub or sniffing chose + chosencfg = { "kernel": None, "ramdisk": None, "args": None } # what to boot - bootcfg = { "kernel": None, "ramdisk": None, "args": None }; + bootcfg = { "kernel": None, "ramdisk": None, "args": None } for o, a in opts: if o in ("-q", "--quiet"):
@@ -524,25 +557,26 @@ 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) - if not incfg["kernel"]: - chosencfg = run_grub(file, isconfig, entry) - else: - chosencfg = incfg - - offset = 0 - if is_disk_image(file): - offset = get_active_offset(file) - if offset == -1: - raise RuntimeError, "Unable to find active partition on disk" - - # read the kernel and initrd onto the hostfs - fs = fsimage.open(file, offset) + # debug + if isconfig: + chosencfg = run_grub(file, entry) + print " kernel: %s" % chosencfg["kernel"] + if img.initrd: + print " initrd: %s" % chosencfg["ramdisk"] + print " args: %s" % chosencfg["args"] + sys.exit(0) + + fs = open_fs(file) + + chosencfg = sniff_solaris(fs, incfg) + + if not chosencfg["kernel"]: + chosencfg = run_grub(file, entry, fs) data = fs.open_file(chosencfg["kernel"]).read() (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.",
PATCH 4/7 Fix auto-bootloading via xm
In reply to John LevonFix auto-bootloading via 'xm create'.
tools/python/xen/xm/create.py +0 -2
@@ -990,8 +990,6 @@ def preprocess_vnc(vals): vals.extra = vnc + ' ' + vals.extra def preprocess(vals): - if not vals.kernel and not vals.bootloader: - err("No kernel specified") preprocess_disk(vals) preprocess_pci(vals) preprocess_ioports(vals)
PATCH 5/7 Fix bootloader = "pygrub" via 'xm create'.
In reply to John LevonFix bootloader = "pygrub" via 'xm create'.
tools/python/xen/xm/create.py +3 -0
@@ -28,6 +28,7 @@ import xmlrpclib from xen.xend import sxp from xen.xend import PrettyPrint +from xen.xend import osdep import xen.xend.XendClient from xen.xend.XendBootloader import bootloader from xen.util import blkif
@@ -759,6 +760,8 @@ def make_config(vals): config_image = configure_image(vals) if vals.bootloader: + if vals.bootloader == "pygrub": + vals.bootloader = osdep.pygrub_path config_image = run_bootloader(vals, config_image) config.append(['bootloader', vals.bootloader]) if vals.bootargs:
PATCH 6/7 Fix xm create direct call to XendBootloader
In reply to John LevonFix xm create direct call to XendBootloader
tools/python/xen/xm/create.py +4 -1
@@ -719,8 +719,11 @@ def run_bootloader(vals, config_image): "--entry= directly.") vals.bootargs = "--entry=%s" %(vals.bootentry,) + kernel = sxp.child_value(config_image, 'kernel') + ramdisk = sxp.child_value(config_image, 'ramdisk') + args = sxp.child_value(config_image, 'args') return bootloader(vals.bootloader, file, not vals.console_autoconnect, - vals.bootargs, config_image) + vals.bootargs, kernel, ramdisk, args) def make_config(vals): """Create the domain configuration.
PATCH 7/7 xm bootload non-interactive fix
In reply to John LevonWhen booting via xm, only run the bootloader if it's in non-interactive mode:
otherwise we lose the user's named kernel and try to bootload the temporary file pygrub returned.
tools/python/xen/xm/create.py +6 -1
@@ -765,7 +765,12 @@ def make_config(vals): if vals.bootloader: if vals.bootloader == "pygrub": vals.bootloader = osdep.pygrub_path - config_image = run_bootloader(vals, config_image) + + # if a kernel is specified, we're using the bootloader + # non-interactively, and need to let xend run it so we preserve the + # real kernel choice. + if not vals.kernel: + config_image = run_bootloader(vals, config_image) config.append(['bootloader', vals.bootloader]) if vals.bootargs: config.append(['bootloader_args', vals.bootargs])
cover pygrub improvements and fixes
In reply to John LevonOoops, forgot a pre-amble. These seven patches consist of our current changes to enable pygrub. A number of them seem to be generic fixes and should probably be applied to 3.0.4 too (where they were tested). In fact, it'd be nice if they all made 3.0.4.
regards,
john
Re: [PATCH 6/7] Fix xm create direct call to XendBootloader
In reply to John LevonQuoted 11 lines · John Levon
Fix xm create direct call to XendBootloader
Signed-off-by John Levon <[email protected]>tools/python/xen/xm/create.py +0
-0@@ -719,8 +719,11 @@ def run_bootloader(vals, config_image): "--entry= directly.") vals.bootargs = "--entry=%s" %(vals.bootentry,)
tools/python/xen/xm/create.py def run_bootloader(vals, config_image): · line 729
Quoted 10 lines
tools/python/xen/xm/create.py +4
-1+ kernel = sxp.child_value(config_image, 'kernel') + ramdisk = sxp.child_value(config_image, 'ramdisk') + args = sxp.child_value(config_image, 'args') return bootloader(vals.bootloader, file, not vals.console_autoconnect, - vals.bootargs, config_image) + vals.bootargs, kernel, ramdisk, args) def make_config(vals): """Create the domain configuration.
Surely there's no reason for xm to be running the bootloader directly?! That doesn't make any sense. Can't we just delete all of this code?
Ewan.
Re: [PATCH 6/7] Fix xm create direct call to XendBootloader
Quoted 21 lines · Ewan Mellor
Quoted 19 lines · John Levon
Fix xm create direct call to XendBootloader
Signed-off-by John Levon <[email protected]>tools/python/xen/xm/create.py +4
-1@@ -719,8 +719,11 @@ def run_bootloader(vals, config_image): "--entry= directly.") vals.bootargs = "--entry=%s" %(vals.bootentry,) + kernel = sxp.child_value(config_image, 'kernel') + ramdisk = sxp.child_value(config_image, 'ramdisk') + args = sxp.child_value(config_image, 'args') return bootloader(vals.bootloader, file, not vals.console_autoconnect, - vals.bootargs, config_image) + vals.bootargs, kernel, ramdisk, args)
Quoted 5 lines
tools/python/xen/xm/create.py def run_bootloader(vals, config_image): · line 729
Quoted 2 lines
tools/python/xen/xm/create.py +0
-0def make_config(vals): """Create the domain configuration.Surely there's no reason for xm to be running the bootloader directly?! That doesn't make any sense. Can't we just delete all of this code
Doesn't xm have to be able to run the bootloader if you want the graphical menu view to let the user choose the kernel - if you run bootloader server-side then it will only ever use the default configured kernel.
Regards,
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Re: [PATCH 6/7] Fix xm create direct call to XendBootloader
In reply to Ewan MellorQuoted 18 lines · Ewan Mellor
Quoted 18 lines
Fix xm create direct call to XendBootloader
Signed-off-by John Levon <[email protected]>tools/python/xen/xm/create.py +4
-1@@ -719,8 +719,11 @@ def run_bootloader(vals, config_image): "--entry= directly.") vals.bootargs = "--entry=%s" %(vals.bootentry,) + kernel = sxp.child_value(config_image, 'kernel') + ramdisk = sxp.child_value(config_image, 'ramdisk') + args = sxp.child_value(config_image, 'args') return bootloader(vals.bootloader, file, not vals.console_autoconnect, - vals.bootargs, config_image) + vals.bootargs, kernel, ramdisk, args)
Quoted 5 lines
tools/python/xen/xm/create.py def run_bootloader(vals, config_image): · line 729
Quoted 2 lines
tools/python/xen/xm/create.py +0
-0def make_config(vals): """Create the domain configuration.Surely there's no reason for xm to be running the bootloader directly?! That doesn't make any sense. Can't we just delete all of this code?
It would be nice but it's required for Linux-style menu.lst usage in interactive mode. I'm somewhat dubious as to the utility of that given that xm reboot has to use non-interactive, but I didn't want to break anything.
regards
john