[Libguestfs] [PATCH] Fix import of RHEL 3 kvm guests using kmod-virtio

Matthew Booth mbooth at redhat.com
Thu May 13 13:34:15 UTC 2010


RHEL 3 doesn't have a dynamic /dev. kmod-virtio creates devices nodes for vdX
block devices based on what the major number of virtblk was at the time it was
installed. This is, in turn, based on the order the modules were loaded in
initrd.

To try to preserve this precarious state of affairs, when adding virtio drivers
to a new initrd we always load the same drivers as kmod-virtio in the same
order.
---
 lib/Sys/VirtV2V/Converter/Linux.pm |    8 +++++++-
 lib/Sys/VirtV2V/GuestOS/RedHat.pm  |    8 ++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter/Linux.pm b/lib/Sys/VirtV2V/Converter/Linux.pm
index df7c969..6c50cd1 100644
--- a/lib/Sys/VirtV2V/Converter/Linux.pm
+++ b/lib/Sys/VirtV2V/Converter/Linux.pm
@@ -332,7 +332,13 @@ sub _configure_boot
     my ($guestos, $kernel, $virtio) = @_;
 
     if($virtio) {
-        $guestos->prepare_bootable($kernel, "virtio_pci", "virtio_blk");
+        # The order of modules here is deliberately the same as the order
+        # specified in the postinstall script of kmod-virtio in RHEL3. The
+        # reason is that the probing order determines the major number of vdX
+        # block devices. If we change it, RHEL 3 KVM guests won't boot.
+        $guestos->prepare_bootable($kernel, "virtio", "virtio_ring",
+                                            "virtio_blk", "virtio_net",
+                                            "virtio_pci");
     } else {
         $guestos->prepare_bootable($kernel, "sym53c8xx");
     }
diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
index 8b211f0..af64dfa 100644
--- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm
+++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
@@ -1381,10 +1381,10 @@ sub prepare_bootable
         # Backup the original initrd
         $g->mv("$initrd", "$initrd.pre-v2v");
 
-        # Create a new initrd which preloads the required kernel modules
-        my @preload_args = ();
+        # Create a new initrd which probes the required kernel modules
+        my @module_args = ();
         foreach my $module (@modules) {
-            push(@preload_args, "--preload=$module");
+            push(@module_args, "--with=$module");
         }
 
         # mkinitrd reads configuration which we've probably changed
@@ -1407,7 +1407,7 @@ sub prepare_bootable
             $g->modprobe("loop");
         };
 
-        $g->command(["/sbin/mkinitrd", @preload_args, $initrd, $version]);
+        $g->command(["/sbin/mkinitrd", @module_args, $initrd, $version]);
     }
 
     # Disable kudzu in the guest
-- 
1.6.6.1




More information about the Libguestfs mailing list