Tomáš Golembiovský
2016-Sep-12 11:20 UTC
[Libguestfs] [PATCH 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 | 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 + 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 + ) 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 -- 2.9.3
Pino Toscano
2016-Sep-12 11:31 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
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@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_cmdI'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 _ -> falseis_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) inspectLGTM otherwise. -- Pino Toscano
Richard W.M. Jones
2016-Sep-12 14:02 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
On Mon, Sep 12, 2016 at 01:31:05PM +0200, Pino Toscano wrote:> > + 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")Once you've made the change that Pino suggests, the code can be refactored a bit more using currying: 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)") Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Seemingly Similar Threads
- [PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
- [PATCH v3 2/2] v2v: ilnux: detect name of grub2-mkconfig
- [PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
- Re: [PATCH 2/2] v2v: ilnux: detect name of grub2-mkconfig
- [PATCH] v2v: fix UEFI bootloader for linux guests