[Libguestfs] [PATCH] Fix Windows conversion when ControlSet001 isn't the CurrentControlSet

Matthew Booth mbooth at redhat.com
Tue Oct 19 09:38:55 UTC 2010


If a Windows boot fails and the user boots the last known good configuration,
ControlSet001 will be marked as failed and no longer used. However, virt-v2v
would only install viostor to ControlSet001, meaning it will fail to boot this
guest after conversion.

This patch looks up the current controlset and always installs registry keys to
the correct one.

Fixes RHBZ#644254
---
 lib/Sys/VirtV2V/Converter/Windows.pm |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter/Windows.pm b/lib/Sys/VirtV2V/Converter/Windows.pm
index bec1d60..29f5cd7 100644
--- a/lib/Sys/VirtV2V/Converter/Windows.pm
+++ b/lib/Sys/VirtV2V/Converter/Windows.pm
@@ -217,24 +217,29 @@ sub _add_viostor_to_registry
     my $h = Win::Hivex->open ($tmpdir . "/system", write => 1)
         or die "open system hive: $!";
 
+    # Get the 'Current' ControlSet. This is normally 001, but not always.
+    my $select = $h->node_get_child($h->root(), 'Select');
+    my $current_cs = $h->node_get_value($select, 'Current');
+    $current_cs = sprintf("ControlSet%03i", $h->value_dword($current_cs));
+
     # Make the changes.
-    my $regedits = '
+    my $regedits = <<REGEDITS;
 ; Edits to be made to a Windows guest to have
 ; it boot from viostor.
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\CriticalDeviceDatabase\pci#ven_1af4&dev_1001&subsys_00000000]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Control\\CriticalDeviceDatabase\\pci#ven_1af4&dev_1001&subsys_00000000]
 "Service"="viostor"
 "ClassGUID"="{4D36E97B-E325-11CE-BFC1-08002BE10318}"
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\CriticalDeviceDatabase\pci#ven_1af4&dev_1001&subsys_00020000]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Control\\CriticalDeviceDatabase\\pci#ven_1af4&dev_1001&subsys_00020000]
 "Service"="viostor"
 "ClassGUID"="{4D36E97B-E325-11CE-BFC1-08002BE10318}"
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\CriticalDeviceDatabase\pci#ven_1af4&dev_1001&subsys_00021af4]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Control\\CriticalDeviceDatabase\\pci#ven_1af4&dev_1001&subsys_00021af4]
 "Service"="viostor"
 "ClassGUID"="{4D36E97B-E325-11CE-BFC1-08002BE10318}"
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor]
 "Type"=dword:00000001
 "Start"=dword:00000000
 "Group"="SCSI miniport"
@@ -242,27 +247,27 @@ sub _add_viostor_to_registry
 "ImagePath"="system32\\\\drivers\\\\viostor.sys"
 "Tag"=dword:00000021
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor\Parameters]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor\\Parameters]
 "BusType"=dword:00000001
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor\Parameters\MaxTransferSize]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor\\Parameters\\MaxTransferSize]
 "ParamDesc"="Maximum Transfer Size"
 "type"="enum"
 "default"="0"
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor\Parameters\MaxTransferSize\enum]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor\\Parameters\\MaxTransferSize\\enum]
 "0"="64  KB"
 "1"="128 KB"
 "2"="256 KB"
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor\Parameters\PnpInterface]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor\\Parameters\\PnpInterface]
 "5"=dword:00000001
 
-[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\viostor\Enum]
+[HKEY_LOCAL_MACHINE\\SYSTEM\\$current_cs\\Services\\viostor\\Enum]
 "0"="PCI\\\\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\\\\3&13c0b0c5&0&20"
 "Count"=dword:00000001
 "NextInstance"=dword:00000001
-';
+REGEDITS
 
     my $io;
     if ($desc->{major_version} == 5 || $desc->{major_version} == 6) {
-- 
1.7.2.3




More information about the Libguestfs mailing list