[Libguestfs] [PATCH v2] v2v: fix UEFI bootloader for linux guests

Richard W.M. Jones rjones at redhat.com
Fri Jul 24 14:20:06 UTC 2020


On Fri, Jul 24, 2020 at 03:36:58PM +0300, Denis Plotnikov wrote:
> v2:
>   Rich, I hope I've done all modifications according to your comments, namely:
>     * moved the code from linux_bootloaders to convert_linux
>     * made minor code modifications 

Thanks - I pushed it.

I squashed in some changes which are stylistic only (hopefully - I
hope I correctly understood what the "contains" function was doing).

The diff versus your patch is attached.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
-------------- next part --------------
>From b75ffe4552147b048397af579ba447ad7d5e04ba Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Fri, 24 Jul 2020 15:14:07 +0100
Subject: [PATCH] UPDATE

---
 v2v/convert_linux.ml | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 9115b9fbcf..a871d754f4 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1105,20 +1105,12 @@ let convert (g : G.guestfs) inspect source_disks output rcaps _ =
        The following code tries to make an uefi fallback path for
        a uefi linux vm.
     *)
-    match inspect.i_firmware with
-    | I_UEFI _ -> (
+    (match inspect.i_firmware with
+    | I_BIOS -> ()
+    | I_UEFI _ ->
       (* Standard uefi fallback path *)
       let uefi_fallback_path = "/boot/efi/EFI/BOOT/" in
 
-      (* Helper function checks if 'source' contains 's' *)
-      let contains source s = (
-        let re = Str.regexp_string s in
-        try
-          ignore (Str.search_forward re source 0);
-          true
-        with Not_found -> false
-      ) in
-
       let cant_fix_uefi () =
         info (f_"Can't fix UEFI bootloader. VM may not boot.")
       in
@@ -1199,7 +1191,7 @@ rm -rf %s" uefi_fallback_path in
                  * if not, then just don't clean up and leave the temp loader
                  * at UEFI fallback path for simplicity
                  *)
-                if contains shim "/boot/efi/EFI/ubuntu/shim" then
+                if String.find shim "/boot/efi/EFI/ubuntu/shim" >= 0 then
                   let fix_script = sprintf
 "#!/bin/bash
 sudo efibootmgr -c -L ubuntu -l \\\\EFI\\\\ubuntu\\\\shim%s.efi
@@ -1207,7 +1199,8 @@ rm -rf %s" arch_suffix uefi_fallback_path in
                   Firstboot.add_firstboot_script
                     g inspect.i_root "fix uefi boot" fix_script
                 else
-                  ())
+                  ()
+              )
               else
                 cant_fix_uefi ()
           | _, _ ->
@@ -1216,8 +1209,7 @@ rm -rf %s" arch_suffix uefi_fallback_path in
             cant_fix_uefi ()
         )
       )
-    )
-    | I_BIOS -> ();
+    ); (* inspect.i_firmware == I_UEFI *)
 
     (* Delete blkid caches if they exist, since they will refer to the old
      * device names.  blkid will rebuild these on demand.
-- 
2.26.2



More information about the Libguestfs mailing list