[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v3 2/2] v2v: ilnux: detect name of grub2-mkconfig



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ý <tgolembi redhat com>
---
 v2v/linux_bootloaders.ml | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
index a5e4c8d..4f53f87 100644
--- a/v2v/linux_bootloaders.ml
+++ b/v2v/linux_bootloaders.ml
@@ -186,6 +186,19 @@ end
 
 (* Grub2 representation. *)
 class bootloader_grub2 (g : G.guestfs) grub_config =
+
+  let grub2_mkconfig_cmd =
+    let elems = [
+       "/sbin/grub2-mkconfig";
+       "/usr/sbin/grub2-mkconfig";
+       "/sbin/grub-mkconfig";
+       "/usr/sbin/grub-mkconfig"
+      ] in
+    try List.find (g#is_file ~followsymlinks:true) elems
+    with Not_found ->
+      error (f_"failed to find grub2-mkconfig binary (but Grub2 was detected on guest)")
+  in
+
 object (self)
   inherit bootloader
 
@@ -218,7 +231,7 @@ object (self)
         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")
@@ -290,7 +303,7 @@ object (self)
   method remove_console = self#grub2_update_console ~remove:true
 
   method update () =
-    ignore (g#command [| "grub2-mkconfig"; "-o"; grub_config |])
+    ignore (g#command [| grub2_mkconfig_cmd; "-o"; grub_config |])
 end
 
 let detect_bootloader (g : G.guestfs) inspect =
-- 
2.9.3



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]