From 074ca009da2ec9f73e893c2e0d7c967866293751 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 27 Jan 2009 11:31:38 +0000 Subject: [PATCH] KVM and Xen: add the HV_ROOT_PATH parameter This parameter allows a different path to be passed to the instance kernel. The new parameter is mandatory, and by default has the value of the old hardcoded value for both kvm and xen. Beta1 clusters will need to have this parameter added for their instances to be able to boot. Reviewed-by: iustinp --- lib/constants.py | 4 ++++ lib/hypervisor/hv_kvm.py | 7 ++++++- lib/hypervisor/hv_xen.py | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/constants.py b/lib/constants.py index 0c44675a8..9d85e6193 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -287,6 +287,7 @@ HV_ACPI = "acpi" HV_PAE = "pae" HV_KERNEL_PATH = "kernel_path" HV_INITRD_PATH = "initrd_path" +HV_ROOT_PATH = "root_path" HVS_PARAMETERS = frozenset([ HV_BOOT_ORDER, @@ -298,6 +299,7 @@ HVS_PARAMETERS = frozenset([ HV_PAE, HV_KERNEL_PATH, HV_INITRD_PATH, + HV_ROOT_PATH, ]) # BE parameter names @@ -426,6 +428,7 @@ HVC_DEFAULTS = { HT_XEN_PVM: { HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU", HV_INITRD_PATH: None, + HV_ROOT_PATH: '/dev/sda', }, HT_XEN_HVM: { HV_BOOT_ORDER: "cd", @@ -439,6 +442,7 @@ HVC_DEFAULTS = { HT_KVM: { HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU", HV_INITRD_PATH: None, + HV_ROOT_PATH: '/dev/vda', HV_ACPI: True, }, HT_FAKE: { diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 0316b1ba5..22cbdc5c9 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -51,6 +51,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): PARAMETERS = [ constants.HV_KERNEL_PATH, constants.HV_INITRD_PATH, + constants.HV_ROOT_PATH, constants.HV_ACPI, ] @@ -240,7 +241,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): if initrd_path: kvm_cmd.extend(['-initrd', initrd_path]) - kvm_cmd.extend(['-append', 'console=ttyS0,38400 root=/dev/vda']) + root_path = instance.hvparams[constants.HV_ROOT_PATH] + kvm_cmd.extend(['-append', 'console=ttyS0,38400 root=%s ro' % root_path]) #"hvm_boot_order", #"hvm_cdrom_image_path", @@ -626,6 +628,9 @@ class KVMHypervisor(hv_base.BaseHypervisor): if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]): raise errors.HypervisorError("The kernel path must be an absolute path") + if not hvparams[constants.HV_ROOT_PATH]: + raise errors.HypervisorError("Need a root partition for the instance") + if hvparams[constants.HV_INITRD_PATH]: if not os.path.isabs(hvparams[constants.HV_INITRD_PATH]): raise errors.HypervisorError("The initrd path must be an absolute path" diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index f92b2fe6e..5b71ff234 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -364,6 +364,7 @@ class XenPvmHypervisor(XenHypervisor): PARAMETERS = [ constants.HV_KERNEL_PATH, constants.HV_INITRD_PATH, + constants.HV_ROOT_PATH, ] @classmethod @@ -386,6 +387,9 @@ class XenPvmHypervisor(XenHypervisor): if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]): raise errors.HypervisorError("The kernel path must be an absolute path") + if not hvparams[constants.HV_ROOT_PATH]: + raise errors.HypervisorError("Need a root partition for the instance") + if hvparams[constants.HV_INITRD_PATH]: if not os.path.isabs(hvparams[constants.HV_INITRD_PATH]): raise errors.HypervisorError("The initrd path must be an absolute path" @@ -443,7 +447,9 @@ class XenPvmHypervisor(XenHypervisor): config.write("disk = [%s]\n" % ",".join( cls._GetConfigFileDiskData(instance.disk_template, block_devices))) - config.write("root = '/dev/sda ro'\n") + + rpath = instance.hvparams[constants.HV_ROOT_PATH] + config.write("root = '%s ro'\n" % rpath) config.write("on_poweroff = 'destroy'\n") config.write("on_reboot = 'restart'\n") config.write("on_crash = 'restart'\n") -- GitLab