Blob Blame History Raw
From 34a8b1a7115aeb95812ae8ee182055de757f3892 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= <tgolembi@redhat.com>
Date: Thu, 5 Mar 2020 15:37:13 +0100
Subject: [PATCH] windows: delay installation of qemu-ga MSI
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Instead of running firstboot script during early boot schedule a task
delayed for 2 minutes.

During the first boot, after virt-v2v conversion, Windows installs the
drivers injected by virt-v2v. When this installation is finished
Windows enforces some kind of internal reboot. This unfortunately
terminates any running firstboot scripts thus killing the installation
of qemu-ga MSI.

This is just a best-effort mitigation. It can still happen (e.g. with
slow disk drives) that the drivers are not yet installed when the
delayed installation starts. On the other hand we cannot delay it too
much otherwise we risk that the users logs in and will be doing some
work when the MSI installation starts. After MSI installation finishes
the VM needs to be rebooted which would be annoying if that would happen
under users hands. Although this is not a best fix (that may come later
as it is more complex, e.g. introducing waiting mechanism), the delay as
it is defined works in most cases. And it dramaticaly improves the
situations -- originaly I experienced more than 90% failure rate.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>

(cherry picked from commit dc66e78fa37db33e3c7358b7f7c7fa809cf62f9d
in virt-v2v)
---
 v2v/convert_windows.ml | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 43c1f85de..088cd33d9 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -428,16 +428,13 @@ popd
  and configure_qemu_ga files =
    List.iter (
      fun msi_path ->
-       let fb_script = "\
-echo Installing qemu-ga from " ^ msi_path ^ "
-\"\\" ^ msi_path ^ "\" /norestart /qn /l+*vx \"%~dpn0.log\"
-set elvl=!errorlevel!
-echo Done installing qemu-ga error_level=!elvl!
-if !elvl! == 0 (
-  echo Restarting Windows...
-  shutdown /r /f /c \"rebooted by firstboot script\"
-)
-" in
+       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); schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString('MM/dd/yyyy') /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;
     ) files
-- 
2.24.1