How can I dual-boot the same (UEFI) Windows install from the metal as well as from qemu-kvm?

0

The initial setup involves a machine that can dual-boot Fedora and Windows 10. GRUB can find both OSs and there is an entry in GRUB to chainload the Windows Boot Manager that has the Windows OS available.

I am trying to ditch dual-boot for qemu-kvm with VGA Passthrough, and my final goal is to achieve near-native performance with Windows for graphics-intensive purposes, while being able to firewall/monitor/NAT the Windows install from Fedora (via iptables on the bridged ethernet interface).

Both OSs are currently installed in the same hard drive, this is my blkid without IDs:

/dev/sda1: LABEL="ESP" TYPE="vfat" PARTLABEL="EFI System Partition"
/dev/sda2: LABEL="LEGACYWIN" TYPE="ntfs" PARTLABEL="Microsoft basic data"
/dev/sda3: TYPE="ntfs" PARTLABEL="Microsoft basic data"
/dev/sda4: TYPE="LVM2_member" PARTLABEL="Linux LVM"
/dev/sda5: LABEL="W10" TYPE="ntfs" PARTLABEL="Microsoft basic data"
/dev/sda6: TYPE="ext4"
/dev/sda7: TYPE="swap"
/dev/mapper/fedora-root: TYPE="ext4"
/dev/mapper/fedora-home: TYPE="ext4"

LEGACYWIN is an old Windows install that is sitting waiting to be removed, never mind it.

I could have mounted a loop interface with the appropriate offsets for each partition and override the ESP partition with a shadow copy to avoid corrupting it from having it open on Fedora, but instead I just unmounted /boot/efi from Fedora and I'm mounting the whole drive as the following:

<domain>
  <devices>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source dev='/dev/sda'/>
      <target dev='sda' bus='sata'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
  </devices>
</domain>

I'm using unit 1 instead of unit 0 because in the real hardware the disk sits too in the 2nd SATA port of the motherboard. On the metal there are two DVD drives attached, and in qemu too (I'm among the last people in the world with dual DVD drives still in working condition).

On the real hardware everything works as expected.

On qemu, the GRUB loader boots, and if I select Windows (I have disabled savedefault so that GRUB does not need to write stuff to disk either) the Windows Boot Manager fires and a BSOD appears saying:

After multiple tries, the operating system on your PC failed to start, so it needs to be repaired.

Error code: 0xc0000001

Still, if I restart the machine, I can cold-boot Windows successfully.

I reboot the qemu domain and boot it from a Windows 10 ISO and click Repair.

If I click on DaRT, I see all options available, which means that the install disk could find my Windows install.

If I go back, and go to cmd.exe, after trying all possible combinations of bootrec and bcdedit within the VM, I still find I can boot from the metal, but not from qemu, interestingly enough.

I tried destroying completely the EFI/Microsoft folder and recreating it with bootrec.exe and also the following things:

> diskpart # to open diskpart
diskpart> sel vol 5 # The ESP volume
diskpart> assign letter s # To see the ESP in cmd
diskpart> exit
> dir s: # The EFI folder is there alongside everything
> bcdedit /store S:\EFI\Microsoft\Boot\BCD /v

-

Windows Boot Manager
--------------------
Identifier              {x-x-x-x-x}
device                  partition=S:
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  en-us
inherit                 {a-a-a-a-a}
default                 {y-y-y-y-y}
resumeobject            {y-y-y-y-y}
displayorder            {y-y-y-y-y}
toolsdisplayorder       {z-z-z-z-z}
timeout                 30

Windows Boot Loader
-------------------
Identifier              {y-y-y-y-y}
device                  partition=E:
path                    \windows\system32\winload.efi
description             Windows 10
locale                  en-us
inherit                 {b-b-b-b-b}
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=E:
systemroot              \windows
resumeobject            {y-y-y-y-y}
nx                      OptIn
bootmenupolicy          Standard

How can I better debug what is happening, or is there a better way to get this done?

I made it work at some point, but after switching to virtio drives, even switching back to sata drives won't do the trick anymore to boot Windows inside qemu (although Windows still boots fine when on the metal). So, it's probably not hardware-related.

The whole domain xml is available in a gist.

windows-10
qemu
linux-kvm
bcd
libvirt
asked on Super User Apr 17, 2019 by ssice

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0