Matthew Booth
2010-Oct-19 09:38 UTC
[Libguestfs] [PATCH] Fix Windows conversion when ControlSet001 isn't the CurrentControlSet
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
Richard W.M. Jones
2010-Oct-19 09:57 UTC
[Libguestfs] [PATCH] Fix Windows conversion when ControlSet001 isn't the CurrentControlSet
On Tue, Oct 19, 2010 at 10:38:55AM +0100, Matthew Booth wrote: [...] Patch looks good, ACK. My only worry is what happens if the following code fails (missing key, unexpected type etc), but I guess that won't happen for a real registry, and if it does we'll get an exception which will propagate out into a useful error message.> + # 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));Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Seemingly Similar Threads
- [PATCH 4/7] v2v: extract reusable parts of viostor regedits
- [PATCH v2v] Pre-convert Windows guests.
- [PATCH 1/7] v2v: check next free oem%d.inf in /Windows/Inf
- [PATCH 5/7] v2v: adapt the subkey in Enum registry to windows version
- [PATCH 7/7] v2v: add support for SUSE VMDP drivers