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

Pino Toscano ptoscano at redhat.com
Mon Sep 12 11:31:05 UTC 2016


On Monday, 12 September 2016 13:20:47 CEST Tomáš Golembiovský wrote:
> 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 at redhat.com>
> ---
>  v2v/linux_bootloaders.ml | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml
> index a5e4c8d..0729f17 100644
> --- a/v2v/linux_bootloaders.ml
> +++ b/v2v/linux_bootloaders.ml
> @@ -189,6 +189,22 @@ class bootloader_grub2 (g : G.guestfs) grub_config =
>  object (self)
>    inherit bootloader
>  
> +  method private grub2_mkconfig_cmd =

I'd make it a simple attribute of the object, just like grub_prefix in
class bootloader_grub1.

> +    let elems = [
> +       "/sbin/grub2-mkconfig";
> +       "/usr/sbin/grub2-mkconfig";
> +       "/sbin/grub-mkconfig"
> +       "/usr/sbin/grub-mkconfig"
> +      ] in
> +    try
> +      List.find (
> +        let e ->
> +          try g#is_file ~followsymlinks:true e
> +          with G.Error _ -> false

is_file returns false if a file does not exist, so there is no need to
catch the error (this currently swallows other errors than "does not
exist")

> +      ) elems
> +    with Not_found ->
> +      error (f_"failed to find grub2-mkconfig binary (but Grub2 was detected on guest)")
> +
>    method private grub2_update_console ~remove () =
>      let rex = Str.regexp "\\(.*\\)\\bconsole=[xh]vc0\\b\\(.*\\)" in
>  
> @@ -218,7 +234,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 +306,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 =

LGTM otherwise.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20160912/95640ded/attachment.sig>


More information about the Libguestfs mailing list