Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 00/12] Windows: set static IP addresses as first thing at first boot
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 This patch set depends on [libguestfs-common PATCH] mlcustomize/firstboot: take an optional priority in "add_firstboot_script" The first 10 patches are meant as refactorings / cleanups, for the sake of easier maintenance / better readability, with no intent to change behavior. From those 10 patches, I ended up regression-testing "configure_qemu_ga" and "configure_wait_pnp" with a real Windows 2019 Server domain; the rest of that section of the series is effectively untested. The last two patches implement the actual goal of this series; I have tested those too, with the same Windows 2019 Server domain. Thanks Laszlo Laszlo Ersek (12): convert_linux: wrap overlong lines convert_windows: wrap overlong lines convert_linux: align shell script indentation with OCaml source code convert_windows: rewrite "configure_qemu_ga" script purely in PowerShell convert_windows: align "reg_restore" batch file commands with OCaml source convert_windows: align "configure_wait_pnp" batch file with OCaml source convert_windows: align "configure_vmdp" batch files with OCaml source convert_windows: align "unconfigure_xenpv" batch file with OCaml source convert_windows: align "unconfigure_prltools" batch file with OCaml source convert_windows: align "unconfigure_vmwaretools" batch file with OCaml src convert/windows: expose "prio" parameter in install_firstboot_powershell convert_windows: install "v2vnetcf.ps1" with prio 2500 convert/convert_linux.ml | 75 +++++--- convert/convert_windows.ml | 193 ++++++++++++-------- convert/windows.ml | 5 +- convert/windows.mli | 6 +- 4 files changed, 170 insertions(+), 109 deletions(-) -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 01/12] convert_linux: wrap overlong lines
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_linux.ml | 54 +++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index 116d9e06f792..930e555de8ed 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -64,7 +64,12 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ * this guest. See for example RHBZ#1965147. *) if inspect.i_apps = [] then - error (f_"inspection of the package database failed for this Linux guest. Rerun virt-v2v with -v -x and see earlier errors. This is an internal error which probably means that this guest is not supported by libguestfs inspection. If the guest should work with virt-v2v (see virt-v2v docs) then a fix will be required in libguestfs."); + error (f_"inspection of the package database failed for this Linux \ + guest. Rerun virt-v2v with -v -x and see earlier errors. \ + This is an internal error which probably means that this guest \ + is not supported by libguestfs inspection. If the guest should \ + work with virt-v2v (see virt-v2v docs) then a fix will be \ + required in libguestfs."); (* We use Augeas for inspection and conversion, so initialize it early. * Calling debug_augeas_errors will display any //error nodes in @@ -300,14 +305,16 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ Linux.augeas_reload g with G.Error msg -> - warning (f_"VirtualBox Guest Additions were detected, but uninstallation failed. The error message was: %s (ignored)") - msg + warning (f_"VirtualBox Guest Additions were detected, but \ + uninstallation failed. The error message was: %s \ + (ignored)") msg ) and unconfigure_vmware () (* Look for any configured VMware yum repos and disable them. *) let repos - g#aug_match "/files/etc/yum.repos.d/*/*[baseurl =~ regexp('https?://([^/]+\\.)?vmware\\.com/.*')]" in + g#aug_match "/files/etc/yum.repos.d/*/*[baseurl =~ \ + regexp('https?://([^/]+\\.)?vmware\\.com/.*')]" in let repos = Array.to_list repos in List.iter ( fun repo -> @@ -392,7 +399,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ ignore (g#command cmd); List.push_front library remove with G.Error msg -> - eprintf "%s: could not install replacement for %s. Error was: %s. %s was not removed.\n" + eprintf "%s: could not install replacement for %s. Error \ + was: %s. %s was not removed.\n" prog library msg library ); ) else ( @@ -438,8 +446,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ Linux.augeas_reload g with G.Error msg -> - warning (f_"VMware tools was detected, but uninstallation failed. The error message was: %s (ignored)") - msg + warning (f_"VMware tools was detected, but uninstallation failed. \ + The error message was: %s (ignored)") msg ) and unconfigure_citrix () @@ -516,8 +524,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ Linux.augeas_reload g with G.Error msg -> - warning (f_"Parallels tools was detected, but uninstallation failed. The error message was: %s (ignored)") - msg + warning (f_"Parallels tools was detected, but uninstallation \ + failed. The error message was: %s (ignored)") msg ) and install_linux_tools () @@ -539,7 +547,9 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ fun { ki_is_xen_pv_only_kernel = pv_only } -> pv_only ) bootloader_kernels in if only_xen_kernels then - error (f_"only Xen kernels are installed in this guest.\n\nRead the %s(1) manual, section \"Xen paravirtualized guests\", to see what to do.") prog; + error (f_"only Xen kernels are installed in this guest.\n\n\ + Read the %s(1) manual, section \"Xen paravirtualized \ + guests\", to see what to do.") prog; (* Enable the best non-Xen kernel, where "best" means the one with * the highest version, preferring non-debug kernels which support @@ -568,7 +578,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ print_kernel_info stderr "\t" best_kernel ); if best_kernel <> List.hd bootloader_kernels then ( - debug "best kernel is not the bootloader default, setting bootloader default ..."; + debug "best kernel is not the bootloader default, \ + setting bootloader default ..."; bootloader#set_default_kernel best_kernel.ki_vmlinuz ); @@ -664,8 +675,10 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ ) ) else if family = `Debian_family then ( - if not (g#is_file ~followsymlinks:true "/usr/sbin/update-initramfs") then - error (f_"unable to rebuild initrd (%s) because update-initramfs was not found in the guest") + if not (g#is_file ~followsymlinks:true + "/usr/sbin/update-initramfs") then + error (f_"unable to rebuild initrd (%s) because update-initramfs \ + was not found in the guest") initrd; if List.length modules > 0 then ( @@ -759,8 +772,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ ignore (g#sh cmd) ) else ( - error (f_"unable to rebuild initrd (%s) because mkinitrd or dracut was not found in the guest") - initrd + error (f_"unable to rebuild initrd (%s) because mkinitrd or dracut \ + was not found in the guest") initrd ) (* We configure a console on ttyS0. Make sure existing console @@ -870,8 +883,9 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ if !updated && not (g#is_file ~followsymlinks:true "/usr/bin/X") && not (g#is_file ~followsymlinks:true "/usr/bin/X11/X") then - warning (f_"The display driver was updated to ?%s?, but X11 does not seem to be installed in the guest. X may not function correctly.") - video_driver + warning (f_"The display driver was updated to ?%s?, but X11 does not \ + seem to be installed in the guest. X may not function \ + correctly.") video_driver and configure_kernel_modules block_type net_type (* This function modifies modules.conf (and its various aliases). *) @@ -909,7 +923,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ ] in try List.find (g#is_file ~followsymlinks:true) paths with Not_found -> - error (f_"unable to find any valid modprobe configuration file such as /etc/modprobe.conf"); + error (f_"unable to find any valid modprobe configuration file such \ + as /etc/modprobe.conf"); ) in @@ -1089,7 +1104,8 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ not (String.is_prefix device "sr") && not (String.is_prefix device "scd") && device <> "cdrom" then - warning (f_"%s references unknown device \"%s\". You may have to fix this entry manually after conversion.") + warning (f_"%s references unknown device \"%s\". You may have to \ + fix this entry manually after conversion.") path device; device in -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 02/12] convert_windows: wrap overlong lines
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 45 ++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 7bdcaf52f33c..5fece75c9691 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -107,8 +107,10 @@ let convert (g : G.guestfs) _ inspect _ static_ips let uninstkey = "UninstallString" in let valueh = g#hivex_node_get_value node uninstkey in if valueh = 0L then ( - warning (f_"cannot uninstall Xen PV drivers: registry key ?HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s? does not contain an ?%s? key") - xenpvreg uninstkey; + warning (f_"cannot uninstall Xen PV drivers: registry key ?HKLM\\\ + SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\\ + Uninstall\\%s? does not contain an ?%s? key") + xenpvreg uninstkey; raise Not_found ); let data = g#hivex_value_value valueh in @@ -157,13 +159,16 @@ let convert (g : G.guestfs) _ inspect _ static_ips let reg_cmd = g#hivex_value_string valueh in let reg_cmd = modfn reg_cmd in let cmd - sprintf "%s /quiet /norestart /l*v+ \"%%~dpn0.log\" REBOOT=ReallySuppress REMOVE=ALL %s" + sprintf "%s /quiet /norestart /l*v+ \"%%~dpn0.log\" \ + REBOOT=ReallySuppress REMOVE=ALL %s" reg_cmd extra_uninstall_params in List.push_front cmd ret ) else let name = g#hivex_node_name uninstnode in - warning (f_"cannot uninstall %s: registry key ?HKLM\\SOFTWARE\\%s\\%s? with DisplayName ?%s? doesn't contain value ?%s?") + warning (f_"cannot uninstall %s: registry key \ + ?HKLM\\SOFTWARE\\%s\\%s? with DisplayName \ + ?%s? doesn't contain value ?%s?") pretty_name (String.concat "\\" path) name dispname uninstval ) @@ -233,9 +238,17 @@ let convert (g : G.guestfs) _ inspect _ static_ips *) if block_driver = Virtio_blk then ( if has_group_policy then - warning (f_"this guest has Windows Group Policy Objects (GPO) and a new virtio block device driver was installed. In some circumstances, Group Policy may prevent new drivers from working (resulting in a 7B boot error). If this happens, try disabling Group Policy before doing the conversion."); + warning (f_"this guest has Windows Group Policy Objects (GPO) and a \ + new virtio block device driver was installed. In some \ + circumstances, Group Policy may prevent new drivers from \ + working (resulting in a 7B boot error). If this happens, \ + try disabling Group Policy before doing the conversion."); if has_antivirus then - warning (f_"this guest has Anti-Virus (AV) software and a new virtio block device driver was installed. In some circumstances, AV may prevent new drivers from working (resulting in a 7B boot error). If this happens, try disabling AV before doing the conversion."); + warning (f_"this guest has Anti-Virus (AV) software and a new virtio \ + block device driver was installed. In some \ + circumstances, AV may prevent new drivers from working \ + (resulting in a 7B boot error). If this happens, try \ + disabling AV before doing the conversion."); ); let machine, virtio_1_0 @@ -319,7 +332,9 @@ let convert (g : G.guestfs) _ inspect _ static_ips if qemu_ga_files <> [] then configure_qemu_ga qemu_ga_files else - warning (f_"QEMU Guest Agent MSI not found on tools ISO/directory. You may want to install the guest agent manually after conversion."); + warning (f_"QEMU Guest Agent MSI not found on tools ISO/directory. You \ + may want to install the guest agent manually after \ + conversion."); unconfigure_xenpv (); unconfigure_prltools (); @@ -634,7 +649,8 @@ if errorlevel 3010 exit /b 0 in loop values | None -> - warning (f_"could not find registry key HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion") + warning (f_"could not find registry key \ + HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion") and configure_network_interfaces net_driver (* If we were asked to force network interfaces to have particular @@ -658,7 +674,8 @@ if errorlevel 3010 exit /b 0 add "$adapters = @()"; add "While (-Not $adapters) {"; add " Start-Sleep -Seconds 5"; - add " $adapters = Get-NetAdapter -Physical | Where DriverFileName -eq \"netkvm.sys\""; + add " $adapters = Get-NetAdapter -Physical \ + | Where DriverFileName -eq \"netkvm.sys\""; add " Write-Host \"adapters = '$adapters'\""; add "}"; add "" @@ -669,7 +686,8 @@ if errorlevel 3010 exit /b 0 if_prefix_length; if_nameservers } -> add (sprintf "$mac_address = '%s'" (String.replace if_mac_addr ":" "-")); - add "$ifindex = (Get-NetAdapter -Physical | Where MacAddress -eq $mac_address).ifIndex"; + add "$ifindex = (Get-NetAdapter -Physical \ + | Where MacAddress -eq $mac_address).ifIndex"; add "if ($ifindex) {"; add " Write-Host \"setting IP address of adapter at $ifindex\""; @@ -697,8 +715,11 @@ if errorlevel 3010 exit /b 0 (* Set-DnsClientServerAddress command *) if if_nameservers <> [] then ( - add (sprintf " Set-DnsClientServerAddress -InterfaceIndex $ifindex -ServerAddresses (%s)" - (String.concat "," (List.map (sprintf "'%s'") if_nameservers))) + add (sprintf " Set-DnsClientServerAddress \ + -InterfaceIndex $ifindex \ + -ServerAddresses (%s)" + (String.concat "," + (List.map (sprintf "'%s'") if_nameservers))) ); add "}"; add "" -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 03/12] convert_linux: align shell script indentation with OCaml source code
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_linux.ml | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml index 930e555de8ed..58a2a2a84d85 100644 --- a/convert/convert_linux.ml +++ b/convert/convert_linux.ml @@ -1231,10 +1231,12 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ g#mkdir_p uefi_fallback_path; g#cp uefi_grub_name uefi_fallback_name; g#cp grub_config uefi_grub_conf; - let fix_script = sprintf -"#!/bin/bash -efibootmgr -c -L \"CentOS 6\" -rm -rf %s" uefi_fallback_path in + let fix_script + sprintf + "#!/bin/bash\n\ + efibootmgr -c -L \"CentOS 6\"\n\ + rm -rf %s" + uefi_fallback_path in Firstboot.add_firstboot_script g inspect.i_root "fix uefi boot" fix_script) else @@ -1262,10 +1264,13 @@ rm -rf %s" uefi_fallback_path in * at UEFI fallback path for simplicity *) if String.find shim "/boot/efi/EFI/ubuntu/shim" >= 0 then - let fix_script = sprintf -"#!/bin/bash -sudo efibootmgr -c -L ubuntu -l \\\\EFI\\\\ubuntu\\\\shim%s.efi -rm -rf %s" arch_suffix uefi_fallback_path in + let fix_script + sprintf + "#!/bin/bash\n\ + sudo efibootmgr -c -L ubuntu \ + -l \\\\EFI\\\\ubuntu\\\\shim%s.efi\n\ + rm -rf %s" + arch_suffix uefi_fallback_path in Firstboot.add_firstboot_script g inspect.i_root "fix uefi boot" fix_script else -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 04/12] convert_windows: rewrite "configure_qemu_ga" script purely in PowerShell
The "configure_qemu_ga" function embeds a 'powershell.exe -command "..."' invocation in a CMD batch file. This makes the actual PowerShell script effectively unreadable, due to both line length and quoting depth. Everything else that the CMD batch file does is easily reimplementable in PowerShell. So reimplement the script in PowerShell purely, which allows us to unnest one level of quoting, and to break the script into short statements that align well with the OCaml source code. Register the script with our "Windows.install_firstboot_powershell" function. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 35 +++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 5fece75c9691..59ad3520c994 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -450,15 +450,32 @@ popd * https://stackoverflow.com/a/18730884 * https://bugzilla.redhat.com/show_bug.cgi?id=1895323 *) - let fb_script = sprintf "\ -echo Removing any previously scheduled qemu-ga installation -schtasks.exe /Delete /TN Firstboot-qemu-ga /F -echo Scheduling delayed installation of qemu-ga from %s -powershell.exe -command \"$d = (get-date).AddSeconds(120); $FormatHack = (($([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) -replace 'y+', 'yyyy') -replace 'M+', 'MM') -replace 'd+', 'dd'; schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString($FormatHack) /RU SYSTEM /TN Firstboot-qemu-ga /TR \\\"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\\\"\" - " - msi_path msi_path msi_path in - Firstboot.add_firstboot_script g inspect.i_root - ("install " ^ msi_path) fb_script; + let psh_script = ref [] in + let add = List.push_back psh_script in + + add "# Uncomment this line for lots of debug output."; + add "# Set-PSDebug -Trace 2"; + add ""; + add "Write-Host Removing any previously scheduled qemu-ga installation"; + add "schtasks.exe /Delete /TN Firstboot-qemu-ga /F"; + add ""; + add (sprintf + "Write-Host Scheduling delayed installation of qemu-ga from %s" + msi_path); + add "$d = (get-date).AddSeconds(120)"; + add "$dtfinfo = [System.Globalization.DateTimeFormatInfo]::CurrentInfo"; + add "$sdp = $dtfinfo.ShortDatePattern"; + add "$sdp = $sdp -replace 'y+', 'yyyy'"; + add "$sdp = $sdp -replace 'M+', 'MM'"; + add "$sdp = $sdp -replace 'd+', 'dd'"; + add "schtasks.exe /Create /SC ONCE `"; + add " /ST $d.ToString('HH:mm') /SD $d.ToString($sdp) `"; + add " /RU SYSTEM /TN Firstboot-qemu-ga `"; + add (sprintf " /TR \"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\"" + msi_path msi_path); + + Windows.install_firstboot_powershell g inspect + (sprintf "install-%s.ps1" msi_path) !psh_script; ) files -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 05/12] convert_windows: align "reg_restore" batch file commands with OCaml source
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 59ad3520c994..97021766c2b7 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -359,10 +359,9 @@ let convert (g : G.guestfs) _ inspect _ static_ips and reg_restore key name value let strkey = String.concat "\\" key in match value with - | Some value -> sprintf "\ -reg add \"%s\" /v %s /t REG_DWORD /d %Ld /f" strkey name value - | None -> sprintf "\ -reg delete \"%s\" /v %s /f" strkey name + | Some value -> sprintf "reg add \"%s\" /v %s /t REG_DWORD /d %Ld /f" + strkey name value + | None -> sprintf "reg delete \"%s\" /v %s /f" strkey name and configure_wait_pnp tool_path (* Prevent destructive interactions of firstboot with PnP. *) -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 06/12] convert_windows: align "configure_wait_pnp" batch file with OCaml source
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 97021766c2b7..f1ae0fa8a4b1 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -401,12 +401,14 @@ let convert (g : G.guestfs) _ inspect _ static_ips let pnp_wait_path = "/Program Files/Guestfs/Firstboot/pnp_wait.exe" in - let fb_script = sprintf "\ - at echo off - -echo Wait for PnP to complete -\"%s\" >\"%%~dpn0.log\" 2>&1 -%s" (String.replace_char pnp_wait_path '/' '\\') reg_restore_str in + let fb_script = sprintf + "@echo off\n\ + \n\ + echo Wait for PnP to complete\n\ + \"%s\" >\"%%~dpn0.log\" 2>&1\n\ + %s" + (String.replace_char pnp_wait_path '/' '\\') + reg_restore_str in Firstboot.add_firstboot_script g inspect.i_root "wait pnp" fb_script; (* add_firstboot_script has created the path already. *) -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 07/12] convert_windows: align "configure_vmdp" batch files with OCaml source
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 32 +++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index f1ae0fa8a4b1..56e12cf12ba8 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -418,25 +418,21 @@ let convert (g : G.guestfs) _ inspect _ static_ips (* Configure VMDP if possible *) g#upload tool_path "/vmdp.exe"; - let fb_script = "\ -echo V2V first boot script started -echo Decompressing VMDP installer -\"\\vmdp.exe\" -pushd \"VMDP-*\" -echo Installing VMDP -setup.exe /eula_accepted /no_reboot -popd -" in + let fb_script = "echo V2V first boot script started\n\ + echo Decompressing VMDP installer\n\ + \"\\vmdp.exe\"\n\ + pushd \"VMDP-*\"\n\ + echo Installing VMDP\n\ + setup.exe /eula_accepted /no_reboot\n\ + popd\n" in - let fb_recover_script = "\ -echo Finishing VMDP installation -if not exist VMDP-* ( - \"\\vmdp.exe\" -) -pushd \"VMDP-*\" -setup.exe /eula_accepted /no_reboot -popd -" in + let fb_recover_script = "echo Finishing VMDP installation\n\ + if not exist VMDP-* (\n\ + \"\\vmdp.exe\"\n\ + )\n\ + pushd \"VMDP-*\"\n\ + setup.exe /eula_accepted /no_reboot\n\ + popd\n" in Firstboot.add_firstboot_script g inspect.i_root "configure vmdp" fb_script; -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 08/12] convert_windows: align "unconfigure_xenpv" batch file with OCaml source
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 56e12cf12ba8..60742454c3c4 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -480,12 +480,12 @@ let convert (g : G.guestfs) _ inspect _ static_ips match xenpv_uninst with | None -> () (* nothing to be uninstalled *) | Some uninst -> - let fb_script = sprintf "\ - at echo off - -echo uninstalling Xen PV driver -\"%s\" -" uninst in + let fb_script = sprintf + "@echo off\n\ + \n\ + echo uninstalling Xen PV driver\n\ + \"%s\"\n" + uninst in Firstboot.add_firstboot_script g inspect.i_root "uninstall Xen PV" fb_script -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 09/12] convert_windows: align "unconfigure_prltools" batch file with OCaml source
While at it, embed the comment about ERROR_SUCCESS_REBOOT_REQUIRED being fine into the batch file. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 60742454c3c4..0611bf06cb80 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -490,19 +490,20 @@ let convert (g : G.guestfs) _ inspect _ static_ips "uninstall Xen PV" fb_script and unconfigure_prltools () + let regkey + "HKLM\\System\\CurrentControlSet\\Services\\prl_strg\\DriverInfo" in List.iter ( fun uninst -> - let fb_script = "\ - at echo off - -REG DELETE HKLM\\System\\CurrentControlSet\\Services\\prl_strg\\DriverInfo /v RefCount /f - -echo uninstalling Parallels guest tools -" ^ uninst ^ -(* ERROR_SUCCESS_REBOOT_REQUIRED == 3010 is OK too *) -" -if errorlevel 3010 exit /b 0 -" in + let fb_script = sprintf + "@echo off\n\ + \n\ + REG DELETE %s /v RefCount /f\n\ + \n\ + echo uninstalling Parallels guest tools\n\ + rem ERROR_SUCCESS_REBOOT_REQUIRED (3010) is OK too\n\ + %s\n\ + if errorlevel 3010 exit /b 0\n" + regkey uninst in Firstboot.add_firstboot_script g inspect.i_root "uninstall Parallels tools" fb_script -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 10/12] convert_windows: align "unconfigure_vmwaretools" batch file with OCaml src
While at it, embed the comment about ERROR_SUCCESS_REBOOT_REQUIRED being fine into the batch file. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 0611bf06cb80..fa2eae28a768 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -512,15 +512,14 @@ let convert (g : G.guestfs) _ inspect _ static_ips and unconfigure_vmwaretools () List.iter ( fun uninst -> - let fb_script = "\ - at echo off - -echo uninstalling VMware Tools -" ^ uninst ^ -(* ERROR_SUCCESS_REBOOT_REQUIRED == 3010 is OK too *) -" -if errorlevel 3010 exit /b 0 -" in + let fb_script = sprintf + "@echo off\n\ + \n\ + echo uninstalling VMware Tools\n\ + rem ERROR_SUCCESS_REBOOT_REQUIRED (3010) is OK too\n\ + %s\n\ + if errorlevel 3010 exit /b 0\n" + uninst in Firstboot.add_firstboot_script g inspect.i_root "uninstall VMware Tools" fb_script -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 11/12] convert/windows: expose "prio" parameter in install_firstboot_powershell
The "Firstboot.add_firstboot_script" function now takes an (optional) priority parameter. Because "install_firstboot_powershell" is a wrapper around "Firstboot.add_firstboot_script", enable callers of the former too to set the script run priority. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/windows.mli | 6 +++--- convert/windows.ml | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/convert/windows.mli b/convert/windows.mli index d888e2db40b3..4c7f292832ac 100644 --- a/convert/windows.mli +++ b/convert/windows.mli @@ -23,7 +23,7 @@ val detect_antivirus : Types.inspect -> bool this Windows guest. *) val install_firstboot_powershell : Guestfs.guestfs -> Types.inspect -> - string -> string list -> unit -(** [install_powershell_firstboot g inspect filename code] installs a + ?prio:int -> string -> string list -> unit +(** [install_powershell_firstboot g inspect prio filename code] installs a Powershell script (the lines of code) as a firstboot script in - the Windows VM. *) + the Windows VM. If [prio] is omitted, [Firstboot.default_prio] is used. *) diff --git a/convert/windows.ml b/convert/windows.ml index fc0faef57249..8a30be10d21a 100644 --- a/convert/windows.ml +++ b/convert/windows.ml @@ -52,7 +52,8 @@ and (=~) str rex = PCRE.matches rex str * a regular batch file. *) let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } - filename code + ?(prio = Firstboot.default_prio) filename + code let tempdir = sprintf "%s/Temp" i_windows_systemroot in g#mkdir_p tempdir; let code = String.concat "\r\n" code ^ "\r\n" in @@ -67,4 +68,4 @@ let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } let ps_path = i_windows_systemroot ^ "\\Temp\\" ^ filename in let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in - Firstboot.add_firstboot_script g i_root filename fb + Firstboot.add_firstboot_script g i_root ~prio filename fb -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 12/12] convert_windows: install "v2vnetcf.ps1" with prio 2500
The windows converter installs the firstboot scripts in this order: do_convert configure_firstboot configure_wait_pnp add_firstboot_script configure_vmdp add_firstboot_script configure_qemu_ga add_firstboot_script unconfigure_xenpv add_firstboot_script unconfigure_prltools add_firstboot_script unconfigure_vmwaretools add_firstboot_script configure_network_interfaces install_firstboot_powershell "v2vnetcf.ps1" add_firstboot_script -> the script that polls for "netkvm.sys" with Get-NetAdapter, then calls New-NetIPAddress Because of this, if the guest is supposed to have static IP address(es), they are set by the "v2vnetcf.ps1" firstboot script quite late during first boot. It's more comfortable for users if the network is usable from an earlier point of the first boot, so register "v2vnetcf.ps1" in priority group 2500 (the default is 5000), moving the script to the front. Suggested-by: Richard W.M. Jones <rjones at redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/convert_windows.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index fa2eae28a768..b53312a9aba4 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -739,8 +739,12 @@ let convert (g : G.guestfs) _ inspect _ static_ips add "" ) static_ips; - (* Install the Powershell script to run at firstboot. *) - Windows.install_firstboot_powershell g inspect psh_filename !psh + (* Install the Powershell script to run at firstboot. + * + * Place it first among the firstboot scripts (RHBZ#1788823). + *) + Windows.install_firstboot_powershell g inspect ~prio:2500 psh_filename + !psh ) (* static_ips <> [] *) and fix_ntfs_heads () -- 2.19.1.3.g30247aa5d201