On Debian family of OSes Grub2 tools are prefixed with 'grub-', not with
'grub2-'. We have to detect the correct name of the tool to use it.

Signed-off-by: Tomáš Golembiovský <[email protected]>
---
 v2v/convert_linux.ml | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 103728b..1f5f12c 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -109,6 +109,23 @@ let rec convert ~keep_serial_console (g : G.guestfs) 
inspect source rcaps =
       Not_found ->
         error (f_"no grub1/grub-legacy or grub2 configuration file was found") 
in
 
+  let grub2_mkconfig_cmd =
+    if grub = `Grub2 then
+      try
+        (* Red Hat and Suse families *)
+        ignore (g#command [| "grub2-mkconfig"; "--version" |]);
+        "grub2-mkconfig"
+      with G.Error _ ->
+        try
+          (* Debian family *)
+          ignore (g#command [| "grub-mkconfig"; "--version" |]);
+          "grub-mkconfig"
+        with G.Error _ ->
+          error (f_"failed to find grub2-mkconfig binary (but Grub2 was 
detected on guest)")
+    else
+      ""
+  in
+
   (* Grub prefix?  Usually "/boot". *)
   let grub_prefix =
     match grub with
@@ -1109,7 +1126,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) 
inspect source rcaps =
         g#aug_save ();
 
         try
-          ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
+          ignore (g#command [| grub2_mkconfig_cmd; "-o"; grub_config |])
         with
           G.Error msg ->
             warning (f_"could not rebuild grub2 configuration file (%s).  This 
may mean that grub output will not be sent to the serial port, but otherwise 
should be harmless.  Original error message: %s")
@@ -1431,7 +1448,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) 
inspect source rcaps =
 
       (* If it's grub2, we have to regenerate the config files. *)
       if grub = `Grub2 then
-        ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |]);
+        ignore (g#command [| grub2_mkconfig_cmd; "-o"; grub_config |]);
 
       Linux.augeas_reload g
     );
-- 
2.9.2


_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to