[Pkg-libvirt-commits] [libguestfs] 25/66: v2v: For grub legacy, edit grub config file instead of using grubby (RHBZ#1141145).

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:47:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.54-1
in repository libguestfs.

commit cee9a4993d4435b57aa233b7b678a9b7cc5c1d53
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Sep 22 16:44:19 2014 +0100

    v2v: For grub legacy, edit grub config file instead of using grubby (RHBZ#1141145).
    
    The old virt-v2v code would either edit the grub config file (grub
    legacy) or use grubby --set-default (grub2).
    
    When translating this code, I figured we could use grubby in both
    cases, since grubby exists for grub legacy guests.
    
    However it doesn't appear to work for grub legacy guests.  Use the
    configuration file editing method for these, same as old virt-v2v.
    
    Thanks: Tingting Zheng
---
 v2v/convert_linux.ml | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index d932bcc..2cd1688 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -755,18 +755,45 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
     best_kernel, virtio
 
   and grub_set_bootable kernel =
-    let cmd =
-      if g#exists "/sbin/grubby" then
-        [| "grubby"; "--set-default"; kernel.ki_vmlinuz |]
-      else
-        [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; sprintf "
+    match grub with
+    | `Grub1 ->
+      if not (string_prefix kernel.ki_vmlinuz grub_prefix) then
+        error (f_"kernel %s is not under grub tree %s")
+          kernel.ki_vmlinuz grub_prefix;
+      let kernel_under_grub_prefix =
+        let prefix_len = String.length grub_prefix in
+        let kernel_len = String.length kernel.ki_vmlinuz in
+        String.sub kernel.ki_vmlinuz prefix_len (kernel_len - prefix_len) in
+
+      (* Find the grub entry for the given kernel. *)
+      let paths = g#aug_match (sprintf "/files%s/title/kernel[. = '%s']"
+                                 grub_config kernel_under_grub_prefix) in
+      let paths = Array.to_list paths in
+      if paths = [] then
+        error (f_"didn't find grub entry for kernel %s") kernel.ki_vmlinuz;
+      let path = List.hd paths in
+      let rex = Str.regexp "/title\\[\\([1-9][0-9]*\\)\\]/kernel" in
+      let index =
+        if Str.string_match rex path 0 then
+          (int_of_string (Str.matched_group 1 path) - 1)
+        else
+          0 in
+      g#aug_set (sprintf "/files%s/default" grub_config) (string_of_int index);
+      g#aug_save ()
+
+    | `Grub2 ->
+      let cmd =
+        if g#exists "/sbin/grubby" then
+          [| "grubby"; "--set-default"; kernel.ki_vmlinuz |]
+        else
+          [| "/usr/bin/perl"; "-MBootloader::Tools"; "-e"; sprintf "
               InitLibrary();
               my @sections = GetSectionList(type=>image, image=>\"%s\");
               my $section = GetSection(@sections);
               my $newdefault = $section->{name};
               SetGlobals(default, \"$newdefault\");
             " kernel.ki_vmlinuz |] in
-    ignore (g#command cmd)
+      ignore (g#command cmd)
 
   (* Even though the kernel was already installed (this version of
    * virt-v2v does not install new kernels), it could have an

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list