[libguestfs-common PATCH] mlcustomize/firstboot: take an optional priority in "add_firstboot_script"
Enable callers of "add_firstboot_script" to pass an (optional) priority parameter. With this, groups of scripts can be formed with well-defined (lexicographical) ordering between the groups. Within a group, the usual order of registration persists. Suggested-by: Richard W.M. Jones <rjones@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- mlcustomize/firstboot.mli | 16 ++++++++++++---- mlcustomize/firstboot.ml | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mlcustomize/firstboot.mli b/mlcustomize/firstboot.mli index fb30886184cc..e6a0d1f70102 100644 --- a/mlcustomize/firstboot.mli +++ b/mlcustomize/firstboot.mli @@ -16,16 +16,24 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) -val add_firstboot_script : Guestfs.guestfs -> string -> string -> string -> unit - (** [add_firstboot_script g root name content] adds a firstboot - script called [name] containing [content]. +val default_prio : int + +val add_firstboot_script : Guestfs.guestfs -> string -> ?prio:int -> string -> + string -> unit + (** [add_firstboot_script g root prio name content] adds a firstboot + script called [name] containing [content] with priority [prio]. [content] is the contents of the script, {b not} a filename. The actual name of the script on the guest filesystem is made of [name] with all characters but alphanumeric replaced with dashes. - The scripts are run in the order they are registered. + Within a given priority, the scripts are run in the order they are + registered. A group of scripts with a numerically lower priority is run + before a group with a numerically greater priority. If [prio] is omitted, + it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data). For Linux guests using SELinux you should make sure the filesystem is relabelled after calling this. *) diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index c3ebfd910d0b..18dc04efa2e6 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -345,12 +345,17 @@ end let script_count = ref 0 -let add_firstboot_script (g : Guestfs.guestfs) root name content = +let default_prio = 5000 + +let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = default_prio) name + content = + assert (prio >= 0 && prio <= 9999); let typ = g#inspect_get_type root in let distro = g#inspect_get_distro root in let major = g#inspect_get_major_version root in incr script_count; - let filename = sprintf "%04d-%s" !script_count (sanitize_name name) in + let filename = sprintf "%04d-%04d-%s" prio !script_count + (sanitize_name name) in match typ, distro with | "linux", _ -> Linux.install_service g root distro major; base-commit: 60efc5407552c12688a5e99b7a54d23d5990aa8f -- 2.19.1.3.g30247aa5d201
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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
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@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
On Tue, Mar 08, 2022 at 03:30:51PM +0100, Laszlo Ersek wrote:
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@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
Well that's a lot easier to read :-) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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 "\ -@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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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 "\ -@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
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@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 = "\ -@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
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@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 = "\ -@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
I couldn't spot any errors in the refactoring, so ACK 1-10. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
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@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
On Tue, Mar 08, 2022 at 03:30:58PM +0100, Laszlo Ersek wrote:
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.
I had a double-take with the "too to" (but it is correct). Maybe s/too/also/ or s/too//?
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
So this is a bit convoluted. I note you exposed default_prio in the Firstboot module which I was a little confused by, but now I see why you did it. However you didn't need to. You can instead do:
let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } - filename code = + ?prio filename code = ... - Firstboot.add_firstboot_script g i_root filename fb + Firstboot.add_firstboot_script g i_root ?prio filename fb
?prio has type 'int option'. So ACK with that change, and drop default_prio from Firstboot too. When pushing this patch, don't forget to update the common submodule in the same commit! Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
On 03/08/22 17:17, Richard W.M. Jones wrote:
On Tue, Mar 08, 2022 at 03:30:58PM +0100, Laszlo Ersek wrote:
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.
I had a double-take with the "too to" (but it is correct). Maybe s/too/also/ or s/too//?
Yes, I'll drop "too".
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
So this is a bit convoluted. I note you exposed default_prio in the Firstboot module which I was a little confused by, but now I see why you did it.
However you didn't need to. You can instead do:
let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } - filename code = + ?prio filename code = ... - Firstboot.add_firstboot_script g i_root filename fb + Firstboot.add_firstboot_script g i_root ?prio filename fb
?prio has type 'int option'.
Huh, this syntax is not in the book I've been consulting! So yes, this is exactly what I needed.
So ACK with that change, and drop default_prio from Firstboot too.
Yes.
When pushing this patch, don't forget to update the common submodule in the same commit!
I figured I'd push a submodule update first, but fusing it with this patch is more descriptive indeed. Thanks! Laszlo
Thanks,
Rich.
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@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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
On Tue, Mar 08, 2022 at 03:30:59PM +0100, Laszlo Ersek wrote:
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@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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 <> [] *)
ACK 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
On 03/08/22 17:19, Richard W.M. Jones wrote:
On Tue, Mar 08, 2022 at 03:30:59PM +0100, Laszlo Ersek wrote:
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@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@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 <> [] *)
ACK
Rich.
Merged the series as commit range 3a66d0fece08..5d24c1575750, with the following updates: 1: 570d94a81870 ! 1: bb952c113cf1 convert_linux: wrap overlong lines @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-2-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml --- a/convert/convert_linux.ml 2: fee83d7a0d6a ! 2: fb909fe761c4 convert_windows: wrap overlong lines @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-3-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 3: ee99a22b1b68 ! 3: e2995d10a5ee convert_linux: align shell script indentation with OCaml source code @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-4-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml --- a/convert/convert_linux.ml 4: 991624de3934 ! 4: 597d17756723 convert_windows: rewrite "configure_qemu_ga" script purely in PowerShell @@ -15,6 +15,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-5-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 5: 918d2cc869ea ! 5: 295b8ae74e33 convert_windows: align "reg_restore" batch file commands with OCaml source @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-6-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 6: 0f216c4351e3 ! 6: 423a009280b6 convert_windows: align "configure_wait_pnp" batch file with OCaml source @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-7-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 7: 74e1089a3774 ! 7: 1a63125af21d convert_windows: align "configure_vmdp" batch files with OCaml source @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-8-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 8: ad69b2cc19c5 ! 8: 4e4959037294 convert_windows: align "unconfigure_xenpv" batch file with OCaml source @@ -4,6 +4,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-9-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 9: 7b0004c90c6d ! 9: e3814222190c convert_windows: align "unconfigure_prltools" batch file with OCaml source @@ -7,6 +7,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-10-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 10: b2bdea6dcfab ! 10: 12648416c15d convert_windows: align "unconfigure_vmwaretools" batch file with OCaml src @@ -7,6 +7,8 @@ Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-11-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml 11: 981546f9f33c ! 11: 54b74413e86d convert/windows: expose "prio" parameter in install_firstboot_powershell @@ -4,11 +4,16 @@ 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. + around "Firstboot.add_firstboot_script", enable callers of the former to + set the script run priority. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-12-lersek@redhat.com> + [lersek@redhat.com: improve commit message language (Rich)] + [lersek@redhat.com: include hunk for submodule update (Rich)] + [lersek@redhat.com: forward optional parameter idiomatically (Rich)] + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/windows.mli b/convert/windows.mli --- a/convert/windows.mli @@ -33,8 +38,7 @@ *) let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } - filename code = -+ ?(prio = Firstboot.default_prio) filename -+ code = ++ ?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 @@ -43,4 +47,11 @@ 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 ++ Firstboot.add_firstboot_script g i_root ?prio filename fb + +diff --git a/common b/common +--- a/common ++++ b/common +@@ +-Subproject commit 60efc5407552c12688a5e99b7a54d23d5990aa8f ++Subproject commit ab708d11d832457d2a0c74e7a6d8c219a4fdd90f 12: 6117bd7cfc15 ! 12: 5d24c1575750 convert_windows: install "v2vnetcf.ps1" with prio 2500 @@ -35,6 +35,8 @@ Suggested-by: Richard W.M. Jones <rjones@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308143059.6384-13-lersek@redhat.com> + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml --- a/convert/convert_windows.ml Thanks Laszlo
This patch is fine, thanks ...
+ it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data).
... but I'm confused by what you meant by "is not expected to depend on external data"? Anyway, ACK 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/
On Tue, Mar 08, 2022 at 04:00:15PM +0000, Richard W.M. Jones wrote:
This patch is fine, thanks ...
+ it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data).
... but I'm confused by what you meant by "is not expected to depend on external data"?
Anyway, ACK
... but see my comment on patch 11: https://listman.redhat.com/archives/libguestfs/2022-March/028400.html Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
On 03/08/22 17:18, Richard W.M. Jones wrote:
On Tue, Mar 08, 2022 at 04:00:15PM +0000, Richard W.M. Jones wrote:
This patch is fine, thanks ...
+ it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data).
... but I'm confused by what you meant by "is not expected to depend on external data"?
Anyway, ACK
... but see my comment on patch 11:
https://listman.redhat.com/archives/libguestfs/2022-March/028400.html
I've pushed the patch as commit ab708d11d832 with the following updates: 1: 70d06d85099b ! 1: ab708d11d832 mlcustomize/firstboot: take an optional priority in "add_firstboot_script" @@ -10,6 +10,10 @@ Suggested-by: Richard W.M. Jones <rjones@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek@redhat.com> + Message-Id: <20220308142922.6267-1-lersek@redhat.com> + [lersek@redhat.com: s/external data/user input/ in MLI docs (Rich)] + [lersek@redhat.com: remove "default_prio", open-code prio 5000 (Rich)] + Acked-by: Richard W.M. Jones <rjones@redhat.com> diff --git a/mlcustomize/firstboot.mli b/mlcustomize/firstboot.mli --- a/mlcustomize/firstboot.mli @@ -21,8 +25,6 @@ -val add_firstboot_script : Guestfs.guestfs -> string -> string -> string -> unit - (** [add_firstboot_script g root name content] adds a firstboot - script called [name] containing [content]. -+val default_prio : int -+ +val add_firstboot_script : Guestfs.guestfs -> string -> ?prio:int -> string -> + string -> unit + (** [add_firstboot_script g root prio name content] adds a firstboot @@ -37,9 +39,9 @@ + Within a given priority, the scripts are run in the order they are + registered. A group of scripts with a numerically lower priority is run + before a group with a numerically greater priority. If [prio] is omitted, -+ it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 -+ or greater than 9999, an Assert_failure is raised (the [prio] parameter -+ is not expected to depend on external data). ++ it is taken as 5000. If [prio] is smaller than 0 or greater than 9999, an ++ Assert_failure is raised (the [prio] parameter is not expected to depend ++ on user input). For Linux guests using SELinux you should make sure the filesystem is relabelled after calling this. *) @@ -52,9 +54,7 @@ let script_count = ref 0 -let add_firstboot_script (g : Guestfs.guestfs) root name content = -+let default_prio = 5000 -+ -+let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = default_prio) name ++let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = 5000) name + content = + assert (prio >= 0 && prio <= 9999); let typ = g#inspect_get_type root in Thans, Laszlo
On 03/08/22 17:00, Richard W.M. Jones wrote:
This patch is fine, thanks ...
+ it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data).
... but I'm confused by what you meant by "is not expected to depend on external data"?
In general, no assert() condition should depend on user-controlled data; assert() is for catching programming bugs. If user input can lead to the falsification of a condition (invariant etc), then that needs to be caught with a different tool -- throw a different exception, report an error, etc. So the idea here is that the priority should never depend on user input. (For example: in case the priority parameter were exposed by virt-customize's --firstboot* options in the future, then the assert() would no longer be OK. A different kind of exception would be necessary.)
Anyway, ACK
Thanks! Laszlo
participants (2)
-
Laszlo Ersek -
Richard W.M. Jones