ReactOS O.4.7 Dev - Qemu 2.10.1 - KVM - PCI passthrough - VGA Passthrough

ReactOS in a Virtual Machine with access to a real keyboard/mouse, real sound card and a real GPU

Info:My blog: http://www.davidgis.fr ,
Author: David TECHER, <davidtecher@yahoo.fr>
Date: 2017-10-26
Revision: 299-074205

Note

Some notes about this project

Table of contents

Warning

warning As of date of writting this document,

1   Video : Silent Installation using unattended installation ISO CD (English subtitles)

In video below we want to set up a virtual machine hosting ReactOS. We want to perform a silent installation. This installation is done using an unattended ISO CD with all drivers.

Note

If you want more information on how to set up this kind of ISO then please refer to ReactOS wiki 1 and 2

Devices listed below are attached to the virtual machine.

2   KEEP IN MIND THAT ...

2.1   IT CAN BREAK YOUR OWN HARDWARE!!!

Yes this is a real drawback when you want to test this. Since I was curious to know if it works that's the reason why I bought a workstation on ebay to test it. I own my own hardware for Qemu/KVM.

The main reason is that it works with NVIDIA cards that it supposed to be Multi OS: Quadro 6000, Quadro 5000, 4800, 4000 and 2000.

Doing some researches on the Internet it seems to work with other cards too

Moreover ReactOS should work with pretty old cards.

Unfortunately Qemu/KVM is known to have some drawbacks with pretty olds cards.

In my case for my Quadro FX 4800, I had to

  • from the BIOS: switch off all USB devices
  • from the BIOS: switch off the IGD. No second screen

Quadro cards were set up for Professional Workstation.

so Qemu + Quadro can imply consumption issue if IGD is not switched off!!!

2.2   THERE WILL BE NO HARDWARE ACCELERATION FOR 3D

ReactOS development is pretty slow. When using native driver, hardware acceleration is disabled :(

3   Hardware

3.1   Host

Host is a HP Compag DC 7900 -- a pretty well-known workstation if you want to set up a hackintosh --. This workstation was bought on ebay for less than 100€

Model = Hewlett-Packard HP Compaq dc7900 Convertible Minitower/3032h

Component Comments
CPU Intel Core 2 Duo E8500 3.16Ghz. This CPU has the expected features for Qemu/KVM (Intel Vt-x and Intel Vt-d)
RAM 6GB
Storage Disk: 250GB
Soud Card Sound Blaster PCI 128
GPU NVIDIA Quadro FX 4800
Mouse ImExPS/2 Logitech Explorer Mouse - I used a USB|PS2 converter
Keyboard HP WMI hotkeys PS2

3.2   GPU: ROM is required!!! Use nvflash

I put it there because this is taken a piece of hardware. Keep in mind that Qemu/KVM may have important drawbacks with legacy cards!!!

You need to use nvflash for Linux. There is a Linux binary that you can download from https://www.techpowerup.com/download/nvidia-nvflash/

  • On the left of the page, click on "Show more versions"

    nvflash_download_01.png

    Click on "Show more versions"

  • Download the last one for Linux

    nvflash_download_02.png

    Download the last version for Linux

  • Unzip the file. Plug your GPU in a PC with a X server or you can use remotely (ssh -X ...). X librairies are required to use nvflash

  • Unload all modules for NVIDIA

    rmmod nouveau nvidiafb
    
  • List all GPUs

    root@kvm-ReactOS:~# ./nvflash --list
    
    NVIDIA Firmware Update Utility (Version 5.278.0)
    Simplified Version For OEM Only
    
    NVIDIA display adapters present in system:
    <0> Quadro FX 4800       (10DE,05FE,10DE,0594) H:--:NRM S:00,B:20,PCI,D:00,F:00
    
  • Back up ROM file

    NVIDIA Firmware Update Utility (Version 5.278.0)
    Simplified Version For OEM Only
    
    Adapter: Quadro FX 4800       (10DE,05FE,10DE,0594) H:--:NRM S:00,B:20,PCI,D:00,F:00
    
    The display may go *BLANK* on and off for up to 10 seconds during access to the EEPROM depending on your display adapter and output device.
    
    Identifying EEPROM...
    EEPROM ID (C2,2011) : MX MX25L1005 2.7-3.6V 1024Kx1S, page
    Reading adapter firmware image...
    IFR Data Size         : 0 bytes
    Image Size            : 64512 bytes
    Version               : 62.00.70.00.08
    ~CRC32                : 999B8B25
    Image Hash            : N/A
    Subsystem ID          : 10DE-0594
    Hierarchy ID          : Normal Board
    Chip SKU              : N/A
    Project               : N/A
    CDP                   : N/A
    Build Date            : 06/24/09
    Modification Date     : 10/16/09
    UEFI Support          : No
    UEFI Version          : N/A
    UEFI Variant Id       : N/A ( Unknown )
    UEFI Signer(s)        : Unsigned
    InfoROM Version       : N/A
    GPU Mode              : N/A
    Saving of image completed.
    

4   OS

This is Debian 9 Strech 64 Bits

4.1   Kernel 4.10.9 patches with ACS override patch

Debian 9 is provided with kernel 4.9. Unfortunately due to IOMMU groups I had to reuse another kernel I had on another machine for Qemu/KVM.

As of date of writting this document, the latest kernel (http://www.kernel.org) is 4.13.9. Unfortunately even if you patched this kernel you will get an important drawback. LVM version provided with Debian 9 is not supported with kernel 4.13.

That's the reason why I downgraded the kernel to 4.10. This one can work with LVM.

I need to use LVM because it makes life easier to manage storage for virtual machine. You can destroy/set up new storages easily

But this is a personal choice. But you can meet this issue with kernel 4.13 if you installed Debian through LVM.

So the kernel was rebuild

  • VFIO: built within the kernel (no modules)
  • KVM: built within the kernel (no modules)
  • PCI: built within the kernel (no modules)

4.2   Grub: Command line for boot

Here is the command in my /boot/grub/grub.cfg file

linux   /vmlinuz-4.10.9 root=/dev/mapper/kvm--ReactOS--vg-root ro intel_iommu=on iommu=1 kvm.ignore_msrs=1 \
kvm.allow_unsafe_assigned_interrupts=1 vfio_iommu_type1.allow_unsafe_interrupts=1 pcie_acs_override=multifonction \
i915.enable_hd_vgaarb=1 vfio-pci.ids=10de:05fe,1274:1371 quiet

5   Qemu 2.10.1 instead of 2.8

Qemu 2.8 is provided with Debian 9. It works -- I tested it !!! -- so it is not worth trying a recent version.

As of time of doing, my main concern was about recent version. The last one was 2.10.1.

For the peace fo mind I took decision to rebuild/test it

apt-get build-dep qemu-kvm

Then download the sources and built it. As a result this version works too.

5.1   My main script

vfiobind() {
dev="$1"
vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
device=$(cat /sys/bus/pci/devices/$dev/device)
if [ -e /sys/bus/pci/devices/$dev/driver ]; then
echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
fi
echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id;
}


vfiobind "0000:20:00.0" # GPU: Quadro FRX 4800
vfiobind "0000:07:04.0" # Sound card: SoundBlaster PCI 128


name="ReactOS"

# Storage is managed through LVM
export DISK_REACTOS="/dev/kvm-ReactOS-vg/ReactOS";

export ISO_REACTOS="/opt/ReactOS/isocd/bootcd-20171026.iso"

export kvm_device_ReactOS="-drive file=${DISK_REACTOS},if=ide,index=0,media=disk,format=raw,cache=writeback "
#kvm_device_ReactOS="-drive file=${DISK_REACTOS},if=virtio,index=0,media=disk,cache=none,format=raw "

# * -machine can not be set to 'q35' because Windows XP/2000 are not supported. So ReactoOS neither :(


/opt/qemu/2.10.1/bin/qemu-system-x86_64 \
        -enable-kvm \
        -bios /opt/qemu/2.10.1/share/qemu/bios-256k.bin \
        -cpu host,kvm=on -m 4096 -mem-path /hugepages -smp 4,maxcpus=4,sockets=1,cores=4,threads=1 \
        -machine pc-i440fx-2.10,accel=kvm  \
        -boot order=cd  \
        -name ${name}    \
        -pidfile /opt/qemu/2.10.1/var/run/${name}.pid \
        -rtc base=localtime,driftfix=slew \
        ${kvm_device_ReactOS} \
        -device vfio-pci,host=20:00.0,multifunction=on,x-vga=on,romfile=/opt/ReactOS/vgabios/quadrom4800.rom \
        -device vfio-pci,host=07:04.0 \
        -cdrom ${ISO_REACTOS} \
        -object input-linux,id=keyboard,evdev=/dev/input/event2,grab_all=on \
        -object input-linux,id=mouse,evdev=/dev/input/event3 \
        -device  virtio-net-pci,netdev=net0 -netdev type=bridge,id=net0,br=br0,helper=/opt/qemu/2.10.1/libexec/qemu-bridge-helper \
        -vga none  \
        -nographic \
        > /root/qemu.log 2>&1

6   FAQ

6.1   Q0: Once the host has just started - How to boot automatically on ReactOS?

You just need to add you Qemu script or its content in the file /etc/rc.local.

Sadly for Debian 9, this file was removed. Googling on this issue, you just need to do use commands provided at https://stackoverflow.com/questions/44797694/where-is-rc-local-in-debian-9-debian-stretch

6.2   Q1: How did you do to attach keyboard/mouse?

If you have a look on my Qemu script then you may notice this

...
-object input-linux,id=keyboard,evdev=/dev/input/event2,grab_all=on \
-object input-linux,id=mouse,evdev=/dev/input/event3
...

This is based on a feature introduced in Qemu 2.6.

  • To discriminate on the devices to install, you need to install evtest

    apt-get install evtest
    
  • Then launch it

    root@kvm-ReactOS:~# evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:      Power Button
    /dev/input/event1:      Power Button
    /dev/input/event2:      AT Translated Set 2 keyboard
    /dev/input/event3:      ImExPS/2 Logitech Explorer Mouse
    /dev/input/event4:      PC Speaker
    /dev/input/event5:      HDA Digital PCBeep
    /dev/input/event6:      HDA Intel Mic
    /dev/input/event7:      HDA Intel Line
    /dev/input/event8:      HDA Intel Line Out
    /dev/input/event9:      HDA Intel Front Headphone
    /dev/input/event10:     HP WMI hotkeys
    Select the device event number [0-10]: ^C
    
  • We just need the list above. So stop it using [Control]+[C]. As shown above

    • my keyboard is /dev/input/event2
    • my mouse is /dev/input/event3

6.3   Q2: Why don't you use 'q35' as machine template?

As written previously, ReactOS is not supposed to work -- for the moment -- with this chipset. Quoted from Qemu documentation "With chipset Q35 Windows 2000 and Windows XP are not supported!!!". So ReactOS neither!! Keep it mind that I tested it and it failed. However I didn't try to use other options/flags. I didn't spent a lot of time Maybe I am wrong here.

6.4   Q3: NVIDIA driver installation didn't fail?

Nope. All legacy drivers for Quadro are listed at http://www.nvidia.com/object/winxp-2k_archive.html You just need to read all technical details/documentation to find the good one :D

7   Bibiography

References

[1]https://www.reactos.org/wiki/Slipstream_files
[2]https://reactos.org/wiki/Create_an_unattended_Installation_CD