Pino Toscano
2016-Oct-03 09:43 UTC
[Libguestfs] [PATCH v2 0/3] v2v: further bits of Debian/Ubuntu guests supports
Hi, this series adds a couple bits more in v2v to convert Debian/Ubuntu (and derived) guests. The series does not complete the support (see known issues below), but all the patches here should be fit for review and inclusion. The series does not enable the conversion, yet. Known issues: * currently tested with simple local guest images, hence needs testing with real guests on libvirt/VMware/Xen/VirtualBox/etc (which have various tools to be removed/tweaked) * is tweaking the "enterprise-linux" module the correct/wanted way? should it be renamed to just "linux" then? * surely something else I'm missing Changes in v2: - dropped former patch #1, merged - reorder former patch #3 as #1 - add kernel config file detection as patch #2 - adapt patch #3 to use the found config file, if available Thanks, Pino Toscano (3): v2v: bootloaders: improve detection of Grub2 default method v2v: linux kernels: detect config file v2v: linux: check also kernel config for modules v2v/linux_bootloaders.ml | 61 ++++++++++++++++++++++++++++++++++-------------- v2v/linux_kernels.ml | 31 ++++++++++++++++++++++-- v2v/linux_kernels.mli | 1 + 3 files changed, 74 insertions(+), 19 deletions(-) -- 2.7.4
Pino Toscano
2016-Oct-03 09:43 UTC
[Libguestfs] [PATCH v2 1/3] v2v: bootloaders: improve detection of Grub2 default method
Detect only once which method must be used to get and set the default Grub2 kernel in the guest: this avoids the same checks in list_kernels and set_default_kernel. Also, add a "no method" option as well: Debian/Ubuntu guests do not have neither grubby nor Perl's Bootloader::Tools, so there is no way to know what is the default kernel, nor to change it. In this case, add a warning about this situation. --- v2v/linux_bootloaders.ml | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/v2v/linux_bootloaders.ml b/v2v/linux_bootloaders.ml index 4f53f87..e03d22b 100644 --- a/v2v/linux_bootloaders.ml +++ b/v2v/linux_bootloaders.ml @@ -184,6 +184,12 @@ object g#aug_save () end +(** The method used to get and set the default kernel in Grub2. *) +type default_kernel_method + | MethodGrubby (** Use the 'grubby' tool. *) + | MethodPerlBootloader (** Use the 'Bootloader::Tools' Perl module. *) + | MethodNone (** No known way. *) + (* Grub2 representation. *) class bootloader_grub2 (g : G.guestfs) grub_config @@ -199,6 +205,20 @@ class bootloader_grub2 (g : G.guestfs) grub_config error (f_"failed to find grub2-mkconfig binary (but Grub2 was detected on guest)") in + let get_default_method + let has_perl_bootloader () + try + ignore (g#command [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e1" |]); + true + with G.Error _ -> false + in + if g#exists "/sbin/grubby" then MethodGrubby + else if has_perl_bootloader () then MethodPerlBootloader + else ( + warning (f_"could not determine a way to update the configuration of Grub2"); + MethodNone + ) in + object (self) inherit bootloader @@ -250,18 +270,23 @@ object (self) method list_kernels let get_default_image () - let cmd - if g#exists "/sbin/grubby" then - [| "grubby"; "--default-kernel" |] - else - [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; " - InitLibrary(); - my $default = Bootloader::Tools::GetDefaultSection(); - print $default->{image}; - " |] in - match g#command cmd with - | "" -> None - | k -> + let res + match get_default_method with + | MethodGrubby -> + Some (g#command [| "grubby"; "--default-kernel" |]) + | MethodPerlBootloader -> + let cmd + [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; " + InitLibrary(); + my $default = Bootloader::Tools::GetDefaultSection(); + print $default->{image}; + " |] in + Some (g#command cmd) + | MethodNone -> + None in + match res with + | None -> None + | Some k -> let len = String.length k in let k if len > 0 && k.[len-1] = '\n' then @@ -285,10 +310,11 @@ object (self) vmlinuzes method set_default_kernel vmlinuz - let cmd - if g#exists "/sbin/grubby" then - [| "grubby"; "--set-default"; vmlinuz |] - else + match get_default_method with + | MethodGrubby -> + ignore (g#command [| "grubby"; "--set-default"; vmlinuz |]) + | MethodPerlBootloader -> + let cmd [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; sprintf " InitLibrary(); my @sections = GetSectionList(type=>image, image=>\"%s\"); @@ -296,7 +322,8 @@ object (self) my $newdefault = $section->{name}; SetGlobals(default, \"$newdefault\"); " vmlinuz |] in - ignore (g#command cmd) + ignore (g#command cmd) + | MethodNone -> () method configure_console = self#grub2_update_console ~remove:false -- 2.7.4
Pino Toscano
2016-Oct-03 09:44 UTC
[Libguestfs] [PATCH v2 2/3] v2v: linux kernels: detect config file
Add a simple detection for the config file of each kernel, so that can be used later to get more information on what a kernel provides. --- v2v/linux_kernels.ml | 10 +++++++++- v2v/linux_kernels.mli | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml index b292921..df093d0 100644 --- a/v2v/linux_kernels.ml +++ b/v2v/linux_kernels.ml @@ -41,12 +41,14 @@ type kernel_info = { ki_supports_virtio : bool; ki_is_xen_kernel : bool; ki_is_debug : bool; + ki_config_file : string option; } let string_of_kernel_info ki - sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)" + sprintf "(%s, %s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)" ki.ki_name ki.ki_version ki.ki_arch ki.ki_vmlinuz (match ki.ki_initrd with None -> "None" | Some f -> f) + (match ki.ki_config_file with None -> "None" | Some f -> f) ki.ki_supports_virtio ki.ki_is_xen_kernel ki.ki_is_debug let detect_kernels (g : G.guestfs) inspect family bootloader @@ -156,6 +158,11 @@ let detect_kernels (g : G.guestfs) inspect family bootloader ) modules in assert (List.length modules > 0); + let config_file + let cfg = "/boot/config-" ^ version in + if List.mem cfg files then Some cfg + else None in + let supports_virtio = List.mem "virtio_net" modules in let is_xen_kernel = List.mem "xennet" modules in @@ -179,6 +186,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader ki_supports_virtio = supports_virtio; ki_is_xen_kernel = is_xen_kernel; ki_is_debug = is_debug; + ki_config_file = config_file; } ) diff --git a/v2v/linux_kernels.mli b/v2v/linux_kernels.mli index 453ce67..c01adeb 100644 --- a/v2v/linux_kernels.mli +++ b/v2v/linux_kernels.mli @@ -31,6 +31,7 @@ type kernel_info = { ki_supports_virtio : bool; (** Kernel has virtio drivers? *) ki_is_xen_kernel : bool; (** Is a Xen paravirt kernel? *) ki_is_debug : bool; (** Is debug kernel? *) + ki_config_file : string option; (** Path of config file, if found. *) } (** Kernel information. *) -- 2.7.4
Pino Toscano
2016-Oct-03 09:44 UTC
[Libguestfs] [PATCH v2 3/3] v2v: linux: check also kernel config for modules
When checking whether a kernel supports virtio or it is Xen-based, it is assumed that the feature has the kernel module for it; this will fail if the feature is built-in in the kernel, misrepresenting it. The solution is to check the kernel configuration whether the feature is built-in, in case there is no module available. This fixes the virtio detection on Ubuntu kernels, where virtio is built in and not as module. --- v2v/linux_kernels.ml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml index df093d0..f15e82a 100644 --- a/v2v/linux_kernels.ml +++ b/v2v/linux_kernels.ml @@ -55,6 +55,21 @@ let detect_kernels (g : G.guestfs) inspect family bootloader (* What kernel/kernel-like packages are installed on the current guest? *) let installed_kernels : kernel_info list let rex_ko = Str.regexp ".*\\.k?o\\(\\.xz\\)?$" in + let check_config version feature = function + | None -> false + | Some config -> + let prefix = "^CONFIG_" ^ String.uppercase_ascii feature ^ "=" in + let lines = g#grep ~extended:true prefix config in + let lines = Array.to_list lines in + match lines with + | [] -> false + | line :: _ -> + let kind = snd (String.split "=" line) in + (match kind with + | "m" | "y" -> true + | _ -> false + ) + in let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in let rex_initrd if family = `Debian_family then @@ -163,7 +178,11 @@ let detect_kernels (g : G.guestfs) inspect family bootloader if List.mem cfg files then Some cfg else None in - let supports_virtio = List.mem "virtio_net" modules in + let kernel_supports what kconf + List.mem what modules + || check_config version kconf config_file in + + let supports_virtio = kernel_supports "virtio_net" "VIRTIO_NET" in let is_xen_kernel = List.mem "xennet" modules in (* If the package name is like "kernel-debug", then it's -- 2.7.4
Richard W.M. Jones
2016-Oct-03 12:28 UTC
Re: [Libguestfs] [PATCH v2 3/3] v2v: linux: check also kernel config for modules
On Mon, Oct 03, 2016 at 11:44:01AM +0200, Pino Toscano wrote:> When checking whether a kernel supports virtio or it is Xen-based, it is > assumed that the feature has the kernel module for it; this will fail if > the feature is built-in in the kernel, misrepresenting it. > > The solution is to check the kernel configuration whether the feature > is built-in, in case there is no module available. > > This fixes the virtio detection on Ubuntu kernels, where virtio is > built in and not as module. > --- > v2v/linux_kernels.ml | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > > diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml > index df093d0..f15e82a 100644 > --- a/v2v/linux_kernels.ml > +++ b/v2v/linux_kernels.ml > @@ -55,6 +55,21 @@ let detect_kernels (g : G.guestfs) inspect family bootloader > (* What kernel/kernel-like packages are installed on the current guest? *) > let installed_kernels : kernel_info list > let rex_ko = Str.regexp ".*\\.k?o\\(\\.xz\\)?$" in > + let check_config version feature = function > + | None -> false > + | Some config -> > + let prefix = "^CONFIG_" ^ String.uppercase_ascii feature ^ "=" in > + let lines = g#grep ~extended:true prefix config in > + let lines = Array.to_list lines in > + match lines with > + | [] -> false > + | line :: _ -> > + let kind = snd (String.split "=" line) in > + (match kind with > + | "m" | "y" -> true > + | _ -> false > + ) > + in > let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in > let rex_initrd > if family = `Debian_family then > @@ -163,7 +178,11 @@ let detect_kernels (g : G.guestfs) inspect family bootloader > if List.mem cfg files then Some cfg > else None in > > - let supports_virtio = List.mem "virtio_net" modules in > + let kernel_supports what kconf > + List.mem what modules > + || check_config version kconf config_file in > + > + let supports_virtio = kernel_supports "virtio_net" "VIRTIO_NET" in > let is_xen_kernel = List.mem "xennet" modules in > > (* If the package name is like "kernel-debug", then it's > --ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Apparently Analagous Threads
- [PATCH 0/3] v2v: further bits of Debian/Ubuntu guests supports
- [PATCH v2 0/8] v2v: Add drivers for virtio-rng, balloon, pvpanic.
- [PATCH v3 0/8] v2v: Add drivers for virtio-rng, balloon, pvpanic.
- [PATCH v4 0/9] v2v: Add drivers for virtio-rng, balloon, pvpanic.
- [PATCH 0/6] v2v: Add drivers for virtio-rng, balloon, pvpanic.