Adding VirtIO drivers to Windows Recovery Environment (Windows RE)

How to customize your Windows System Restore

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…

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.

Requirements

  1. Windows VirtIO Drivers ISO (https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso)
  2. Windows Server 2019/2022 ISO, or its install.wim file
  3. 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).UniqueId
Code language: PowerShell (powershell)

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\winre
Code language: PowerShell (powershell)

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:

Dism /image:c:\mount\winre /Add-Driver /Driver:"F:\vioscsi\2k19\amd64\vioscsi.inf"
Code language: PowerShell (powershell)

Second driver is Red Hat VirtIO Ethernet Adapter (NetKVM) for networking:

Dism /image:c:\mount\winre /Add-Driver /Driver:"f:\NetKVM\2k19\amd64\netkvm.inf"
Code language: PowerShell (powershell)

You can verify the drivers were added using DISM /get-drivers and /get-driverInfo parameters. Here you see the vioscsi driver was added

PS C:\Users\janreilink> Dism /image:C:\mount\winre\ /get-driverInfo /driver:oem0.inf Deployment Image Servicing and Management tool Version: 10.0.17763.1697 Image Version: 10.0.17763.107 Driver package information: Published Name : oem0.inf Driver Store Path : C:\mount\winre\Windows\System32\DriverStore\FileRepository\vioscsi.inf_amd64_580a262bfd85344b\vioscsi.inf Class Name : SCSIAdapter Class Description : Storage controllers Class GUID : {4D36E97B-E325-11CE-BFC1-08002BE10318} Date : 8/30/2021 Version : 100.85.104.20800 Boot Critical : Yes Drivers for architecture : amd64 Manufacturer : Red Hat, Inc. Description : Red Hat VirtIO SCSI pass-through controller Architecture : amd64 Hardware ID : PCI\VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00 Service Name : vioscsi Compatible IDs : PCI\VEN_1AF4&DEV_1004 Exclude IDs : Manufacturer : Red Hat, Inc. Description : Red Hat VirtIO SCSI pass-through controller Architecture : amd64 Hardware ID : PCI\VEN_1AF4&DEV_1048&SUBSYS_11001AF4&REV_01 Service Name : vioscsi Compatible IDs : PCI\VEN_1AF4&DEV_1048 Exclude IDs : The operation completed successfully.
Code language: PowerShell (powershell)

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
Code language: PowerShell (powershell)

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
Code language: PowerShell (powershell)

It should otuput something like:

Saving image [==========================100.0%==========================] Unmounting image [==========================100.0%==========================] The operation completed successfully.
Code language: PowerShell (powershell)

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:

Get-ItemProperty C:\mount\windows2019\Windows\System32\Recovery\Winre.wim | select -ExpandProperty LastWriteTime Tuesday, November 23, 2021 9:38:37 AM
Code language: PowerShell (powershell)

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
Code language: PowerShell (powershell)

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
Code language: PowerShell (powershell)

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 C:\Recovery\WindowsRE\Winre.wim:

xcopy c:\mount\winre-optimized.wim C:\Recovery\WindowsRE\Winre.wim /h /r
Code language: PowerShell (powershell)
Sharing is caring
Show Buttons
Hide Buttons