Commit cc130cc7 authored by Marco Casavecchia's avatar Marco Casavecchia Committed by Iustin Pop
Browse files

Use floppy disk and a second CDROM on KVM



Hi all,
this patch will add 3 new KVM parameters and a new option.

New Parameters:
 - floppy_image_path = "" -> Specify the floppy image to load as
floppy disk.
 - cdrom2_image_path = "" -> Specify a second cdrom image to load on
the system (note: this in not intended to be used as a boot device. To
boot the system from cdrom you must use the "cdrom_image_path"
parameter as always).
 - cdrom_disk_type = "" -> it can be one of the kvm supported types as
"ide,scsi,paravirtual,ecc". I introduced this optional parameter to
make possible to specify a different virtual device for cdroms. It is
useful if you want to install a windows system

New option for "boot_device" parameter:
 -  "floppy": with this value you should be able to boot a KVM
instance from floppy image.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 52f33103
......@@ -604,8 +604,11 @@ ENFORCEABLE_TYPES = frozenset([
# HV parameter names (global namespace)
HV_BOOT_ORDER = "boot_order"
HV_CDROM_IMAGE_PATH = "cdrom_image_path"
HV_KVM_CDROM2_IMAGE_PATH = "cdrom2_image_path"
HV_KVM_FLOPPY_IMAGE_PATH = "floppy_image_path"
HV_NIC_TYPE = "nic_type"
HV_DISK_TYPE = "disk_type"
HV_KVM_CDROM_DISK_TYPE = "cdrom_disk_type"
HV_VNC_BIND_ADDRESS = "vnc_bind_address"
HV_VNC_PASSWORD_FILE = "vnc_password_file"
HV_VNC_TLS = "vnc_tls"
......@@ -641,9 +644,12 @@ HV_BLOCKDEV_PREFIX = "blockdev_prefix"
HVS_PARAMETER_TYPES = {
HV_BOOT_ORDER: VTYPE_STRING,
HV_KVM_FLOPPY_IMAGE_PATH: VTYPE_STRING,
HV_CDROM_IMAGE_PATH: VTYPE_STRING,
HV_KVM_CDROM2_IMAGE_PATH: VTYPE_STRING,
HV_NIC_TYPE: VTYPE_STRING,
HV_DISK_TYPE: VTYPE_STRING,
HV_KVM_CDROM_DISK_TYPE: VTYPE_STRING,
HV_VNC_PASSWORD_FILE: VTYPE_STRING,
HV_VNC_BIND_ADDRESS: VTYPE_STRING,
HV_VNC_TLS: VTYPE_BOOL,
......@@ -845,11 +851,13 @@ HT_MOUSE_TABLET = "tablet"
HT_KVM_VALID_MOUSE_TYPES = frozenset([HT_MOUSE_MOUSE, HT_MOUSE_TABLET])
# Boot order
HT_BO_FLOPPY = "floppy"
HT_BO_CDROM = "cdrom"
HT_BO_DISK = "disk"
HT_BO_NETWORK = "network"
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_CDROM, HT_BO_DISK, HT_BO_NETWORK])
HT_KVM_VALID_BO_TYPES = frozenset([HT_BO_FLOPPY, HT_BO_CDROM,
HT_BO_DISK, HT_BO_NETWORK])
# Security models
HT_SM_NONE = "none"
......@@ -1177,10 +1185,13 @@ HVC_DEFAULTS = {
HV_VNC_X509: '',
HV_VNC_X509_VERIFY: False,
HV_VNC_PASSWORD_FILE: '',
HV_KVM_FLOPPY_IMAGE_PATH: '',
HV_CDROM_IMAGE_PATH: '',
HV_KVM_CDROM2_IMAGE_PATH: '',
HV_BOOT_ORDER: HT_BO_DISK,
HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
HV_KVM_CDROM_DISK_TYPE: '',
HV_USB_MOUSE: '',
HV_MIGRATION_PORT: 8102,
HV_MIGRATION_BANDWIDTH: 32, # MiB/s
......
......@@ -164,13 +164,17 @@ class KVMHypervisor(hv_base.BaseHypervisor):
constants.HV_VNC_X509: hv_base.OPT_DIR_CHECK,
constants.HV_VNC_X509_VERIFY: hv_base.NO_CHECK,
constants.HV_VNC_PASSWORD_FILE: hv_base.OPT_FILE_CHECK,
constants.HV_KVM_FLOPPY_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_KVM_CDROM2_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_BOOT_ORDER:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_BO_TYPES),
constants.HV_NIC_TYPE:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_NIC_TYPES),
constants.HV_DISK_TYPE:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_DISK_TYPES),
constants.HV_KVM_CDROM_DISK_TYPE:
hv_base.ParamInSet(False, constants.HT_KVM_VALID_DISK_TYPES),
constants.HV_USB_MOUSE:
hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
......@@ -517,6 +521,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
hvp = instance.hvparams
boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
boot_cdrom = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_CDROM
boot_floppy = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_FLOPPY
boot_network = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_NETWORK
if hvp[constants.HV_KVM_FLAG] == constants.HT_KVM_ENABLED:
......@@ -565,22 +570,51 @@ class KVMHypervisor(hv_base.BaseHypervisor):
cache_val)
kvm_cmd.extend(['-drive', drive_val])
#Now we can specify a different device type for CDROM devices.
cdrom_disk_type = hvp[constants.HV_KVM_CDROM_DISK_TYPE]
if not cdrom_disk_type:
cdrom_disk_type = disk_type
iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
if iso_image:
options = ',format=raw,media=cdrom'
if boot_cdrom:
kvm_cmd.extend(['-boot', 'd'])
if disk_type != constants.HT_DISK_IDE:
if cdrom_disk_type != constants.HT_DISK_IDE:
options = '%s,boot=on,if=%s' % (options, constants.HT_DISK_IDE)
else:
options = '%s,boot=on' % options
else:
if disk_type == constants.HT_DISK_PARAVIRTUAL:
if cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL:
if_val = ',if=virtio'
else:
if_val = ',if=%s' % disk_type
if_val = ',if=%s' % cdrom_disk_type
options = '%s%s' % (options, if_val)
drive_val = 'file=%s%s' % (iso_image, options)
kvm_cmd.extend(['-drive', drive_val])
iso_image2 = hvp[constants.HV_KVM_CDROM2_IMAGE_PATH]
if iso_image2:
options = ',format=raw,media=cdrom'
if cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL:
if_val = ',if=virtio'
else:
if_val = ',if=%s' % cdrom_disk_type
options = '%s%s' % (options, if_val)
drive_val = 'file=%s%s' % (iso_image2, options)
kvm_cmd.extend(['-drive', drive_val])
floppy_image = hvp[constants.HV_KVM_FLOPPY_IMAGE_PATH]
if floppy_image:
options = ',format=raw,media=disk'
if boot_floppy:
kvm_cmd.extend(['-boot', 'a'])
options = '%s,boot=on' % options
if_val = ',if=floppy'
options = '%s%s' % (options, if_val)
drive_val = 'file=%s%s' % (floppy_image, options)
kvm_cmd.extend(['-drive', drive_val])
kernel_path = hvp[constants.HV_KERNEL_PATH]
if kernel_path:
kvm_cmd.extend(['-kernel', kernel_path])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment