Fix installation of drivers on firstboot with pending reboots

resolves: RHEL-100682
This commit is contained in:
Richard W.M. Jones 2025-07-13 13:01:11 +01:00
parent 4aed9b6a40
commit 27e99401af
2 changed files with 113 additions and 2 deletions

View File

@ -0,0 +1,108 @@
From f93106129586d21c5326445b730113744d140ebd Mon Sep 17 00:00:00 2001
From: Vadim Rozenfeld <vrozenfe@redhat.com>
Date: Thu, 10 Jul 2025 10:12:56 +1000
Subject: [PATCH] Modify configure_pnputil_install script to check pending
reboot status and report PnPUtil execution status
This change adds checks for system reboot status and reports
the result of PnPUtil driver installation attempt.
Related: https://issues.redhat.com/browse/RHEL-100682
Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
RWMJ:
Cherry picked from commit 594b05d6940c8719167d10c0cdfaa253349060ab.
I also updated the common submodule to cherry pick
libguestfs-common commit b40e534fefb74af32bd496904e44ce9bca1a7b34
---
common | 2 +-
convert/convert_windows.ml | 48 +++++++++++++++++++++++++++++++++++---
2 files changed, 46 insertions(+), 4 deletions(-)
Submodule common 3873d593..b48c7d00:
diff --git a/common/mlcustomize/firstboot.ml b/common/mlcustomize/firstboot.ml
index 6aca4c34..5f2642b0 100644
--- a/common/mlcustomize/firstboot.ml
+++ b/common/mlcustomize/firstboot.ml
@@ -305,13 +305,19 @@ if not exist \"%%scripts_done%%\" (
:: Pick the next script to run.
for %%%%f in (\"%%scripts%%\"\\*.bat) do (
echo running \"%%%%f\"
- move \"%%%%f\" \"%%scripts_done%%\"
- pushd \"%%scripts_done%%\"
+ pushd \"%%scripts%%\"
call \"%%%%~nf\"
set elvl=!errorlevel!
echo .... exit code !elvl!
popd
+ if !elvl! NEQ 249 (
+ echo Script succeeded, moving to scripts-done
+ move \"%%%%f\" \"%%scripts_done%%\"
+ ) else (
+ echo Script failed, will retry on next boot
+ )
+
:: Reboot the computer. This is necessary to free any locked
:: files which may prevent later scripts from running.
shutdown /r /t 0 /y
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
index 7434ac69..a9ec276a 100644
--- a/convert/convert_windows.ml
+++ b/convert/convert_windows.ml
@@ -396,9 +396,51 @@ let convert (g : G.guestfs) source inspect i_firmware
and configure_pnputil_install () =
let fb_script = "@echo off\n\
\n\
- echo Wait for VirtIO drivers to be installed\n\
- %systemroot%\\Sysnative\\PnPutil -i -a \
- %systemroot%\\Drivers\\Virtio\\*.inf" in
+ setlocal EnableDelayedExpansion\n\
+ set inf_dir=%systemroot%\\Drivers\\Virtio\\\n\
+ echo Installing drivers from %inf_dir%\n\
+ set REBOOT_PENDING=0\n\
+ \n\
+ timeout /t 10 /nobreak\n\
+ \n\
+ reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired\"\n\
+ if %errorlevel%==0 (\n\
+ echo Windows Update: Reboot required.\n\
+ set REBOOT_PENDING=1\n\
+ )\n\
+ \n\
+ reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending\"\n\
+ if %errorlevel%==0 (\n\
+ echo CBS: Reboot required.\n\
+ set REBOOT_PENDING=1\n\
+ )\n\
+ \n\
+ reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\" /v PendingFileRenameOperations\n\
+ if %errorlevel%==0 (\n\
+ echo Session Manager: Reboot required.\n\
+ set REBOOT_PENDING=1\n\
+ )\n\
+ \n\
+ if \"%REBOOT_PENDING%\"==\"1\" (\n\
+ echo A reboot is pending.\n\
+ exit /b 249\n\
+ ) else (\n\
+ echo No pending reboot detected.\n\
+ )\n\
+ \n\
+ for %%f in (\"%inf_dir%*.inf\") do (\n\
+ echo Installing: %%~nxf.\n\
+ %systemroot%\\Sysnative\\PnPutil -i -a \"%%f\"\n\
+ if !errorlevel! NEQ 0 (\n\
+ echo Failed to install %%~nxf.\n\
+ exit /b 249\n\
+ ) else (\n\
+ echo Successfully installed %%~nxf.\n\
+ )\n\
+ )\n\
+ echo All drivers installed successfully.\n\
+ exit /b 0\n\
+ )" in
(* Set priority higher than that of "network-configure" firstboot script. *)
Firstboot.add_firstboot_script g inspect.i_root ~prio:2000

View File

@ -8,7 +8,7 @@
Name: virt-v2v
Epoch: 1
Version: 2.7.1
Release: 13%{?dist}
Release: 14%{?dist}
Summary: Convert a virtual machine to run on KVM
License: GPL-2.0-or-later AND LGPL-2.0-or-later
@ -84,6 +84,7 @@ Patch0053: 0053-docs-Remove-old-paragraph-about-a-bug-in-Grub.patch
Patch0054: 0054-Add-new-virt-v2v-open-tool.patch
Patch0055: 0055-docs-Document-io-vddk-file-in-the-main-options-listi.patch
Patch0056: 0056-vddk-Remove-io-vddk-noextents-option.patch
Patch0057: 0057-Modify-configure_pnputil_install-script-to-check.patch
%if !0%{?rhel}
# libguestfs hasn't been built on i686 for a while since there is no
@ -387,7 +388,7 @@ make -C tests TESTS=test-fedora-luks-on-lvm-conversion.sh check
%changelog
* Wed Jul 09 2025 Richard W.M. Jones <rjones@redhat.com> - 1:2.7.1-13
* Sun Jul 13 2025 Richard W.M. Jones <rjones@redhat.com> - 1:2.7.1-14
- mlcustomize: Remove dnf --verbose option
resolves: RHEL-83289
- Print blkhash of converted image in virt-v2v debugging output
@ -406,6 +407,8 @@ make -C tests TESTS=test-fedora-luks-on-lvm-conversion.sh check
resolves: RHEL-88985
- Remove virt-v2v -io vddk-noextents=true option
resolves: RHEL-102618
- Fix installation of drivers on firstboot with pending reboots
resolves: RHEL-100682
* Tue Feb 25 2025 Richard W.M. Jones <rjones@redhat.com> - 1:2.7.1-5
- Rebase to upstream development version 2.7.1