[Libguestfs] [PATCH 3/6] v2v: efi: Detect if the guest could boot with UEFI.

Richard W.M. Jones rjones at redhat.com
Thu Apr 30 16:28:35 UTC 2015


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




More information about the Libguestfs mailing list