Pino Toscano
2018-May-21 12:56 UTC
[Libguestfs] [PATCH] v2v: linux: fix kernel detection when split in different packages
The current detection code for Linux kernels assumes that a kernel package contains everything in it, i.e. the kernel itself, its modules, and its configuration. However, since recent Ubuntu versions (e.g. starting from 18.04) modules & config (with few more files) are split in an own package, thus not detecting the modpath from installed vmlinuz files. To overcome this situation, rework this detection a bit: 1) find the vmlinuz file as before, but then immediately make sure it exists by stat'ing it 2) get the kernel version from the vmlinuz filename, which should be a good assumption to do 3) use the calculated version to detect the modules path, checking that it exists As additional change, do not assume the config file is in the same package as vmlinuz, but directly look into the filesystem using the version we already have. --- v2v/linux_kernels.ml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml index c047d6deb..6a355b880 100644 --- a/v2v/linux_kernels.ml +++ b/v2v/linux_kernels.ml @@ -103,27 +103,27 @@ let detect_kernels (g : G.guestfs) inspect family bootloader None ) else ( - (* Which of these is the kernel itself? *) + (* Which of these is the kernel itself? Also, make sure to check + * it exists by stat'ing it. + *) let vmlinuz = List.find ( fun filename -> String.is_prefix filename "/boot/vmlinuz-" ) files in - (* Which of these is the modpath? *) - let modpath = List.find ( - fun filename -> - String.length filename >= 14 && - String.is_prefix filename "/lib/modules/" - ) files in - - (* Check vmlinuz & modpath exist. *) - if not (g#is_dir ~followsymlinks:true modpath) then - raise Not_found; let vmlinuz_stat try g#statns vmlinuz with G.Error _ -> raise Not_found in - (* Get/construct the version. XXX Read this from kernel file. *) + (* Get/construct the version from the vmlinuz file. + * XXX Read this from kernel file. + *) let version - let prefix_len = String.length "/lib/modules/" in - String.sub modpath prefix_len (String.length modpath - prefix_len) in + String.sub vmlinuz 14 (String.length vmlinuz - 14) in + + (* Determine the modpath from the vmlinuz version, and check it + * exists. + *) + let modpath = "/lib/modules/" ^ version in + if not (g#is_dir ~followsymlinks:true modpath) then + raise Not_found; (* Find the initramfs which corresponds to the kernel. * Since the initramfs is built at runtime, and doesn't have @@ -188,7 +188,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader let config_file let cfg = "/boot/config-" ^ version in - if List.mem cfg files then Some cfg + if g#is_file ~followsymlinks:true cfg then Some cfg else None in let kernel_supports what kconf -- 2.17.0
Richard W.M. Jones
2018-May-21 17:41 UTC
Re: [Libguestfs] [PATCH] v2v: linux: fix kernel detection when split in different packages
On Mon, May 21, 2018 at 02:56:53PM +0200, Pino Toscano wrote:> - (* Get/construct the version. XXX Read this from kernel file. *) > + (* Get/construct the version from the vmlinuz file. > + * XXX Read this from kernel file. > + *) > let version > - let prefix_len = String.length "/lib/modules/" in > - String.sub modpath prefix_len (String.length modpath - prefix_len) in > + String.sub vmlinuz 14 (String.length vmlinuz - 14) inThe assumption we can just chop up the vmlinuz filename at a particular point and get a version seems dubious. Does something else support this? 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/
Possibly Parallel Threads
- [PATCH v2] v2v: linux: fix kernel detection when split in different packages
- [v2v PATCH 3/3] linux: remove special handling of packages with no files
- [PATCH] v2v: linux: Move kernel detection to a separate module.
- [v2v PATCH 1/3] linux: remove warning for packages with no files
- [libguestfs-common PATCH 0/2] detect_kernels: deal with RHEL's kernel-core / kernel-modules-core split