[PATCH 0/2] Delay firstboot scripts to some later time
When firstboot is used from virt-v2v the scripts, if not fast enough, can get killed by Windows. After windows installs virtio drivers injected by virt-v2v it performs some internall reboot, stopping all the running services and killing any running firstboot script. This is problem mostly for MSI installs (like qemu-ga that was added recently) that can take several seconds to finish. This change is little bit controversial in fact that it relies on powershell. This is not available in early versions (without service packs) of XP and 2003 and our support matrix still mentions these Windows versions. The change can also be problem for those who really wish to perform an action early in the boot... if there are such users. Tomáš Golembiovský (2): firstboot: use absolute path to rhsrvany firstboot: schedule firstboot as delayed task mlcustomize/firstboot.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.24.0
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- mlcustomize/firstboot.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index a8f4ef7..c3ebfd9 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -307,7 +307,7 @@ for %%%%f in (\"%%scripts%%\"\\*.bat) do ( ) echo uninstalling firstboot service -%s -s firstboot uninstall +\"%%firstboot%%\\%s\" -s firstboot uninstall " firstboot_dir_win srvany in g#write (firstboot_dir // "firstboot.bat") -- 2.24.0
On Thu, Nov 21, 2019 at 12:04:17PM +0100, Tomáš Golembiovský wrote:
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- mlcustomize/firstboot.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index a8f4ef7..c3ebfd9 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -307,7 +307,7 @@ for %%%%f in (\"%%scripts%%\"\\*.bat) do ( )
echo uninstalling firstboot service -%s -s firstboot uninstall +\"%%firstboot%%\\%s\" -s firstboot uninstall " firstboot_dir_win srvany in
g#write (firstboot_dir // "firstboot.bat")
I have pushed this one. It will need an update to libguestfs and/or virt-v2v in order to pick up the change, which I'll roll into a later change. Thanks, 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
Instead of running firstboot scripts during early boot schedule a task delayed for 1-2 minute. During the first boot, after virt-v2v conversion, Windows installs the drivers injected by virit-v2v. When this installation is finished Windows enforces some kind of internal reboot. This unfortunately terminates any running firstboot scritps thus killing for example the installation of qemu-ga MSI. Hopefully delaying the installtion to some later time can also fix problem we sometimes saw on Windows 2012R2 when installing RHEV-APT, where the installer terminated immediately with the error: Failed to connect to server. Error: 0x8007045B Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- mlcustomize/firstboot.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index c3ebfd9..b4ca181 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -286,10 +286,18 @@ set log=%%firstboot%%\\log.txt set scripts=%%firstboot%%\\scripts set scripts_done=%%firstboot%%\\scripts-done -call :main >> \"%%log%%\" 2>&1 +call :main %%1 >> \"%%log%%\" 2>&1 exit /b :main + +if not '%%1' == 'real' ( + REM schedule delayed task + schtasks.exe /Delete /TN Firstboot /F + powershell.exe -command \"$d = (get-date).AddSeconds(119); schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString('MM/dd/yyyy') /RU SYSTEM /TN Firstboot /TR \\\"%%~dpnx0 real\\\"\" + exit /b +) + echo starting firstboot service if not exist \"%%scripts_done%%\" ( -- 2.24.0
On Thu, Nov 21, 2019 at 12:04:18PM +0100, Tomáš Golembiovský wrote:
Instead of running firstboot scripts during early boot schedule a task delayed for 1-2 minute.
During the first boot, after virt-v2v conversion, Windows installs the drivers injected by virit-v2v. When this installation is finished Windows enforces some kind of internal reboot. This unfortunately terminates any running firstboot scritps thus killing for example the installation of qemu-ga MSI.
Hopefully delaying the installtion to some later time can also fix problem we sometimes saw on Windows 2012R2 when installing RHEV-APT, where the installer terminated immediately with the error:
Failed to connect to server. Error: 0x8007045B
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- mlcustomize/firstboot.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index c3ebfd9..b4ca181 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -286,10 +286,18 @@ set log=%%firstboot%%\\log.txt set scripts=%%firstboot%%\\scripts set scripts_done=%%firstboot%%\\scripts-done
-call :main >> \"%%log%%\" 2>&1 +call :main %%1 >> \"%%log%%\" 2>&1 exit /b
:main + +if not '%%1' == 'real' ( + REM schedule delayed task + schtasks.exe /Delete /TN Firstboot /F + powershell.exe -command \"$d = (get-date).AddSeconds(119); schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString('MM/dd/yyyy') /RU SYSTEM /TN Firstboot /TR \\\"%%~dpnx0 real\\\"\" + exit /b +) + echo starting firstboot service
I have really no clue about this. What is "~dpnx0"? I wwill say that in general we do need a way that we can order firstboot scripts so that some run before others. At the moment the Windows static IP script sometimes runs before the network device is created (see https://bugzilla.redhat.com/1788823). I guess we could hack that by making the sleep time above settable when registering a firstboot script, but what we really need is some kind of dependency system. I have no idea if Windows has a mechanism to do this already. 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/
What is "~dpnx0"?
That is a series of substitutions of batch parameter. Here is Microsoft doc: https://docs.microsoft.com/en-us/windows-server/administration/windows-comma... And here is more clear step-by-step explanation: https://stackoverflow.com/a/3679781/716075 -- Mykola Ivanets
On Tue, 11 Feb 2020 14:36:24 +0000 "Richard W.M. Jones" <rjones@redhat.com> wrote:
On Thu, Nov 21, 2019 at 12:04:18PM +0100, Tomáš Golembiovský wrote:
Instead of running firstboot scripts during early boot schedule a task delayed for 1-2 minute.
During the first boot, after virt-v2v conversion, Windows installs the drivers injected by virit-v2v. When this installation is finished Windows enforces some kind of internal reboot. This unfortunately terminates any running firstboot scritps thus killing for example the installation of qemu-ga MSI.
Hopefully delaying the installtion to some later time can also fix problem we sometimes saw on Windows 2012R2 when installing RHEV-APT, where the installer terminated immediately with the error:
Failed to connect to server. Error: 0x8007045B
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- mlcustomize/firstboot.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index c3ebfd9..b4ca181 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -286,10 +286,18 @@ set log=%%firstboot%%\\log.txt set scripts=%%firstboot%%\\scripts set scripts_done=%%firstboot%%\\scripts-done
-call :main >> \"%%log%%\" 2>&1 +call :main %%1 >> \"%%log%%\" 2>&1 exit /b
:main + +if not '%%1' == 'real' ( + REM schedule delayed task + schtasks.exe /Delete /TN Firstboot /F + powershell.exe -command \"$d = (get-date).AddSeconds(119); schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString('MM/dd/yyyy') /RU SYSTEM /TN Firstboot /TR \\\"%%~dpnx0 real\\\"\" + exit /b +) + echo starting firstboot service
I have really no clue about this.
What is "~dpnx0"?
I wanted to documented that in a comment at first. But then I decided against that as it seemed that as it seemed such patterns are used in multiple places in the code (ergo everyone knows). Looking now I see two occurrence in convert_windows.ml and one in firstboot.ml. I guess picking one of those for the comment should be enough.
I wwill say that in general we do need a way that we can order firstboot scripts so that some run before others. At the moment the Windows static IP script sometimes runs before the network device is created (see https://bugzilla.redhat.com/1788823). I guess we could hack that by making the sleep time above settable when registering a firstboot script, but what we really need is some kind of dependency system. I have no idea if Windows has a mechanism to do this already.
Such ordering or dependency mechanism would be nice, but I guess that's beyond what command line tools provide. Maybe we could script that to some degree if we turn the main firstboot script completely into PowerShell. But that would mean opening a can of worms. Tomas
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/
-- Tomáš Golembiovský <tgolembi@redhat.com>
I have really no clue about this.
What is "~dpnx0"?
I wanted to documented that in a comment at first. But then I decided against that as it seemed that as it seemed such patterns are used in multiple places in the code (ergo everyone knows).
Looking now I see two occurrence in convert_windows.ml and one in firstboot.ml. I guess picking one of those for the comment should be enough.
For completeness, "~dpnx0" expands into the name of the running script (0) with full path (p), including drive letter (d) and filename (n) with extension (x). Tomas
On Thu, Feb 13, 2020 at 02:07:07PM +0100, Tomáš Golembiovský wrote:
I have really no clue about this.
What is "~dpnx0"?
I wanted to documented that in a comment at first. But then I decided against that as it seemed that as it seemed such patterns are used in multiple places in the code (ergo everyone knows).
Looking now I see two occurrence in convert_windows.ml and one in firstboot.ml. I guess picking one of those for the comment should be enough.
For completeness, "~dpnx0" expands into the name of the running script (0) with full path (p), including drive letter (d) and filename (n) with extension (x).
You asked me on IRC about this one - sorry I wasn't reading IRC today, trying to get some programming done :-) Basically my position is that changes to the core firstboot functionality (ie. in this mlcustomize module) are highly risky. I don't claim to understand the implications of this change, and don't have time to research or test it properly myself. I do know that we want to change how firstboot is done (a) to make it more robust against things like reboots that happen in the middle, (b) to allow firstboot scripts to be prioritised in some way, and possibly (c) to allow dependencies between firstboot scripts. So I think there are two ways to go here: (1) Try to make the change only in virt-v2v. (2) Fix issues (a), (b) and (c) above, prove that it works, and submit a patch which does all that. Obviously (2) would be great but is a ton of work. 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
BTW, I don't see any problem with depending on Powershell for this, if it makes things easier. 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
participants (3)
-
Nikolay Ivanets -
Richard W.M. Jones -
Tomáš Golembiovský