v2v: Support conversion of EFI guests (RHBZ#1184690)
VMware allows you to present UEFI firmware to guests (instead of the ordinary PC BIOS). Virt-v2v can convert these guests, but requires that UEFI is supported by the target hypervisor. Currently KVM supports OVMF, a partially open source UEFI firmware, and can run these guests. Since OVMF support was only recently added to KVM (in 2014/2015), only output to raw qemu or libvirt is supported. Rich.
Old virt-v2v had a bunch of code for removing EFI configuration from a Linux guest, and replacing it with grub. I copied this code to new virt-v2v but it was never tested. Now that OVMF exists, we can simply boot EFI guests directly on KVM. Thus these hacks can finally be removed. --- v2v/convert_linux.ml | 62 ---------------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml index f47b26f..61a6a2a 100644 --- a/v2v/convert_linux.ml +++ b/v2v/convert_linux.ml @@ -115,30 +115,6 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = ) [ "/boot/grub"; "/boot" ] with Not_found -> "" in - (* EFI? *) - let efi = - if Array.length (g#glob_expand "/boot/efi/EFI/*/grub.cfg") < 1 then - None - else ( - (* Check the first partition of each device looking for an EFI - * boot partition. We can't be sure which device is the boot - * device, so we just check them all. - *) - let devs = g#list_devices () in - let devs = Array.to_list devs in - try - Some ( - List.find ( - fun dev -> - try - g#part_get_gpt_type dev 1 - = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" - with G.Error _ -> false - ) devs - ) - with Not_found -> None - ) in - (* What kernel/kernel-like packages are installed on the current guest? *) let installed_kernels : kernel_info list = let rex_ko = Str.regexp ".*\\.k?o\\(\\.xz\\)?$" in @@ -686,43 +662,6 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = if !updated then g#aug_save (); ) - and unconfigure_efi () = - match efi with - | None -> () - | Some dev -> - match grub with - | `Grub1 -> - g#cp "/etc/grub.conf" "/boot/grub/grub.conf"; - g#ln_sf "/boot/grub/grub.conf" "/etc/grub.conf"; - - (* Reload Augeas to pick up new location of grub.conf. *) - Linux.augeas_reload verbose g; - - ignore (g#command [| "grub-install"; dev |]) - - | `Grub2 -> - (* EFI systems boot using grub2-efi, and probably don't have the - * base grub2 package installed. - *) - Linux.install verbose g inspect ["grub2"]; - - (* Relabel the EFI boot partition as a BIOS boot partition. *) - g#part_set_gpt_type dev 1 "21686148-6449-6E6F-744E-656564454649"; - - (* Delete the fstab entry for the EFI boot partition. *) - let nodes = g#aug_match "/files/etc/fstab/*[file = '/boot/efi']" in - let nodes = Array.to_list nodes in - List.iter (fun node -> ignore (g#aug_rm node)) nodes; - g#aug_save (); - - (* Install grub2 in the BIOS boot partition. This overwrites the - * previous contents of the EFI boot partition. - *) - ignore (g#command [| "grub2-install"; dev |]); - - (* Re-generate the grub2 config, and put it in the correct place *) - ignore (g#command [| "grub2-mkconfig"; "-o"; "/boot/grub2/grub.cfg" |]) - and unconfigure_kudzu () = (* Disable kudzu in the guest * Kudzu will detect the changed network hardware at boot time and @@ -1426,7 +1365,6 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = unconfigure_vbox (); unconfigure_vmware (); unconfigure_citrix (); - unconfigure_efi (); unconfigure_kudzu (); let kernel, virtio = configure_kernel () in -- 2.3.1
Also modify the input_* drivers so they pull out the firmware from the metadata. Currently this is only possible for `-i ova', since libvirt does not expose it (RHBZ#1217444). --- v2v/input_disk.ml | 1 + v2v/input_libvirtxml.ml | 1 + v2v/input_ova.ml | 12 ++++++++++++ v2v/test-v2v-i-ova-formats.expected | 1 + v2v/test-v2v-i-ova-formats.ovf | 2 +- v2v/test-v2v-i-ova-gz.expected | 1 + v2v/test-v2v-i-ova-two-disks.expected | 1 + v2v/test-v2v-print-source.sh | 1 + v2v/types.ml | 12 ++++++++++++ v2v/types.mli | 10 ++++++++++ 10 files changed, 41 insertions(+), 1 deletion(-) diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml index b3048e3..84a2f85 100644 --- a/v2v/input_disk.ml +++ b/v2v/input_disk.ml @@ -85,6 +85,7 @@ class input_disk verbose input_format disk = object s_memory = 2048L *^ 1024L *^ 1024L; (* 2048 MB *) s_vcpu = 1; (* 1 vCPU is a safe default *) s_features = [ "acpi"; "apic"; "pae" ]; + s_firmware = UnknownFirmware; (* causes virt-v2v to autodetect *) s_display = Some { s_display_type = Window; s_keymap = None; s_password = None; s_listen = LNone; s_port = None }; diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml index dd46ee2..4e019d4 100644 --- a/v2v/input_libvirtxml.ml +++ b/v2v/input_libvirtxml.ml @@ -346,6 +346,7 @@ let parse_libvirt_xml ?conn ~verbose xml = s_memory = memory; s_vcpu = vcpu; s_features = features; + s_firmware = UnknownFirmware; (* XXX until RHBZ#1217444 is fixed *) s_display = display; s_sound = sound; s_disks = []; diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index ce00f5d..3c13cd2 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -176,6 +176,8 @@ object Xml.xpath_register_ns xpathctx "rasd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSett..."; Xml.xpath_register_ns xpathctx + "vmw" "http://www.vmware.com/schema/ovf"; + Xml.xpath_register_ns xpathctx "vssd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingDa..."; let xpath_to_string expr default = @@ -211,6 +213,15 @@ object (* Search for number of vCPUs. *) let vcpu = xpath_to_int "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=3]/rasd:VirtualQuantity/text()" 1 in + (* BIOS or EFI firmware? *) + let firmware = xpath_to_string "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/vmw:Config[@vmw:key=\"firmware\"]/@vmw:value" "bios" in + let firmware = + match firmware with + | "bios" -> BIOS + | "efi" -> UEFI + | s -> + error (f_"unknown Config:firmware value %s (expected \"bios\" or \"efi\")") s in + (* Helper function to return the parent controller of a disk. *) let parent_controller id = let expr = sprintf "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:InstanceID/text()=%d]/rasd:ResourceType/text()" id in @@ -358,6 +369,7 @@ object s_memory = memory; s_vcpu = vcpu; s_features = []; (* XXX *) + s_firmware = firmware; s_display = None; (* XXX *) s_sound = None; s_disks = disks; diff --git a/v2v/test-v2v-i-ova-formats.expected b/v2v/test-v2v-i-ova-formats.expected index 68a761e..22e6136 100644 --- a/v2v/test-v2v-i-ova-formats.expected +++ b/v2v/test-v2v-i-ova-formats.expected @@ -5,6 +5,7 @@ hypervisor type: vmware memory: 1073741824 (bytes) nr vCPUs: 1 CPU features: + firmware: uefi display: sound: disks: diff --git a/v2v/test-v2v-i-ova-formats.ovf b/v2v/test-v2v-i-ova-formats.ovf index 3c685f4..4827c7e 100644 --- a/v2v/test-v2v-i-ova-formats.ovf +++ b/v2v/test-v2v-i-ova-formats.ovf @@ -118,7 +118,7 @@ </Item> <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="false"/> <vmw:Config ovf:required="false" vmw:key="cpuHotRemoveEnabled" vmw:value="false"/> - <vmw:Config ovf:required="false" vmw:key="firmware" vmw:value="bios"/> + <vmw:Config ovf:required="false" vmw:key="firmware" vmw:value="efi"/> <vmw:Config ovf:required="false" vmw:key="virtualICH7MPresent" vmw:value="false"/> <vmw:Config ovf:required="false" vmw:key="virtualSMCPresent" vmw:value="false"/> <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="false"/> diff --git a/v2v/test-v2v-i-ova-gz.expected b/v2v/test-v2v-i-ova-gz.expected index 4eeb74d..e6ef699 100644 --- a/v2v/test-v2v-i-ova-gz.expected +++ b/v2v/test-v2v-i-ova-gz.expected @@ -5,6 +5,7 @@ hypervisor type: vmware memory: 1073741824 (bytes) nr vCPUs: 1 CPU features: + firmware: bios display: sound: disks: diff --git a/v2v/test-v2v-i-ova-two-disks.expected b/v2v/test-v2v-i-ova-two-disks.expected index f54f370..c45f266 100644 --- a/v2v/test-v2v-i-ova-two-disks.expected +++ b/v2v/test-v2v-i-ova-two-disks.expected @@ -5,6 +5,7 @@ hypervisor type: vmware memory: 1073741824 (bytes) nr vCPUs: 1 CPU features: + firmware: bios display: sound: disks: diff --git a/v2v/test-v2v-print-source.sh b/v2v/test-v2v-print-source.sh index 5abd391..e7a8382 100755 --- a/v2v/test-v2v-print-source.sh +++ b/v2v/test-v2v-print-source.sh @@ -58,6 +58,7 @@ hypervisor type: test memory: 1073741824 (bytes) nr vCPUs: 1 CPU features: + firmware: unknown display: sound: disks: diff --git a/v2v/types.ml b/v2v/types.ml index 155fdc7..90591c3 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -27,6 +27,7 @@ type source = { s_memory : int64; s_vcpu : int; s_features : string list; + s_firmware : source_firmware; s_display : source_display option; s_sound : source_sound option; s_disks : source_disk list; @@ -40,6 +41,10 @@ and source_hypervisor = | Physical (* used by virt-p2v *) | UnknownHV (* used by -i disk *) | OtherHV of string +and source_firmware = + | BIOS + | UEFI + | UnknownFirmware and source_disk = { s_disk_id : int; s_qemu_uri : string; @@ -84,6 +89,7 @@ hypervisor type: %s memory: %Ld (bytes) nr vCPUs: %d CPU features: %s + firmware: %s display: %s sound: %s disks: @@ -98,6 +104,7 @@ NICs: s.s_memory s.s_vcpu (String.concat "," s.s_features) + (string_of_source_firmware s.s_firmware) (match s.s_display with | None -> "" | Some display -> string_of_source_display display) @@ -146,6 +153,11 @@ and source_hypervisor_of_string = function | "unknown" -> OtherHV "unknown" (* because `UnknownHV is for internal use *) | s -> OtherHV s +and string_of_source_firmware = function + | BIOS -> "bios" + | UEFI -> "uefi" + | UnknownFirmware -> "unknown" + and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format; s_controller = controller } = sprintf "\t%s%s%s" diff --git a/v2v/types.mli b/v2v/types.mli index 4c89d3d..b629283 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -27,6 +27,7 @@ type source = { s_memory : int64; (** Memory size (bytes). *) s_vcpu : int; (** Number of CPUs. *) s_features : string list; (** Machine features. *) + s_firmware : source_firmware; (** Firmware (BIOS or EFI). *) s_display : source_display option; (** Guest display. *) s_sound : source_sound option; (** Sound card. *) s_disks : source_disk list; (** Disk images. *) @@ -46,6 +47,15 @@ and source_hypervisor = [libvirt.git/docs/schemas/domaincommon.rng] for the list supported by libvirt. *) +and source_firmware = + | BIOS (** PC BIOS or default firmware *) + | UEFI (** UEFI *) + | UnknownFirmware (** Unknown: try to autodetect. *) +(** The firmware from the source metadata. Note that + [UnknownFirmware] state corresponds to disks (where we have no + metadata) and temporarily also to libvirt because of + RHBZ#1217444. *) + and source_disk = { s_disk_id : int; (** A unique ID for each source disk. *) s_qemu_uri : string; (** QEMU URI of source disk. *) -- 2.3.1
This is only used where we have missing metadata (in the source.s_firmware == UnknownFirmware case). --- v2v/types.ml | 1 + v2v/types.mli | 1 + v2v/v2v.ml | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/v2v/types.ml b/v2v/types.ml index 90591c3..5531f26 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -275,6 +275,7 @@ type inspect = { i_mountpoints : (string * string) list; i_apps : Guestfs.application2 list; i_apps_map : Guestfs.application2 list StringMap.t; + i_uefi : bool; } type mpstat = { diff --git a/v2v/types.mli b/v2v/types.mli index b629283..1ee9013 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -164,6 +164,7 @@ type inspect = { (** This is a map from the app name to the application object. Since RPM allows multiple packages with the same name to be installed, the value is a list. *) + i_uefi : bool; (** True if the guest could boot with UEFI. *) } (** Inspection information. *) diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 0ae7f7d..dcf0b80 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -530,6 +530,22 @@ and inspect_source g root_choice = StringMap.add name (app :: vs) map ) StringMap.empty apps in + (* See if this guest could use UEFI to boot. It should use GPT and + * it should have an EFI System Partition (ESP). + *) + let uefi = + let rec uefi_ESP_guid = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" + and is_uefi_ESP dev { G.part_num = partnum } = + g#part_get_gpt_type dev (Int32.to_int partnum) = uefi_ESP_guid + and is_uefi_bootable_device dev = + g#part_get_parttype dev = "gpt" && ( + let partitions = Array.to_list (g#part_list dev) in + List.exists (is_uefi_ESP dev) partitions + ) + in + let devices = Array.to_list (g#list_devices ()) in + List.exists is_uefi_bootable_device devices in + { i_root = root; i_type = g#inspect_get_type root; i_distro = g#inspect_get_distro root; @@ -542,7 +558,8 @@ and inspect_source g root_choice = i_product_variant = g#inspect_get_product_variant root; i_mountpoints = mps; i_apps = apps; - i_apps_map = apps_map; } + i_apps_map = apps_map; + i_uefi = uefi; } (* Conversion can fail if there is no space on the guest filesystems * (RHBZ#1139543). To avoid this situation, check there is some -- 2.3.1
This helps with debugging. --- v2v/types.ml | 45 +++++++++++++++++++++++++++++++++++++++++++++ v2v/types.mli | 4 ++++ v2v/v2v.ml | 16 +++++++++++----- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/v2v/types.ml b/v2v/types.ml index 5531f26..2817557 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -278,6 +278,31 @@ type inspect = { i_uefi : bool; } +let string_of_inspect inspect = + sprintf "\ +i_root = %s +i_type = %s +i_distro = %s +i_arch = %s +i_major_version = %d +i_minor_version = %d +i_package_format = %s +i_package_management = %s +i_product_name = %s +i_product_variant = %s +i_uefi = %b +" inspect.i_root + inspect.i_type + inspect.i_distro + inspect.i_arch + inspect.i_major_version + inspect.i_minor_version + inspect.i_package_format + inspect.i_package_management + inspect.i_product_name + inspect.i_product_variant + inspect.i_uefi + type mpstat = { mp_dev : string; mp_path : string; @@ -296,6 +321,26 @@ and guestcaps_block_type = Virtio_blk | IDE and guestcaps_net_type = Virtio_net | E1000 | RTL8139 and guestcaps_video_type = QXL | Cirrus +let string_of_guestcaps gcaps = + sprintf "\ +gcaps_block_bus = %s +gcaps_net_bus = %s +gcaps_video = %s +gcaps_arch = %s +gcaps_acpi = %b +" (match gcaps.gcaps_block_bus with + | Virtio_blk -> "virtio" + | IDE -> "ide") + (match gcaps.gcaps_net_bus with + | Virtio_net -> "virtio-net" + | E1000 -> "e1000" + | RTL8139 -> "rtl8139") + (match gcaps.gcaps_video with + | QXL -> "qxl" + | Cirrus -> "cirrus") + gcaps.gcaps_arch + gcaps.gcaps_acpi + class virtual input verbose = object method virtual as_options : string method virtual source : unit -> source diff --git a/v2v/types.mli b/v2v/types.mli index 1ee9013..b96ef8a 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -168,6 +168,8 @@ type inspect = { } (** Inspection information. *) +val string_of_inspect : inspect -> string + type guestcaps = { gcaps_block_bus : guestcaps_block_type; gcaps_net_bus : guestcaps_net_type; @@ -187,6 +189,8 @@ and guestcaps_block_type = Virtio_blk | IDE and guestcaps_net_type = Virtio_net | E1000 | RTL8139 and guestcaps_video_type = QXL | Cirrus +val string_of_guestcaps : guestcaps -> string + class virtual input : bool -> object method virtual as_options : string (** Converts the input object back to the equivalent command line options. diff --git a/v2v/v2v.ml b/v2v/v2v.ml index dcf0b80..10aff9c 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -222,7 +222,7 @@ let rec main () = (* Inspection - this also mounts up the filesystems. *) msg (f_"Inspecting the overlay"); - let inspect = inspect_source g root_choice in + let inspect = inspect_source ~verbose g root_choice in (* The guest free disk space check and the target free space * estimation both require statvfs information from mountpoints, so @@ -269,7 +269,9 @@ let rec main () = error (f_"virt-v2v is unable to convert this guest type (%s/%s)") inspect.i_type inspect.i_distro in if verbose then printf "picked conversion module %s\n%!" conversion_name; - convert ~verbose ~keep_serial_console g inspect source in + let guestcaps = convert ~verbose ~keep_serial_console g inspect source in + if verbose then printf "%s%!" (string_of_guestcaps guestcaps); + guestcaps in (* Did we manage to install virtio drivers? *) if not quiet then ( @@ -434,7 +436,7 @@ let rec main () = if debug_gc then Gc.compact () -and inspect_source g root_choice = +and inspect_source ~verbose g root_choice = let roots = g#inspect_os () in let roots = Array.to_list roots in @@ -546,7 +548,8 @@ and inspect_source g root_choice = let devices = Array.to_list (g#list_devices ()) in List.exists is_uefi_bootable_device devices in - { i_root = root; + let inspect = { + i_root = root; i_type = g#inspect_get_type root; i_distro = g#inspect_get_distro root; i_arch = g#inspect_get_arch root; @@ -559,7 +562,10 @@ and inspect_source g root_choice = i_mountpoints = mps; i_apps = apps; i_apps_map = apps_map; - i_uefi = uefi; } + i_uefi = uefi + } in + if verbose then printf "%s%!" (string_of_inspect inspect); + inspect (* Conversion can fail if there is no space on the guest filesystems * (RHBZ#1139543). To avoid this situation, check there is some -- 2.3.1
Add the Types.target_firmware type, which stores our final decision for whether the guest requires BIOS or UEFI on the target. Not all output modes support UEFI. In order to fail as early as possible if conversion isn't going to be possible, there is an output#supported_firmware method which returns the list of supported target_firmware. Add the target_firmware parameter to output#create_metadata so it can select the correct firmware in the final metadata. --- v2v/output_glance.ml | 7 ++++++- v2v/output_libvirt.ml | 30 ++++++++++++++++++++++++------ v2v/output_libvirt.mli | 2 +- v2v/output_local.ml | 6 ++++-- v2v/output_null.ml | 4 +++- v2v/output_qemu.ml | 28 +++++++++++++++++++++++++++- v2v/output_rhev.ml | 7 ++++++- v2v/output_vdsm.ml | 7 ++++++- v2v/types.ml | 9 ++++++++- v2v/types.mli | 9 ++++++++- v2v/utils.ml | 29 +++++++++++++++++++++++++++++ v2v/v2v.ml | 19 ++++++++++++++++++- v2v/virt-v2v.pod | 35 +++++++++++++++++++++++++++++++++++ 13 files changed, 175 insertions(+), 17 deletions(-) diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml index 9de90dc..4880151 100644 --- a/v2v/output_glance.ml +++ b/v2v/output_glance.ml @@ -40,6 +40,8 @@ object method as_options = "-o glance" + method supported_firmware = [ TargetBIOS ] + method prepare_targets source targets = (* This does nothing useful except to check that the user has * supplied all the correct auth environment variables to make @@ -60,7 +62,10 @@ object { t with target_file = target_file } ) targets - method create_metadata source targets guestcaps inspect = + method create_metadata source targets guestcaps inspect target_firmware = + (* See #supported_firmware above. *) + assert (target_firmware = TargetBIOS); + (* Upload the disk image (there should only be one - see above). *) let { target_file = target_file; target_format = target_format } = List.hd targets in diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml index 5be5b2c..0ed7a61 100644 --- a/v2v/output_libvirt.ml +++ b/v2v/output_libvirt.ml @@ -69,7 +69,8 @@ let target_features_of_capabilities_doc doc arch = !features ) -let create_libvirt_xml ?pool source targets guestcaps target_features = +let create_libvirt_xml ?pool source targets guestcaps + target_features target_firmware = let memory_k = source.s_memory /^ 1024L in (* We have the machine features of the guest when it was on the @@ -107,6 +108,23 @@ let create_libvirt_xml ?pool source targets guestcaps target_features = let features = List.sort compare (StringSet.elements features) in + (* The <os> section subelements. *) + let os_section = + let loader = + match target_firmware with + | TargetBIOS -> [] + | TargetUEFI -> + (* danpb is proposing that libvirt supports <loader type="efi"/>, + * (https://bugzilla.redhat.com/show_bug.cgi?id=1217444#c6) but + * until that day we have to use a bunch of heuristics. XXX + *) + let code, vars_template = find_uefi_firmware guestcaps.gcaps_arch in + [ e "loader" ["type", "pflash"] [ PCData code ]; + e "nvram" ["template", vars_template] [] ] in + + (e "type" ["arch", guestcaps.gcaps_arch] [PCData "hvm"]) :: loader in + + (* Disks. *) let disks = let block_prefix = match guestcaps.gcaps_block_bus with @@ -275,9 +293,7 @@ let create_libvirt_xml ?pool source targets guestcaps target_features = e "memory" ["unit", "KiB"] [PCData (Int64.to_string memory_k)]; e "currentMemory" ["unit", "KiB"] [PCData (Int64.to_string memory_k)]; e "vcpu" [] [PCData (string_of_int source.s_vcpu)]; - e "os" [] [ - e "type" ["arch", guestcaps.gcaps_arch] [PCData "hvm"]; - ]; + e "os" [] os_section; e "features" [] (List.map (fun s -> e s [] []) features); e "on_poweroff" [] [PCData "destroy"]; @@ -299,6 +315,8 @@ class output_libvirt verbose oc output_pool = object | None -> sprintf "-o libvirt -os %s" output_pool | Some uri -> sprintf "-o libvirt -oc %s -os %s" uri output_pool + method supported_firmware = [ TargetBIOS; TargetUEFI ] + method prepare_targets source targets = (* Get the capabilities from libvirt. *) let cmd = @@ -354,7 +372,7 @@ class output_libvirt verbose oc output_pool = object { t with target_file = target_file } ) targets - method create_metadata source targets guestcaps _ = + method create_metadata source targets guestcaps _ target_firmware = (* We copied directly into the final pool directory. However we * have to tell libvirt. *) @@ -379,7 +397,7 @@ class output_libvirt verbose oc output_pool = object (* Create the metadata. *) let doc = create_libvirt_xml ~pool:output_pool source targets - guestcaps target_features in + guestcaps target_features target_firmware in let tmpfile, chan = Filename.open_temp_file "v2vlibvirt" ".xml" in DOM.doc_to_chan chan doc; diff --git a/v2v/output_libvirt.mli b/v2v/output_libvirt.mli index e6c0cd6..6370912 100644 --- a/v2v/output_libvirt.mli +++ b/v2v/output_libvirt.mli @@ -23,5 +23,5 @@ val output_libvirt : bool -> string option -> string -> Types.output {!Types.output} object specialized for writing output to libvirt. *) -val create_libvirt_xml : ?pool:string -> Types.source -> Types.target list -> Types.guestcaps -> string list -> DOM.doc +val create_libvirt_xml : ?pool:string -> Types.source -> Types.target list -> Types.guestcaps -> string list -> Types.target_firmware -> DOM.doc (** This is called from {!Output_local} to generate the libvirt XML. *) diff --git a/v2v/output_local.ml b/v2v/output_local.ml index f1862db..3b10791 100644 --- a/v2v/output_local.ml +++ b/v2v/output_local.ml @@ -29,6 +29,8 @@ class output_local verbose dir = object method as_options = sprintf "-o local -os %s" dir + method supported_firmware = [ TargetBIOS; TargetUEFI ] + method prepare_targets source targets = List.map ( fun t -> @@ -36,7 +38,7 @@ class output_local verbose dir = object { t with target_file = target_file } ) targets - method create_metadata source targets guestcaps _ = + method create_metadata source targets guestcaps _ target_firmware = (* We don't know what target features the hypervisor supports, but * assume a common set that libvirt supports. *) @@ -48,7 +50,7 @@ class output_local verbose dir = object let doc = Output_libvirt.create_libvirt_xml source targets - guestcaps target_features in + guestcaps target_features target_firmware in let name = source.s_name in let file = dir // name ^ ".xml" in diff --git a/v2v/output_null.ml b/v2v/output_null.ml index 5c39d9a..de44615 100644 --- a/v2v/output_null.ml +++ b/v2v/output_null.ml @@ -39,6 +39,8 @@ object method as_options = "-o null" + method supported_firmware = [ TargetBIOS; TargetUEFI ] + method prepare_targets source targets = List.map ( fun t -> @@ -46,7 +48,7 @@ object { t with target_file = target_file } ) targets - method create_metadata _ _ _ _ = () + method create_metadata _ _ _ _ _ = () end let output_null = new output_null diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml index 3868b00..1d8dbdb 100644 --- a/v2v/output_qemu.ml +++ b/v2v/output_qemu.ml @@ -31,6 +31,8 @@ object method as_options = sprintf "-o qemu -os %s%s" dir (if qemu_boot then " --qemu-boot" else "") + method supported_firmware = [ TargetBIOS; TargetUEFI ] + method prepare_targets source targets = List.map ( fun t -> @@ -38,20 +40,44 @@ object { t with target_file = target_file } ) targets - method create_metadata source targets guestcaps inspect = + method create_metadata source targets guestcaps inspect target_firmware = let name = source.s_name in let file = dir // name ^ ".sh" in + let uefi_firmware = + match target_firmware with + | TargetBIOS -> None + | TargetUEFI -> + Some (find_uefi_firmware guestcaps.gcaps_arch) in + let chan = open_out file in let fpf fs = fprintf chan fs in let nl = " \\\n\t" in fpf "#!/bin/sh -\n"; fpf "\n"; + + (match uefi_firmware with + | None -> () + | Some (_, vars_template) -> + fpf "# Make a copy of the UEFI variables template\n"; + fpf "uefi_vars=\"$(mktemp)\"\n"; + fpf "cp %s \"$uefi_vars\"\n" (quote vars_template); + fpf "\n" + ); + fpf "qemu-system-%s" guestcaps.gcaps_arch; fpf "%s-no-user-config -nodefaults" nl; fpf "%s-name %s" nl (quote source.s_name); fpf "%s-machine accel=kvm:tcg" nl; + + (match uefi_firmware with + | None -> () + | Some (code, _) -> + fpf "%s-drive if=pflash,format=raw,file=%s,readonly" nl (quote code); + fpf "%s-drive if=pflash,format=raw,file=\"$uefi_vars\"" nl + ); + fpf "%s-m %Ld" nl (source.s_memory /^ 1024L /^ 1024L); if source.s_vcpu > 1 then fpf "%s-smp %d" nl source.s_vcpu; diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml index 06a2f1b..150a7bd 100644 --- a/v2v/output_rhev.ml +++ b/v2v/output_rhev.ml @@ -122,6 +122,8 @@ object | Some Server -> " --vmtype server" | Some Desktop -> " --vmtype desktop") + method supported_firmware = [ TargetBIOS ] + (* RHEV doesn't support serial consoles. This causes the conversion * step to remove it. *) @@ -276,7 +278,10 @@ object ) (* This is called after conversion to write the OVF metadata. *) - method create_metadata source targets guestcaps inspect = + method create_metadata source targets guestcaps inspect target_firmware = + (* See #supported_firmware above. *) + assert (target_firmware = TargetBIOS); + (* Create the metadata. *) let ovf = OVF.create_ovf verbose source targets guestcaps inspect output_alloc vmtype esd_uuid image_uuids vol_uuids vm_uuid in diff --git a/v2v/output_vdsm.ml b/v2v/output_vdsm.ml index 3869696..aa56e23 100644 --- a/v2v/output_vdsm.ml +++ b/v2v/output_vdsm.ml @@ -50,6 +50,8 @@ object | Some Server -> " --vmtype server" | Some Desktop -> " --vmtype desktop") + method supported_firmware = [ TargetBIOS ] + (* RHEV doesn't support serial consoles. This causes the conversion * step to remove it. *) @@ -163,7 +165,10 @@ object ?clustersize path format size (* This is called after conversion to write the OVF metadata. *) - method create_metadata source targets guestcaps inspect = + method create_metadata source targets guestcaps inspect target_firmware = + (* See #supported_firmware above. *) + assert (target_firmware = TargetBIOS); + (* Create the metadata. *) let ovf = OVF.create_ovf verbose source targets guestcaps inspect output_alloc vmtype dd_uuid diff --git a/v2v/types.ml b/v2v/types.ml index 2817557..e241d02 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -261,6 +261,12 @@ target_overlay.ov_source = %s t.target_overlay.ov_overlay_file t.target_overlay.ov_source.s_qemu_uri +type target_firmware = TargetBIOS | TargetUEFI + +let string_of_target_firmware = function + | TargetBIOS -> "bios" + | TargetUEFI -> "uefi" + type inspect = { i_root : string; i_type : string; @@ -350,9 +356,10 @@ end class virtual output verbose = object method virtual as_options : string method virtual prepare_targets : source -> target list -> target list + method virtual supported_firmware : target_firmware list method check_target_free_space (_ : source) (_ : target list) = () method disk_create = (new Guestfs.guestfs ())#disk_create - method virtual create_metadata : source -> target list -> guestcaps -> inspect -> unit + method virtual create_metadata : source -> target list -> guestcaps -> inspect -> target_firmware -> unit method keep_serial_console = true end diff --git a/v2v/types.mli b/v2v/types.mli index b96ef8a..e587850 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -147,6 +147,10 @@ type target = { val string_of_target : target -> string +type target_firmware = TargetBIOS | TargetUEFI + +val string_of_target_firmware : target_firmware -> string + type inspect = { i_root : string; (** Root device. *) i_type : string; (** Usual inspection fields. *) @@ -209,10 +213,13 @@ class virtual output : bool -> object This is just used for pretty-printing log messages. *) method virtual prepare_targets : source -> target list -> target list (** Called before conversion to prepare the output. *) + method virtual supported_firmware : target_firmware list + (** Does this output method support UEFI? Allows us to abort early if + conversion is impossible. *) method check_target_free_space : source -> target list -> unit (** Called before conversion. Can be used to check there is enough space on the target, using the [target.target_estimated_size] field. *) - method virtual create_metadata : source -> target list -> guestcaps -> inspect -> unit + method virtual create_metadata : source -> target list -> guestcaps -> inspect -> target_firmware -> unit (** Called after conversion to finish off and create metadata. *) method disk_create : ?backingfile:string -> ?backingformat:string -> ?preallocation:string -> ?compat:string -> ?clustersize:int -> string -> string -> int64 -> unit (** Called in order to create disks on the target. The method has the diff --git a/v2v/utils.ml b/v2v/utils.ml index 1cc7e76..ad92392 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -85,6 +85,35 @@ let qemu_supports_sound_card = function | USBAudio -> true +(* Find the UEFI firmware. *) +let find_uefi_firmware guest_arch = + let files = + match guest_arch with + | "i386" | "i486" | "i586" | "i686" -> + [ "/usr/share/edk2.git/ovmf-ia32/OVMF_CODE-pure-efi.fd", + "/usr/share/edk2.git/ovmf-ia32/OVMF_VARS-pure-efi.fd" ] + | "x86_64" -> + [ "/usr/share/OVMF/OVMF_CODE.fd", + "/usr/share/OVMF/OVMF_VARS.fd"; + "/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd", + "/usr/share/edk2.git/ovmf-x64/OVMF_VARS-pure-efi.fd" ] + | "aarch64" -> + [ "/usr/share/AAVMF/AAVMF_CODE.fd", + "/usr/share/AAVMF/AAVMF_VARS.fd"; + "/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw", + "/usr/share/edk2.git/aarch64/vars-template-pflash.raw" ] + | arch -> + error (f_"don't know how to convert UEFI guests for architecture %s") + guest_arch in + let rec loop = function + | [] -> + error (f_"cannot find firmware for UEFI guests.\n\nYou probably need to install OVMF, or Gerd's firmware repo (https://www.kraxel.org/repos/), or AAVMF (if using aarch64)") + | ((code, vars_template) as ret) :: rest -> + if Sys.file_exists code && Sys.file_exists vars_template then ret + else loop rest + in + loop files + let compare_app2_versions app1 app2 = let i = compare app1.Guestfs.app2_epoch app2.Guestfs.app2_epoch in if i <> 0 then i diff --git a/v2v/v2v.ml b/v2v/v2v.ml index 10aff9c..bee626c 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -224,6 +224,23 @@ let rec main () = msg (f_"Inspecting the overlay"); let inspect = inspect_source ~verbose g root_choice in + (* Does the guest require UEFI on the target? *) + let target_firmware = + match source.s_firmware with + | BIOS -> TargetBIOS + | UEFI -> TargetUEFI + | UnknownFirmware -> + if inspect.i_uefi then TargetUEFI else TargetBIOS in + let supported_firmware = output#supported_firmware in + if not (List.mem target_firmware supported_firmware) then + error (f_"this guest cannot run on the target, because the target does not support %s firmware (supported firmware on target: %s)") + (string_of_target_firmware target_firmware) + (String.concat " " + (List.map string_of_target_firmware supported_firmware)); + (match target_firmware with + | TargetBIOS -> () + | TargetUEFI -> info (f_"This guest requires UEFI on the target to boot.")); + (* The guest free disk space check and the target free space * estimation both require statvfs information from mountpoints, so * get that information first. @@ -417,7 +434,7 @@ let rec main () = (* Create output metadata. *) msg (f_"Creating output metadata"); - output#create_metadata source targets guestcaps inspect; + output#create_metadata source targets guestcaps inspect target_firmware; (* Save overlays if --debug-overlays option was used. *) if debug_overlays then ( diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod index fad3c1d..82a15ea 100644 --- a/v2v/virt-v2v.pod +++ b/v2v/virt-v2v.pod @@ -231,6 +231,10 @@ guests. =back +=head2 Guest firmware + +BIOS or UEFI for all guest types (but see L</UEFI> below). + =head1 OPTIONS =over 4 @@ -799,6 +803,37 @@ loaded. =back +=head1 UEFI + +VMware allows you to present UEFI firmware to guests (instead of the +ordinary PC BIOS). Virt-v2v can convert these guests, but requires +that UEFI is supported by the target hypervisor. + +Currently KVM supports OVMF, a partially open source UEFI firmware, +and can run these guests. + +Since OVMF support was only recently added to KVM (in 2014/2015), not +all target environments support UEFI guests yet: + +=over 4 + +=item UEFI on libvirt, qemu + +Supported. Virt-v2v will generate the correct libvirt XML (metadata) +automatically, but note that the same version of OVMF must be +installed on the conversion host as is installed on the target +hypervisor, else you will have to adjust paths in the metadata. + +=item UEFI on OpenStack + +Not supported. + +=item UEFI on RHEV + +Not supported. + +=back + =head1 NETWORKS AND BRIDGES Guests are usually connected to one or more networks, and when -- 2.3.1
--- v2v/convert_linux.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml index 61a6a2a..a24a7fa 100644 --- a/v2v/convert_linux.ml +++ b/v2v/convert_linux.ml @@ -91,14 +91,20 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source = (* What grub is installed? *) let grub_config, grub = + let locations = [ + "/boot/grub2/grub.cfg", `Grub2; + "/boot/grub/menu.lst", `Grub1; + "/boot/grub/grub.conf", `Grub1; + ] in + let locations = + if inspect.i_uefi then + ("/boot/efi/EFI/redhat/grub.cfg", `Grub2) :: locations + else + locations in try List.find ( fun (grub_config, _) -> g#is_file ~followsymlinks:true grub_config - ) [ - "/boot/grub2/grub.cfg", `Grub2; - "/boot/grub/menu.lst", `Grub1; - "/boot/grub/grub.conf", `Grub1; - ] + ) locations with Not_found -> error (f_"no grub1/grub-legacy or grub2 configuration file was found") in -- 2.3.1
participants (1)
-
Richard W.M. Jones