If you need to add VirtIO drivers to your Windows Recovery Environment (Windows RE) to recover your Windows virtual machine, here is how. The following steps come in handy if you found out the hard way you don’t see any disks in Windows RE after a hard crash. As have I…
Windows Recovery Environment (Windows RE)
Windows Recovery Environment (WinRE) is a recovery environment that can repair common causes of unbootable operating systems. WinRE is based on Windows Preinstallation Environment (Windows PE), and can be customized with additional drivers, languages, Windows PE Optional Components, and other troubleshooting and diagnostic tools. By default, WinRE is preloaded into the Windows 10 and Windows 11 for desktop editions (Home, Pro, Enterprise, and Education) and Windows Server 2016, and later, installations.
Customize your Windows System Restore (how-to)
The following steps worked for me repeatedly to create a new
Winre.wim image file with additional VirtIO drivers: vioscsi and netkvm. I could easily copy the new image over the existing
C:\Recovery\WindowsRE\Winre.wim file, and reboot into Windows RE to verify it worked. All steps come from Microsofts Customize Windows RE documentation, I merely added some additional information.
In a nutshell,
virtio is an abstraction layer over devices in a paravirtualized hypervisor. Virtio was developed as a standardized open interface for virtual machines (VMs) to access simplified devices such as block devices and network adaptors.
- Windows VirtIO Drivers ISO (https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso)
- Windows Server 2019/2022 ISO, or its install.wim file
- winre.wim file, extracted from install.wim (see below)
You can extract the contents of your Windows Server and VirtIO drivers ISO to a location on a file server (which is preferable), or you can mount them using DISM:
$virtioImg = Mount-DiskImage -ImagePath \\fileserver\path\to\drivers\virtio-win\virtio-win-0.1.208.iso -NoDriveLetter mountvol "F:" $($virtioImg | Get-Volume).UniqueId $winservImg = Mount-DiskImage -ImagePath \\fileserver\path\to\iso\2022\SW_DVD9_Win_Server_STD_CORE_2022__64Bit_English_DC_STD_MLF_X22-74290.ISO -NoDriveLetter mountvol "G:" $($winservImg | Get-Volume).UniqueIdCode language: PHP (php)
Now you have your VirtIO drivers available on driver letter F:, and your Windows Server ISO on G:.
If you mount Windows Server ISO, you cannot commit changes back into the .ISO file, as it’s read-only. So extracting its contents is preferable. This is what I have done for this guide. Let’s continue.
Step 1: Mount all .WIM images using DISM
First you need to mount your .WIM image files into a location, because winre.wim resides within install.wim. The following steps copies your existing install.wim file to c:\mount, mounts it into c:\mount\windows2019 and mounts winre.wim into c:\mount\winre.
md c:\mount md c:\mount\windows2019 md C:\mount\winre Copy-Item G:\Sources\install.wim C:\mount\ # if necessary, remove the read-only flag attrib C:\mount\install.wim -r Dism /Mount-Image /ImageFile:C:\mount\install.wim /Index:1 /MountDir:C:\mount\windows2019 Dism /Mount-Image /ImageFile:C:\mount\windows2019\windows\system32\recovery\winre.wim /Index:1 /MountDir:C:\mount\winreCode language: PHP (php)
Step 2: Add Red Hat VirtIO SCSI pass-through controller (vioscsi) driver to the image using DISM
Now you have mounted all WIM files, you can start adding drivers. First one up is Red Hat VirtIO SCSI pass-through controller (vioscsi) driver:
Second driver is Red Hat VirtIO Ethernet Adapter (NetKVM) for networking:
You can verify the drivers were added using DISM /get-drivers and /get-driverInfo parameters. Here you see the vioscsi driver was added
Neat, heh :)
Step 3: Optimize the image
This step is not really required, but it’s time to optimize the image and shave off some bytes.
Dism /Image:c:\mount\winre /Cleanup-Image /StartComponentCleanup
When this command finishes, you need to unmount the WinRE image
Step 4: Unmount WinRE image and commit changes
If you want to save the new WinRE image, you must unmount it and commit the changes:
Dism /Unmount-Image /MountDir:C:\mount\winre /Commit
It should otuput something like:
Saving image [==========================100.0%==========================] Unmounting image [==========================100.0%==========================] The operation completed successfully.Code language: CSS (css)
Next you can verify the last write date of the file to make sure it was written correctly:
Get-ItemProperty C:\mount\windows2019\Windows\System32\Recovery\Winre.wim | select -ExpandProperty LastWriteTime Tuesday, November 23, 2021 9:38:37 AM
Step 4: Optimize WinRE image, part 2
You can also optimize an image by exporting to a new image file, using the export-image parameter. So export the Windows RE image into a new Windows image file and replace the old Windows RE image with the newly-optimized image.
Dism /Export-Image /SourceImageFile:c:\mount\windows2019\windows\system32\recovery\winre.wim /SourceIndex:1 /DestinationImageFile:c:\mount\winre-optimized.wim del c:\mount\windows2019\windows\system32\recovery\winre.wim copy c:\mount\winre-optimized.wim c:\mount\windows2019\windows\system32\recovery\winre.wim
Step 5: Unmount the Windows install image
Last but not least, unmount the Winodws install image and commit the changes (e.g the new winre.wim file):
Dism /Unmount-Image /MountDir:C:\mount\windows2019 /Commit
Depending on where you got your install.wim image from, you either need to create a new ISO, copy the file into an unpacked ISO location (
\Sources dir), or copy and overwrite
xcopy c:\mount\winre-optimized.wim C:\Recovery\WindowsRE\Winre.wim /h /r
Test and boot into Windows RE using REAgentC
To manually boot into the Windows Recovery Environment you can use REAgentC.exe tool if you’re unable to press a function key during boot. For example in a cloud environment.
You can use the REAgentC.exe tool to configure a Windows Recovery Environment (Windows RE) boot image and a push-button reset recovery image, and to administer recovery options and customizations. REAgentC comes with Windows, and you can run the REAgentC command on an offline Windows image or on a running Windows operating system.REAgentC command-line options
In your administrative shell, execute the following REAgentC command:
reagentc /boottoreCode language: PowerShell (powershell)
Followed by a shutdown / reboot command:
shutdown /r /f /t 0.
You can also reboot the computer in WinRE mode from the command prompt using the
-o parameter of the shutdown command:
shutdown /f /r /o /t 0. But this cannot be executed when connected through RDP (“The parameter is incorrect (87)” appears).
Show Your Support
If you want to step in to help me cover the costs for running this website, that would be awesome. Just use this link to donate a cup of coffee ☕($10 USD or €10 EUR for example). And please share the love and help others make use of this website. Thank you very much! <3 ❤️