Roman Kagan
2016-Apr-06 17:24 UTC
[Libguestfs] [PATCH 0/4] v2v: simplify Windows registry patching
The way we patch the Windows registry in order to allow it to boot off a virtio-blk drive was initially conceived by comparing the state with virtio-blk driver properly installed, to that without. However, we don't want to replicate the Windows PnP system; rather we need to apply just enough edits to make the system boot, and then let the Windows PnP manager figure out the rest. This series makes a dramatic reduction to the amount of edits we apply. Besides it refactors the code somewhat, to make it generic enough to allow later on to accomodate other SCSI drivers (specifically, vioscsi). Tested on Win XP SP3 x32 Win XP SP2 x64 Win 2003R2 SP2 x32 Win 2003R2 SP2 x63 Win Vista SP2 x32 Win Vista SP2 x64 Win 2008 SP2 x32 Win 2008R2 SP1 x64 Win 7 SP1 x32 Win 7 SP1 x64 Win 8 x32 Win 8 x64 Win 8.1 x32 Win 8.1 x64 Win 2012R2 x64 Win 10 x64 Roman Kagan (4): v2v: win <= 7: reduce registry patch v2v: win >= 8: reduce registry patch v2v: win >= 8: simplify registry patching v2v: win: factor out common bits in registry patching v2v/windows_virtio.ml | 306 +++++++++----------------------------------------- 1 file changed, 52 insertions(+), 254 deletions(-) -- 2.5.5
Roman Kagan
2016-Apr-06 17:24 UTC
[Libguestfs] [PATCH 1/4] v2v: win <= 7: reduce registry patch
The patch to the Windows registry allowing it to boot off a virtio-blk drive was initially conceived by comparing the state with virtio-blk driver properly installed, to that without. However, we don't want to replicate the Windows PnP system; rather we need to apply just enough edits to make the system boot, and then let the Windows PnP manager figure out the rest. It turned out that for Windows <= 7 / 2008R2 the "just enough" set includes only the service entry for the driver, and a CriticalDeviceDatabase entry matching the PCI id of the device and pointing at that service entry. While at this, also drop CriticalDeviceDatabase entries for older and no longer relevant PCI ids of the virtio-blk device. Tested on Win XP SP3 x32 Win XP SP2 x64 Win 2003R2 SP2 x32 Win 2003R2 SP2 x63 Win Vista SP2 x32 Win Vista SP2 x64 Win 2008 SP2 x32 Win 2008R2 SP1 x64 Win 7 SP1 x32 Win 7 SP1 x64 Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/windows_virtio.ml | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml index ba87aa6..7796a0f 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -147,18 +147,6 @@ and add_viostor_to_critical_device_database g root current_cs * hive may be modified here. *) let regedits = [ - [ current_cs; "Control"; "CriticalDeviceDatabase"; "pci#ven_1af4&dev_1001&subsys_00000000" ], - [ "Service", REG_SZ "viostor"; - "ClassGUID", REG_SZ "{4D36E97B-E325-11CE-BFC1-08002BE10318}" ]; - - [ current_cs; "Control"; "CriticalDeviceDatabase"; "pci#ven_1af4&dev_1001&subsys_00020000" ], - [ "Service", REG_SZ "viostor"; - "ClassGUID", REG_SZ "{4D36E97B-E325-11CE-BFC1-08002BE10318}" ]; - - [ current_cs; "Control"; "CriticalDeviceDatabase"; "pci#ven_1af4&dev_1001&subsys_00021af4" ], - [ "Service", REG_SZ "viostor"; - "ClassGUID", REG_SZ "{4D36E97B-E325-11CE-BFC1-08002BE10318}" ]; - [ current_cs; "Control"; "CriticalDeviceDatabase"; "pci#ven_1af4&dev_1001&subsys_00021af4&rev_00" ], [ "Service", REG_SZ "viostor"; "ClassGUID", REG_SZ "{4D36E97B-E325-11CE-BFC1-08002BE10318}" ]; @@ -168,29 +156,7 @@ and add_viostor_to_critical_device_database g root current_cs "Start", REG_DWORD 0x0_l; "Group", REG_SZ "SCSI miniport"; "ErrorControl", REG_DWORD 0x1_l; - "ImagePath", REG_EXPAND_SZ "system32\\drivers\\viostor.sys"; - "Tag", REG_DWORD 0x21_l ]; - - [ current_cs; "Services"; "viostor"; "Parameters" ], - [ "BusType", REG_DWORD 0x1_l ]; - - [ current_cs; "Services"; "viostor"; "Parameters"; "MaxTransferSize" ], - [ "ParamDesc", REG_SZ "Maximum Transfer Size"; - "type", REG_SZ "enum"; - "default", REG_SZ "0" ]; - - [ current_cs; "Services"; "viostor"; "Parameters"; "MaxTransferSize"; "enum" ], - [ "0", REG_SZ "64 KB"; - "1", REG_SZ "128 KB"; - "2", REG_SZ "256 KB" ]; - - [ current_cs; "Services"; "viostor"; "Parameters"; "PnpInterface" ], - [ "5", REG_DWORD 0x1_l ]; - - [ current_cs; "Services"; "viostor"; "Enum" ], - [ "0", REG_SZ "PCI\\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\\3&13c0b0c5&0&20"; - "Count", REG_DWORD 0x1_l; - "NextInstance", REG_DWORD 0x1_l ]; + "ImagePath", REG_EXPAND_SZ "system32\\drivers\\viostor.sys" ]; ] in reg_import g root regedits -- 2.5.5
Roman Kagan
2016-Apr-06 17:24 UTC
[Libguestfs] [PATCH 2/4] v2v: win >= 8: reduce registry patch
The patch to the Windows registry allowing it to boot off a virtio-blk drive was initially conceived by comparing the state with virtio-blk driver properly installed, to that without. However, we don't want to replicate the Windows PnP system; rather we need to apply just enough edits to make the system boot, and then let the Windows PnP manager figure out the rest. It turned out (by trial and error) that for Windows >= 8 / 2012 the "just enough" set includes only the service entry for the driver, and a few entries under DriverDatabase. Tested on Win 8 x32 Win 8 x64 Win 8.1 x32 Win 8.1 x64 Win 2012R2 x64 Win 10 x64 Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/windows_virtio.ml | 144 +------------------------------------------------- 1 file changed, 2 insertions(+), 142 deletions(-) diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml index 7796a0f..738fa11 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -197,77 +197,16 @@ and add_viostor_to_driver_database g root arch current_cs if value = 0_L then oem_inf else loop node (i+1) in let oem_inf = loop node 1 in - (* Create the key. *) - g#hivex_node_set_value node oem_inf (* REG_NONE *) 0_L ""; oem_inf in - (* There should be a key - * HKLM\SYSTEM\ControlSet001\Control\Class\<scsi_adapter_guid> - * There may be subkey(s) of this called "0000", "0001" etc. We want - * to create the next free subkey. MSFT covers the key here: - * https://technet.microsoft.com/en-us/library/cc957341.aspx - * That page incorrectly states that the key has the form "000n". - * In fact we observed from real registries that the key is a - * decimal number that goes 0009 -> 0010 etc. - *) - let controller_path - [ current_cs; "Control"; "Class"; scsi_adapter_guid ] in - let controller_offset = get_controller_offset g root controller_path in - let regedits = [ - controller_path @ [ controller_offset ], - [ "DriverDate", REG_SZ "6-4-2014"; - "DriverDateData", REG_BINARY "\x00\x40\x90\xed\x87\x7f\xcf\x01"; - "DriverDesc", REG_SZ "Red Hat VirtIO SCSI controller"; - "DriverVersion", REG_SZ "62.71.104.8600" (* XXX *); - "InfPath", REG_SZ oem_inf; - "InfSection", REG_SZ "rhelscsi_inst"; - "MatchingDeviceId", REG_SZ "PCI\\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00"; - "ProviderName", REG_SZ "Red Hat, Inc." ]; - - [ current_cs; "Enum"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\\3&13c0b0c5&0&38" ], - [ "Capabilities", REG_DWORD 0x6_l; - "ClassGUID", REG_SZ scsi_adapter_guid; - "CompatibleIDs", REG_MULTI_SZ [ - "PCI\\VEN_1AF4&DEV_1001&REV_00"; - "PCI\\VEN_1AF4&DEV_1001"; - "PCI\\VEN_1AF4&CC_010000"; - "PCI\\VEN_1AF4&CC_0100"; - "PCI\\VEN_1AF4"; - "PCI\\CC_010000"; - "PCI\\CC_0100"; - ]; - "ConfigFlags", REG_DWORD 0_l; - "ContainerID", REG_SZ "{00000000-0000-0000-ffff-ffffffffffff}"; - "DeviceDesc", REG_SZ (sprintf "@%s,%%rhelscsi.devicedesc%%;Red Hat VirtIO SCSI controller" oem_inf); - "Driver", REG_SZ (sprintf "%s\\%s" scsi_adapter_guid controller_offset); - "HardwareID", REG_MULTI_SZ [ - "PCI\\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00"; - "PCI\\VEN_1AF4&DEV_1001&SUBSYS_00021AF4"; - "PCI\\VEN_1AF4&DEV_1001&CC_010000"; - "PCI\\VEN_1AF4&DEV_1001&CC_0100"; - ]; - "LocationInformation", REG_SZ "@System32\\drivers\\pci.sys,#65536;PCI bus %1, device %2, function %3;(0,7,0)"; - "Mfg", REG_SZ (sprintf "@%s,%%rhel%%;Red Hat, Inc." oem_inf); - "ParentIdPrefix", REG_SZ "4&87f7bfb&0"; - "Service", REG_SZ "viostor"; - "UINumber", REG_DWORD 0x7_l ]; - [ current_cs; "Services"; "viostor" ], [ "ErrorControl", REG_DWORD 0x1_l; "Group", REG_SZ "SCSI miniport"; "ImagePath", REG_EXPAND_SZ "system32\\drivers\\viostor.sys"; - "Owners", REG_MULTI_SZ [ oem_inf ]; "Start", REG_DWORD 0x0_l; - "Tag", REG_DWORD 0x58_l; "Type", REG_DWORD 0x1_l ]; - [ current_cs; "Services"; "viostor"; "Parameters" ], - [ "BusType", REG_DWORD 0x1_l ]; - - [ current_cs; "Services"; "viostor"; "Parameters"; "PnpInterface" ], - [ "5", REG_DWORD 0x1_l ]; - [ "DriverDatabase"; "DriverInfFiles"; oem_inf ], [ "", REG_MULTI_SZ [ viostor_inf ]; "Active", REG_SZ viostor_inf; @@ -277,94 +216,15 @@ and add_viostor_to_driver_database g root arch current_cs [ "DriverDatabase"; "DeviceIds"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], [ oem_inf, REG_BINARY "\x01\xff\x00\x00" ]; - [ "DriverDatabase"; "DriverPackages"; viostor_inf ], - [ "", REG_SZ oem_inf; - "F6", REG_DWORD 0x1_l; - "InfName", REG_SZ "viostor.inf"; - "OemPath", REG_SZ ("X:\\windows\\System32\\DriverStore\\FileRepository\\" ^ viostor_inf); - "Provider", REG_SZ "Red Hat, Inc."; - "SignerName", REG_SZ "Microsoft Windows Hardware Compatibility Publisher"; - "SignerScore", REG_DWORD 0x0d000005_l; - "StatusFlags", REG_DWORD 0x00000012_l; - (* NB: scsi_adapter_guid appears inside this string. *) - "Version", REG_BINARY "\x00\xff\x09\x00\x00\x00\x00\x00\x7b\xe9\x36\x4d\x25\xe3\xce\x11\xbf\xc1\x08\x00\x2b\xe1\x03\x18\x00\x40\x90\xed\x87\x7f\xcf\x01\x98\x21\x68\x00\x47\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x00\x00" ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations" ], - []; - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst" ], [ "ConfigFlags", REG_DWORD 0_l; "Service", REG_SZ "viostor" ]; - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Device" ], - []; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Device"; "Interrupt Management" ], - []; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Device"; "Interrupt Management"; "Affinity Policy" ], - [ "DevicePolicy", REG_DWORD 0x00000005_l ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Device"; "Interrupt Management"; "MessageSignaledInterruptProperties" ], - [ "MSISupported", REG_DWORD 0x00000001_l; - "MessageNumberLimit", REG_DWORD 0x00000002_l ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Services" ], - []; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Services"; "viostor" ], - []; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Services"; "viostor"; "Parameters" ], - [ "BusType", REG_DWORD 0x00000001_l ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst"; "Services"; "viostor"; "Parameters"; "PnpInterface" ], - [ "5", REG_DWORD 0x00000001_l ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Descriptors" ], - []; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Descriptors"; "PCI" ], - []; - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Descriptors"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], - [ "Configuration", REG_SZ "rhelscsi_inst"; - "Description", REG_SZ "%rhelscsi.devicedesc%"; - "Manufacturer", REG_SZ "%rhel%" ]; - - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Strings" ], - [ "rhel", REG_SZ "Red Hat, Inc."; - "rhelscsi.devicedesc", REG_SZ "Red Hat VirtIO SCSI controller" ]; + [ "Configuration", REG_SZ "rhelscsi_inst" ] ] in - reg_import g root regedits; - -(* - A few more keys which we don't add above. Note that "oem1.inf" =- 6f,00,65,00,6d,00,31,00,2e,00,69,00,6e,00,66,00. - - [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\PCI\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\3&13c0b0c5&0&38\Properties\{540b947e-8b40-45bc-a8a2-6a0b894cbda2}\0007] - @=hex(ffff0012):6f,00,65,00,6d,00,31,00,2e,00,69,00,6e,00,66,00,3a,00,50,00,43,00,49,00,5c,00,56,00,45,00,4e,00,5f,00,31,00,41,00,46,00,34,00,26,00,44,00,45,00,56,00,5f,00,31,00,30,00,30,00,31,00,26,00,53,00,55,00,42,00,53,00,59,00,53,00,5f,00,30,00,30,00,30,00,32,00,31,00,41,00,46,00,34,00,26,00,52,00,45,00,56,00,5f,00,30,00,30,00,2c,00,72,00,68,00,65,00,6c,00,73,00,63,00,73,00,69,00,5f,00,69,00,6e,00,73,00,74,00,00,00 - - [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\PCI\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\3&13c0b0c5&0&38\Properties\{83da6326-97a6-4088-9453-a1923f573b29}\0003] - @=hex(ffff0012):6f,00,65,00,6d,00,31,00,2e,00,69,00,6e,00,66,00,3a,00,32,00,65,00,35,00,31,00,37,00,32,00,63,00,33,00,62,00,33,00,37,00,62,00,65,00,39,00,39,00,38,00,3a,00,72,00,68,00,65,00,6c,00,73,00,63,00,73,00,69,00,5f,00,69,00,6e,00,73,00,74,00,3a,00,36,00,32,00,2e,00,37,00,31,00,2e,00,31,00,30,00,34,00,2e,00,38,00,36,00,30,00,30,00,3a,00,50,00,43,00,49,00,5c,00,56,00,45,00,4e,00,5f,00,31,00,41,00,46,00,34,00,26,00,44,00,45,00,56,00,5f,00,31,00,30,00,30,00,31,00,26,00,53,00,55,00,42,00,53,00,59,00,53,00,5f,00,30,00,30,00,30,00,32,00,31,00,41,00,46,00,34,00,26,00,52,00,45,00,56,00,5f,00,30,00,30,00,00,00 - - [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\PCI\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00\3&13c0b0c5&0&38\Properties\{a8b865dd-2e3d-4094-ad97-e593a70c75d6}\0005] - @=hex(ffff0012):6f,00,65,00,6d,00,31,00,2e,00,69,00,6e,00,66,00,00,00 -*) - -and get_controller_offset g root controller_path - match Windows.get_node g root controller_path with - | None -> - error (f_"cannot find HKLM\\SYSTEM\\%s in the guest registry") - (String.concat "\\" controller_path) - | Some node -> - let rec loop node i - let controller_offset = sprintf "%04d" i in - let child = g#hivex_node_get_child node controller_offset in - if child = 0_L then controller_offset else loop node (i+1) - in - loop node 0 + reg_import g root regedits (* Copy the matching drivers to the driverdir; return true if any have * been copied. -- 2.5.5
Roman Kagan
2016-Apr-06 17:24 UTC
[Libguestfs] [PATCH 3/4] v2v: win >= 8: simplify registry patching
It turned out (by trial and error) that for Windows >= 8 / 2012, even though the PnP system uses names related to the original driver's .inf file for certain entries under DriverDatabase registry subtree, this doesn't have to hold for the storage driver to make it boot. So use our own artificial names there and simplify the surrounding code. This will also make sure the added entries don't confilct with those generated by PnP proper once the driver is installed, and that the entries are easy to look up in the eventual registry. The name chosen to refer to the driver -- "guestor" -- is intentionally different from the original "viostor" both to avoid collisions and to naturally expand to other relevant drivers (e.g. "vioscsi") later on. Tested on Win 8 x32 Win 8 x64 Win 8.1 x32 Win 8.1 x64 Win 2012R2 x64 Win 10 x64 Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/windows_virtio.ml | 51 +++++++++++---------------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml index 738fa11..c76a677 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -166,38 +166,9 @@ and add_viostor_to_driver_database g root arch current_cs * one must add keys into the DriverDatabase. *) - let viostor_inf - let arch - match arch with - | "x86_64" -> "amd64" - | "i386" | "i486" | "i585" | "i686" -> "x86" - | _ -> - error (f_"when adding viostor to the DriverDatabase, unknown architecture: %s") arch in - (* XXX I don't know what the significance of the c863.. string is. It - * may even be random. - *) - sprintf "viostor.inf_%s_%s" arch "c86329aaeb0a7904" in - - let scsi_adapter_guid = "{4d36e97b-e325-11ce-bfc1-08002be10318}" in - (* There should be a key - * HKLM\SYSTEM\DriverDatabase\DeviceIds\<scsi_adapter_guid> - * We want to add: - * "oem1.inf"=hex(0): - * but if we find "oem1.inf" we'll add "oem2.inf" (etc). - *) - let oem_inf - let path = [ "DriverDatabase"; "DeviceIds"; scsi_adapter_guid ] in - match Windows.get_node g root path with - | None -> - error (f_"cannot find HKLM\\SYSTEM\\DriverDatabase\\DeviceIds\\%s in the guest registry") scsi_adapter_guid - | Some node -> - let rec loop node i - let oem_inf = sprintf "oem%d.inf" i in - let value = g#hivex_node_get_value node oem_inf in - if value = 0_L then oem_inf else loop node (i+1) - in - let oem_inf = loop node 1 in - oem_inf in + let drv_inf = "guestor.inf" in + let drv_inf_label = drv_inf ^ "_tmp" in + let drv_config = "guestor_conf" in let regedits = [ [ current_cs; "Services"; "viostor" ], @@ -207,21 +178,21 @@ and add_viostor_to_driver_database g root arch current_cs "Start", REG_DWORD 0x0_l; "Type", REG_DWORD 0x1_l ]; - [ "DriverDatabase"; "DriverInfFiles"; oem_inf ], - [ "", REG_MULTI_SZ [ viostor_inf ]; - "Active", REG_SZ viostor_inf; - "Configurations", REG_MULTI_SZ [ "rhelscsi_inst" ] + [ "DriverDatabase"; "DriverInfFiles"; drv_inf ], + [ "", REG_MULTI_SZ [ drv_inf_label ]; + "Active", REG_SZ drv_inf_label; + "Configurations", REG_MULTI_SZ [ drv_config ] ]; [ "DriverDatabase"; "DeviceIds"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], - [ oem_inf, REG_BINARY "\x01\xff\x00\x00" ]; + [ drv_inf, REG_BINARY "\x01\xff\x00\x00" ]; - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Configurations"; "rhelscsi_inst" ], + [ "DriverDatabase"; "DriverPackages"; drv_inf_label; "Configurations"; drv_config ], [ "ConfigFlags", REG_DWORD 0_l; "Service", REG_SZ "viostor" ]; - [ "DriverDatabase"; "DriverPackages"; viostor_inf; "Descriptors"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], - [ "Configuration", REG_SZ "rhelscsi_inst" ] + [ "DriverDatabase"; "DriverPackages"; drv_inf_label; "Descriptors"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], + [ "Configuration", REG_SZ drv_config ] ] in reg_import g root regedits -- 2.5.5
Roman Kagan
2016-Apr-06 17:24 UTC
[Libguestfs] [PATCH 4/4] v2v: win: factor out common bits in registry patching
Refactor registry patching to share common parts between Win <= 7 and Win >= 8. Also branch between the two based on the presence of the DriverDatabase subtree rather than on the OS version, which allows not to pass the inspect handle into the functions. OTOH make the patching functions accept the driver name and device PCI id as arguments; this will allow to easily expand the code to support other drivers (e.g. vioscsi) later on. Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/windows_virtio.ml | 91 ++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml index c76a677..7ca4068 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -33,6 +33,9 @@ let virtio_win with Not_found -> Guestfs_config.datadir // "virtio-win" +let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}" +let viostor_pciid = "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" + let rec install_drivers g inspect systemroot root current_cs rcaps (* Copy the virtio drivers to the guest. *) let driverdir = sprintf "%s/Drivers/VirtIO" systemroot in @@ -82,7 +85,8 @@ let rec install_drivers g inspect systemroot root current_cs rcaps let target = sprintf "%s/system32/drivers/viostor.sys" systemroot in let target = g#case_sensitive_path target in g#cp source target; - add_viostor_to_registry g inspect root current_cs; + add_guestor_to_registry g root current_cs "viostor" + viostor_pciid; Virtio_blk | Some IDE, _ -> @@ -133,35 +137,40 @@ let rec install_drivers g inspect systemroot root current_cs rcaps (block, net, video) ) -and add_viostor_to_registry g inspect root current_cs - let { i_major_version = major; i_minor_version = minor; - i_arch = arch } = inspect in - if (major == 6 && minor >= 2) || major >= 7 then (* Windows >= 8 *) - add_viostor_to_driver_database g root arch current_cs - else (* Windows <= 7 *) - add_viostor_to_critical_device_database g root current_cs +and add_guestor_to_registry g root current_cs drv_name drv_pciid + let ddb_node = g#hivex_node_get_child root "DriverDatabase" in -and add_viostor_to_critical_device_database g root current_cs - (* See http://rwmj.wordpress.com/2010/04/30/tip-install-a-device-driver-in-a-windows-vm/ - * NB: All these edits are in the HKLM\SYSTEM hive. No other - * hive may be modified here. - *) - let regedits = [ - [ current_cs; "Control"; "CriticalDeviceDatabase"; "pci#ven_1af4&dev_1001&subsys_00021af4&rev_00" ], - [ "Service", REG_SZ "viostor"; - "ClassGUID", REG_SZ "{4D36E97B-E325-11CE-BFC1-08002BE10318}" ]; + let regedits + if ddb_node = 0L then + cdb_regedits current_cs drv_name drv_pciid + else + ddb_regedits current_cs drv_name drv_pciid in - [ current_cs; "Services"; "viostor" ], + let drv_sys_path = sprintf "system32\\drivers\\%s.sys" drv_name in + let common_regedits = [ + [ current_cs; "Services"; drv_name ], [ "Type", REG_DWORD 0x1_l; "Start", REG_DWORD 0x0_l; "Group", REG_SZ "SCSI miniport"; "ErrorControl", REG_DWORD 0x1_l; - "ImagePath", REG_EXPAND_SZ "system32\\drivers\\viostor.sys" ]; - ] in + "ImagePath", REG_EXPAND_SZ drv_sys_path ]; + ] in - reg_import g root regedits + reg_import g root (regedits @ common_regedits) -and add_viostor_to_driver_database g root arch current_cs +and cdb_regedits current_cs drv_name drv_pciid + (* See http://rwmj.wordpress.com/2010/04/30/tip-install-a-device-driver-in-a-windows-vm/ + * NB: All these edits are in the HKLM\SYSTEM hive. No other + * hive may be modified here. + *) + [ + [ current_cs; "Control"; "CriticalDeviceDatabase"; + "PCI#" ^ drv_pciid ], + [ "Service", REG_SZ drv_name; + "ClassGUID", REG_SZ scsi_class_guid ]; + ] + +and ddb_regedits current_cs drv_name drv_pciid (* Windows >= 8 doesn't use the CriticalDeviceDatabase. Instead * one must add keys into the DriverDatabase. *) @@ -170,32 +179,24 @@ and add_viostor_to_driver_database g root arch current_cs let drv_inf_label = drv_inf ^ "_tmp" in let drv_config = "guestor_conf" in - let regedits = [ - [ current_cs; "Services"; "viostor" ], - [ "ErrorControl", REG_DWORD 0x1_l; - "Group", REG_SZ "SCSI miniport"; - "ImagePath", REG_EXPAND_SZ "system32\\drivers\\viostor.sys"; - "Start", REG_DWORD 0x0_l; - "Type", REG_DWORD 0x1_l ]; - - [ "DriverDatabase"; "DriverInfFiles"; drv_inf ], - [ "", REG_MULTI_SZ [ drv_inf_label ]; - "Active", REG_SZ drv_inf_label; - "Configurations", REG_MULTI_SZ [ drv_config ] - ]; - - [ "DriverDatabase"; "DeviceIds"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], - [ drv_inf, REG_BINARY "\x01\xff\x00\x00" ]; + [ + [ "DriverDatabase"; "DriverInfFiles"; drv_inf ], + [ "", REG_MULTI_SZ [ drv_inf_label ]; + "Active", REG_SZ drv_inf_label; + "Configurations", REG_MULTI_SZ [ drv_config ] ]; - [ "DriverDatabase"; "DriverPackages"; drv_inf_label; "Configurations"; drv_config ], - [ "ConfigFlags", REG_DWORD 0_l; - "Service", REG_SZ "viostor" ]; + [ "DriverDatabase"; "DeviceIds"; "PCI"; drv_pciid ], + [ drv_inf, REG_BINARY "\x01\xff\x00\x00" ]; - [ "DriverDatabase"; "DriverPackages"; drv_inf_label; "Descriptors"; "PCI"; "VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" ], - [ "Configuration", REG_SZ drv_config ] - ] in + [ "DriverDatabase"; "DriverPackages"; drv_inf_label; + "Configurations"; drv_config ], + [ "ConfigFlags", REG_DWORD 0_l; + "Service", REG_SZ drv_name ]; - reg_import g root regedits + [ "DriverDatabase"; "DriverPackages"; drv_inf_label; + "Descriptors"; "PCI"; drv_pciid ], + [ "Configuration", REG_SZ drv_config ]; + ] (* Copy the matching drivers to the driverdir; return true if any have * been copied. -- 2.5.5
Richard W.M. Jones
2016-Apr-06 20:24 UTC
Re: [Libguestfs] [PATCH 0/4] v2v: simplify Windows registry patching
Crumbs .. Yes .. I don't even know how to review this. I have a set of (non-upstream) virt-v2v tests against Windows guests which I will start running now. They usually take many hours to run, and also I'm on holiday tomorrow. That should hopefully tell me if it completely breaks stuff or appears to work. After that it'd be nice if other virt-v2v users (especially those that know what's going on with Windows -- ie. not me) can look at this and comment. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Cedric Bosdonnat
2016-Apr-07 16:08 UTC
Re: [Libguestfs] [PATCH 0/4] v2v: simplify Windows registry patching
Hi Roman, I rebased my patches on top of yours and I'm getting troubles loading the VMDP virtio block driver. I'll need to investigate more to uncover what is missing to get it working. -- Cedric On Wed, 2016-04-06 at 20:24 +0300, Roman Kagan wrote:> The way we patch the Windows registry in order to allow it to boot > off a > virtio-blk drive was initially conceived by comparing the state with > virtio-blk driver properly installed, to that without. > > However, we don't want to replicate the Windows PnP system; rather we > need to apply just enough edits to make the system boot, and then let > the Windows PnP manager figure out the rest. > > This series makes a dramatic reduction to the amount of edits we > apply. > Besides it refactors the code somewhat, to make it generic enough to > allow later on to accomodate other SCSI drivers (specifically, > vioscsi). > > Tested on > > Win XP SP3 x32 > Win XP SP2 x64 > Win 2003R2 SP2 x32 > Win 2003R2 SP2 x63 > Win Vista SP2 x32 > Win Vista SP2 x64 > Win 2008 SP2 x32 > Win 2008R2 SP1 x64 > Win 7 SP1 x32 > Win 7 SP1 x64 > Win 8 x32 > Win 8 x64 > Win 8.1 x32 > Win 8.1 x64 > Win 2012R2 x64 > Win 10 x64 > > > Roman Kagan (4): > v2v: win <= 7: reduce registry patch > v2v: win >= 8: reduce registry patch > v2v: win >= 8: simplify registry patching > v2v: win: factor out common bits in registry patching > > v2v/windows_virtio.ml | 306 +++++++++------------------------------- > ---------- > 1 file changed, 52 insertions(+), 254 deletions(-) >
Richard W.M. Jones
2016-Apr-11 12:05 UTC
Re: [Libguestfs] [PATCH 0/4] v2v: simplify Windows registry patching
I'm not going to claim my tests are very comprehensive, but all the Windows ones do pass with your patch, so that's good news. (My RHEL-on-Xen tests fail, but that seems to be a separate regression). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Richard W.M. Jones
2016-Apr-11 16:52 UTC
Re: [Libguestfs] [PATCH 0/4] v2v: simplify Windows registry patching
On Mon, Apr 11, 2016 at 07:49:32PM +0300, Roman Kagan wrote:> On Mon, Apr 11, 2016 at 01:05:06PM +0100, Richard W.M. Jones wrote: > > > > I'm not going to claim my tests are very comprehensive, but all the > > Windows ones do pass with your patch, so that's good news. > > That's really good news, thanks a lot! I was actually counting on this > testing as you most probably had different set of Windows VMs than I did > so that would broaden the test coverage. > > So what are we going to do with it now?I just asked Vadim to comment, but basically I'm happy. Can we see if he replies by tomorrow? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/