[PATCH] v2v: bootloaders: search grub config for all distributions
This patch improves the search of grub config on EFI partition. This means that the config will be found not only for rhel but also for many other distributions. Tests were performed on the following distributions: centos, fedora, ubuntu, suse. In all cases, the config path was /boot/efi/EFI/*distname*/grub.cfg The main purpose of the patch is to improve support for converting of vm with UEFI for most distributions. Unfortunately this patch does not solve the problem for all distributions, for example Debian does not store grub config on the EFI partition, therefore for such distributions another solution is necessary. Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> --- v2v/linux_bootloaders.ml | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml index cad72a829..33a6dc4e9 100644 --- a/v2v/linux_bootloaders.ml +++ b/v2v/linux_bootloaders.ml @@ -49,6 +49,13 @@ let remove_hd_prefix path = (* Grub1 (AKA grub-legacy) representation. *) class bootloader_grub1 (g : G.guestfs) inspect grub_config = + let () = + (* Apply the "grub" lens if it is not handling the file + * already -- Augeas < 1.7.0 will error out otherwise. + *) + if g#aug_ls ("/files" ^ grub_config) = [||] then + g#aug_transform "grub" grub_config in + (* Grub prefix? Usually "/boot". *) let grub_prefix = let mounts = g#inspect_get_mountpoints inspect.i_root in @@ -335,33 +342,46 @@ object (self) end let detect_bootloader (g : G.guestfs) inspect = - let config_file, typ = - let locations = [ - "/boot/grub2/grub.cfg", Grub2; - "/boot/grub/grub.cfg", Grub2; - "/boot/grub/menu.lst", Grub1; - "/boot/grub/grub.conf", Grub1; - ] in - let locations = - match inspect.i_firmware with - | I_UEFI _ -> - [ - "/boot/efi/EFI/redhat/grub.cfg", Grub2; - "/boot/efi/EFI/redhat/grub.conf", Grub1; - ] @ locations - | I_BIOS -> locations in - try - List.find ( - fun (config_file, _) -> g#is_file ~followsymlinks:true config_file - ) locations - with - Not_found -> - error (f_"no bootloader detected") in - - match typ with - | Grub1 -> - if config_file = "/boot/efi/EFI/redhat/grub.conf" then - g#aug_transform "grub" "/boot/efi/EFI/redhat/grub.conf"; - - new bootloader_grub1 g inspect config_file - | Grub2 -> new bootloader_grub2 g config_file + (* Where to start searching for bootloaders. *) + let mp = + match inspect.i_firmware with + | I_BIOS -> "/boot" + | I_UEFI _ -> "/boot/efi/EFI" in + + (* Find all paths below the mountpoint, then filter them to find + * the grub config file. + *) + let paths = + try List.map ((^) mp) (Array.to_list (g#find mp)) + with G.Error msg -> + error (f_"could not find bootloader mount point (%s): %s") mp msg in + + (* We can determine if the bootloader config file is grub 1 or + * grub 2 just by looking at the filename. + *) + let bootloader_type_of_filename path = + match last_part_of path '/' with + | Some "grub.cfg" -> Some Grub2 + | Some ("grub.conf" | "menu.lst") -> Some Grub1 + | Some _ + | None -> None + in + + let grub_config, typ = + let rec loop = function + | [] -> error (f_"no bootloader detected") + | path :: paths -> + match bootloader_type_of_filename path with + | None -> loop paths + | Some typ -> + if not (g#is_file ~followsymlinks:true path) then loop paths + else path, typ + in + loop paths in + + let bl = + (match typ with + | Grub1 -> new bootloader_grub1 g inspect grub_config + | Grub2 -> new bootloader_grub2 g grub_config) in + debug "detected bootloader %s at %s" bl#name grub_config; + bl -- 2.11.0
On Tue, May 02, 2017 at 03:35:06PM +0300, Pavel Butsykin wrote:
This patch improves the search of grub config on EFI partition. This means that the config will be found not only for rhel but also for many other distributions. Tests were performed on the following distributions: centos, fedora, ubuntu, suse. In all cases, the config path was /boot/efi/EFI/*distname*/grub.cfg
The main purpose of the patch is to improve support for converting of vm with UEFI for most distributions. Unfortunately this patch does not solve the problem for all distributions, for example Debian does not store grub config on the EFI partition, therefore for such distributions another solution is necessary.
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Thanks - this is pushed. Sorry it took a bit of time, I had to run all of the virt-v2v non-free test cases to convince myself there were no corner cases that might regress. They passed fine. 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
On 03.05.2017 12:57, Richard W.M. Jones wrote:
On Tue, May 02, 2017 at 03:35:06PM +0300, Pavel Butsykin wrote:
This patch improves the search of grub config on EFI partition. This means that the config will be found not only for rhel but also for many other distributions. Tests were performed on the following distributions: centos, fedora, ubuntu, suse. In all cases, the config path was /boot/efi/EFI/*distname*/grub.cfg
The main purpose of the patch is to improve support for converting of vm with UEFI for most distributions. Unfortunately this patch does not solve the problem for all distributions, for example Debian does not store grub config on the EFI partition, therefore for such distributions another solution is necessary.
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Thanks - this is pushed.
Sorry it took a bit of time, I had to run all of the virt-v2v non-free test cases to convince myself there were no corner cases that might regress. They passed fine.
Thank you for the extra check, it's always helpful! What are "non-free test cases" ? Is it something in addition to " v2v]# make check && make check-slow" ?
Rich.
On Thu, May 04, 2017 at 02:21:59PM +0300, Pavel Butsykin wrote:
On 03.05.2017 12:57, Richard W.M. Jones wrote:
On Tue, May 02, 2017 at 03:35:06PM +0300, Pavel Butsykin wrote:
This patch improves the search of grub config on EFI partition. This means that the config will be found not only for rhel but also for many other distributions. Tests were performed on the following distributions: centos, fedora, ubuntu, suse. In all cases, the config path was /boot/efi/EFI/*distname*/grub.cfg
The main purpose of the patch is to improve support for converting of vm with UEFI for most distributions. Unfortunately this patch does not solve the problem for all distributions, for example Debian does not store grub config on the EFI partition, therefore for such distributions another solution is necessary.
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Thanks - this is pushed.
Sorry it took a bit of time, I had to run all of the virt-v2v non-free test cases to convince myself there were no corner cases that might regress. They passed fine.
Thank you for the extra check, it's always helpful!
What are "non-free test cases" ? Is it something in addition to " v2v]# make check && make check-slow" ?
Unfortunately they are non-free (and hence not (re-)distributable), as the name suggests. However you can look at the framework here: http://git.annexia.org/?p=virt-v2v-test-cases-nonfree.git;a=summary Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (2)
-
Pavel Butsykin -
Richard W.M. Jones