From 0b35988b06a6c24a9bebb95ca32ff6994a0b7669 Mon Sep 17 00:00:00 2001 From: Jun Futagawa Date: Sat, 24 Oct 2009 14:34:15 +0900 Subject: [PATCH] Add support for using the bootloader in xen-pvm This patch adds three optional parameters: - 'use_bootloader', whether use or not the bootloader - 'bootloader_path', absolute path to the bootloader - 'bootloader_args', extra arguments to the bootloader Syntax: gnt-cluster modify --hypervisor-parameters \ xen-pvm:bootloader_path=/usr/bin/pygrub,use_bootloader=False gnt-instance modify -H use_bootloader=True instance1.example.com If use_bootloader is True, each domU can boot with its own kernel instead of using the dom0 kernel. Signed-off-by: Jun Futagawa --- Makefile.am | 2 ++ configure.ac | 9 +++++++++ lib/constants.py | 10 ++++++++++ lib/hypervisor/hv_xen.py | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Makefile.am b/Makefile.am index 26d6b1c..1e8a155 100644 --- a/Makefile.am +++ b/Makefile.am @@ -324,6 +324,7 @@ lib/_autoconf.py: Makefile stamp-directories echo "SSH_INITD_SCRIPT = '$(SSH_INITD_SCRIPT)'"; \ echo "EXPORT_DIR = '$(EXPORT_DIR)'"; \ echo "OS_SEARCH_PATH = [$(OS_SEARCH_PATH)]"; \ + echo "XEN_BOOTLOADER = '$(XEN_BOOTLOADER)'"; \ echo "XEN_KERNEL = '$(XEN_KERNEL)'"; \ echo "XEN_INITRD = '$(XEN_INITRD)'"; \ echo "FILE_STORAGE_DIR = '$(FILE_STORAGE_DIR)'"; \ @@ -341,6 +342,7 @@ $(REPLACE_VARS_SED): Makefile stamp-directories echo 's#@LOCALSTATEDIR@#$(localstatedir)#g'; \ echo 's#@SBINDIR@#$(sbindir)#g'; \ echo 's#@GANETI_VERSION@#$(PACKAGE_VERSION)#g'; \ + echo 's#@CUSTOM_XEN_BOOTLOADER@#$(XEN_BOOTLOADER)#g'; \ echo 's#@CUSTOM_XEN_KERNEL@#$(XEN_KERNEL)#g'; \ echo 's#@CUSTOM_XEN_INITRD@#$(XEN_INITRD)#g'; \ echo 's#@RPL_FILE_STORAGE_DIR@#$(FILE_STORAGE_DIR)#g'; \ diff --git a/configure.ac b/configure.ac index 2e5b386..7b9a747 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,15 @@ AC_ARG_WITH([iallocator-search-path], [iallocator_search_path="'$libdir/$PACKAGE_NAME/iallocators'"]) AC_SUBST(IALLOCATOR_SEARCH_PATH, $iallocator_search_path) +# --with-xen-bootloader=... +AC_ARG_WITH([xen-bootloader], + [AS_HELP_STRING([--with-xen-bootloader=PATH], + [bootloader for Xen hypervisor (default is empty)] + )], + [xen_bootloader="$withval"], + [xen_bootloader=]) +AC_SUBST(XEN_BOOTLOADER, $xen_bootloader) + # --with-xen-kernel=... AC_ARG_WITH([xen-kernel], [AS_HELP_STRING([--with-xen-kernel=PATH], diff --git a/lib/constants.py b/lib/constants.py index e5dafb1..a4d92f9 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -130,6 +130,7 @@ EXPORT_DIR = _autoconf.EXPORT_DIR EXPORT_CONF_FILE = "config.ini" +XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER XEN_KERNEL = _autoconf.XEN_KERNEL XEN_INITRD = _autoconf.XEN_INITRD @@ -302,6 +303,9 @@ HV_VNC_X509 = "vnc_x509_path" HV_VNC_X509_VERIFY = "vnc_x509_verify" HV_ACPI = "acpi" HV_PAE = "pae" +HV_USE_BOOTLOADER = "use_bootloader" +HV_BOOTLOADER_ARGS = "bootloader_args" +HV_BOOTLOADER_PATH = "bootloader_path" HV_KERNEL_ARGS = "kernel_args" HV_KERNEL_PATH = "kernel_path" HV_INITRD_PATH = "initrd_path" @@ -321,6 +325,9 @@ HVS_PARAMETER_TYPES = { HV_VNC_X509_VERIFY: VTYPE_BOOL, HV_ACPI: VTYPE_BOOL, HV_PAE: VTYPE_BOOL, + HV_USE_BOOTLOADER: VTYPE_BOOL, + HV_BOOTLOADER_PATH: VTYPE_STRING, + HV_BOOTLOADER_ARGS: VTYPE_STRING, HV_KERNEL_PATH: VTYPE_STRING, HV_KERNEL_ARGS: VTYPE_STRING, HV_INITRD_PATH: VTYPE_STRING, @@ -499,6 +506,9 @@ DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM HVC_DEFAULTS = { HT_XEN_PVM: { + HV_USE_BOOTLOADER: False, + HV_BOOTLOADER_PATH: XEN_BOOTLOADER, + HV_BOOTLOADER_ARGS: '', HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU", HV_INITRD_PATH: '', HV_ROOT_PATH: '/dev/sda1', diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 8a29d6b..547ee0e 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -402,6 +402,9 @@ class XenPvmHypervisor(XenHypervisor): """Xen PVM hypervisor interface""" PARAMETERS = [ + constants.HV_USE_BOOTLOADER, + constants.HV_BOOTLOADER_PATH, + constants.HV_BOOTLOADER_ARGS, constants.HV_KERNEL_PATH, constants.HV_INITRD_PATH, constants.HV_ROOT_PATH, @@ -422,6 +425,11 @@ class XenPvmHypervisor(XenHypervisor): """ super(XenPvmHypervisor, cls).CheckParameterSyntax(hvparams) + if hvparams[constants.HV_BOOTLOADER_PATH]: + if not os.path.isabs(hvparams[constants.HV_BOOTLOADER_PATH]): + raise errors.HypervisorError("The bootloader path must be an absolute" + "path, if defined") + if not hvparams[constants.HV_KERNEL_PATH]: raise errors.HypervisorError("Need a kernel for the instance") @@ -463,14 +471,29 @@ class XenPvmHypervisor(XenHypervisor): config = StringIO() config.write("# this is autogenerated by Ganeti, please do not edit\n#\n") - # kernel handling - kpath = hvp[constants.HV_KERNEL_PATH] - config.write("kernel = '%s'\n" % kpath) + # if bootloader is True, use bootloader instead of kernel and ramdisk + # parameters. + if hvp[constants.HV_USE_BOOTLOADER]: + # bootloader handling + bootloader_path = hvp[constants.HV_BOOTLOADER_PATH] + if bootloader_path: + config.write("bootloader = '%s'\n" % bootloader_path) + else: + raise errors.HypervisorError("Bootloader enabled, but missing" + " bootloader path") - # initrd handling - initrd_path = hvp[constants.HV_INITRD_PATH] - if initrd_path: - config.write("ramdisk = '%s'\n" % initrd_path) + bootloader_args = hvp[constants.HV_BOOTLOADER_ARGS] + if bootloader_args: + config.write("bootargs = '%s'\n" % bootloader_args) + else: + # kernel handling + kpath = hvp[constants.HV_KERNEL_PATH] + config.write("kernel = '%s'\n" % kpath) + + # initrd handling + initrd_path = hvp[constants.HV_INITRD_PATH] + if initrd_path: + config.write("ramdisk = '%s'\n" % initrd_path) # rest of the settings config.write("memory = %d\n" % instance.beparams[constants.BE_MEMORY]) -- 1.5.5.6