[Libguestfs] [PATCH 2/2] kernel: find vmlinuz kernels in modules path (RHBZ#1394699)

Pino Toscano ptoscano at redhat.com
Mon Nov 21 13:39:14 UTC 2016


Newer kernel packages e.g. in Fedora place the kernel image named
"vmlinuz" directly within the modules path of that kernel.
Find these images first, not looking for kernels in /boot if any is
found under modules paths.
---
 src/kernel.ml | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/kernel.ml b/src/kernel.ml
index 2e061d8..b4e89da 100644
--- a/src/kernel.ml
+++ b/src/kernel.ml
@@ -22,6 +22,7 @@ open Printf
 open Utils
 open Ext2fs
 open Fnmatch
+open Glob
 
 let patt_of_cpu host_cpu =
   let models =
@@ -60,7 +61,28 @@ let rec build_kernel debug host_cpu dtb_wildcard copy_kernel kernel dtb =
       let modpath = find_modpath debug kernel_version in
       kernel_env, kernel_name, kernel_version, modpath
     with Not_found ->
-      find_kernel debug host_cpu kernel in
+      let kernels =
+        let files = glob "/lib/modules/*/vmlinuz" [GLOB_NOSORT; GLOB_NOESCAPE] in
+        let files = Array.to_list files in
+        let kernels =
+          List.map (
+            fun f ->
+              let modpath = Filename.dirname f in
+              f, Filename.basename f, Filename.basename modpath, modpath
+          ) files in
+        List.sort (
+          fun (_, _, a, _) (_, _, b, _) -> compare_version b a
+        ) kernels in
+
+      if kernels <> [] then (
+        let kernel = List.hd kernels in
+        if debug >= 1 then (
+          let kernel_file, _, _, _ = kernel in
+          printf "supermin: kernel: picked vmlinuz %s\n%!" kernel_file;
+        );
+        kernel
+      ) else
+        find_kernel debug host_cpu kernel in
 
   (* If the user passed --dtb option, locate dtb. *)
   (match dtb_wildcard with
-- 
2.7.4




More information about the Libguestfs mailing list