Windows install virtio then reboot met BSOD

Scope

This blog is a practice search about windows virtio driver installation.

Backgroud

For virtualization software, normally guest will install virtio related drivers to get better virtualization performance. But instll virtio driver to windows guest sometimes became complex, so many softwares offer a practice guide about virtio dirver installation

Software practice guide
Proxmox https://pve.proxmox.com/wiki/Windows_VirtIO_Drivers
https://pve.proxmox.com/wiki/Windows_10_guest_best_practices
IBM Cloud orchestrator https://www.ibm.com/docs/en/cloud-orchestrator/2.5.0.3?topic=images-installing-virtio-driver-kvm-hypervisor-only

the guide introduce that how to install virtio driver from win-virtio.iso while lauch windows install.

But in practice, if user want install driver to exists guest, windows still get BSOD after virtio driver installed.

So I write this blog to solve related problems.

Newly virtio driver installation

Windows running root disk attached to ide controller and install virtio driver. Then stop guest and move the disk from ide controller to virtio-serial controller, start guest will meet BSOD (no accessible boot device).

This is because windows do not load the virtio controller when install virtio driver to running vm.

According to P2V practice, how to inject virtio driver to a guest https://portal.nutanix.com/page/documents/kbs/details?targetId=kA00e000000kAWeCAM

we need manually load driver

1
drvload vioser.inf

then install the driver to disk where windows installed:

1
dism /image:c:\ /add-driver /driver:vioscsi.inf

but if you try to do this on a running windows vm, dism will tell you that this operation is not allowed on a running windows. So the kv tell user to do the operation through cmd prompt when windows failed to boot not convinence if there are many guest need do this.

from superuser https://superuser.com/questions/1057959/windows-10-in-kvm-change-boot-disk-to-virtio/1253728#1253728

other solution is raised, the best one is by setting guest into safeboot mode

1
bcdedit /set "{current}" safeboot minimal

windows will load all drivers then change the disk controller seems make sense, but still manually operation is required.

A tricky way is noticed by adding a dummy virtio disk to windows and then install virtio driver, the controller will be loaded at first.

the following steps I followed:

  1. Install the virtio driver in windows
  2. Add a additional “dummy” virtio disk. Reboot and check if the “dummy” works.
  3. If Step 2 works, then switch the boot disk to virtio.
  4. Reboot
  5. Remove the additional “dummy” virtio disk

because we do not need to do more operation inside guest, so this solution can be changed to a automatic way.

And more discussion can be found on reddit:

Looks like you’re having the issue of windows refusing to load the virtio storage drivers at boot.

The only thing I found that works for me is using this method - https://superuser.com/a/1200899. You can also try this method of adding another disk and installing the driver but I personally found that to be very hit and miss.

For the first method you need to use diskpart to assign drive letters to your windows drive and virtio iso this tutorial should help if you don’t know how to do it.

but luckily,

You need to install the virtio drivers on a per storage device basis.

I suggest swapping back to sata and add a empty virtio device to your guest. Then boot and install the virtio driver for the new the device. Last step is to delete the old sata device and mount the device image at the virtio device and boot your guest.

Make sure that libvirt didn’t changed the pcie address of your virtio device as windows registers the driver on a per device basis.

the dummy disk work around can be used because the pci address acutally reused (as the virtio device will be removed and reboot)

This method works well when virtio drivers are newly added, but if you have booted guest with virtio driver installed, change the controller from ide to virtio is complex.

We prefer user to install virtio driver during first windows intallation and make it as a image to avoid controller change.

Virtio driver already installed

While virtio already installed and reboot windows and the disk controller not changed. After reboot the boot disk is still ide.

If you attach virtio-blk disk to guest, it will be recognized and loaded right now.

But if follow the steps below to attach a dummy disk (in this case you attached a virtio-blk disk actually), change the ide controller to virtio will not work, windows kept report BSOD after changed.

Work around is uninstall the virtio driver and reinstall with the steps than reboot every will works.

I think maybe windows only load all drivers which are newly installed. But for existing driver, it only works per disk basis.

Virtio-scsi always works

Cheerfully, if you change the ide/sata controller to virtio-scsi controller after virtio driver installed, windows works well.

More performance test is needed because we kept use virtio-blk for root disk due to some version of virtio driver offered virtio-scsi has bad performance.