HOW-TO make dual-boot obsolete using kvm VGA passthrough

Questions about virtualization software
Forum rules
Before you post please read how to get help
bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Sat Apr 15, 2017 5:51 pm

taskset did the trick.

I used this:

#set running cinnamon desktop task to use cpu 0 and 1 only
taskset -p 0x00000003 `pidof cinnamon`

#launch qemu using cpus 2 through 7 and define 6 cpus for windows
taskset -c 2-7 qemu-system-x86_64 -machine type=q35,accel=kvm -cpu host,kvm=off \
-smp 6,sockets=1,cores=3,threads=2 \


I found that Windows actually used less cpu power after this and that most of the lag was gone when running Fallout 4.
Before, I had to give windows all 8 cpus and I had to raise the priority of Fallout 4 to high or realtime using the task manager.

Much more merciful setup. Less heat. Less lag.
Honestly, I need to build a desktop with 16 cores.

:-D

fastboot
Level 1
Level 1
Posts: 2
Joined: Sat Apr 15, 2017 7:03 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by fastboot » Sat Apr 15, 2017 7:27 pm

Hey,

thanks a lot for the great tutorial powerhouse and to all the others who contributed to this.

Sadly it just does not work for me. I tried this some time ago x times with ubuntu 14.04 but it never worked for me. SInce I got a new SSD I thought I give it a try again with Ubuntu 16.04 and I stuck again. :(

Some Specs about my Hardware:
CPU: I5 4670S
RAM: 32Gigs
MainBoard: GigaByte H87-HD3
GPU: GigaByte NVIDIA GeForce GTX 750 Ti Black Edition
OS: Ubuntu 16.04 64bit (Kernel now on 4.8 )

Here some Information:
/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet intel_iommu=on modprobe.blacklist=nouveau"

dmesg | grep "Virtualization Technology for Directed I/O"
[ 0.697140] DMAR: Intel(R) Virtualization Technology for Directed I/O


lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] (rev a2)

lspci | grep 01:00
01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] (rev a2)
01:00.1 Audio device: NVIDIA Corporation Device 0fbc (rev a1)

for a in /sys/kernel/iommu_groups/*; do find $a -type l; done
/sys/kernel/iommu_groups/0/devices/0000:00:00.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.1
/sys/kernel/iommu_groups/1/devices/0000:00:01.0
/sys/kernel/iommu_groups/1/devices/0000:01:00.0

/sys/kernel/iommu_groups/10/devices/0000:00:1c.3
/sys/kernel/iommu_groups/10/devices/0000:05:01.0
/sys/kernel/iommu_groups/10/devices/0000:05:01.1
/sys/kernel/iommu_groups/10/devices/0000:04:00.0
/sys/kernel/iommu_groups/10/devices/0000:05:01.2
/sys/kernel/iommu_groups/11/devices/0000:00:1d.0
/sys/kernel/iommu_groups/12/devices/0000:00:1f.3
/sys/kernel/iommu_groups/12/devices/0000:00:1f.2
/sys/kernel/iommu_groups/12/devices/0000:00:1f.0
/sys/kernel/iommu_groups/13/devices/0000:03:00.0
/sys/kernel/iommu_groups/2/devices/0000:00:02.0
/sys/kernel/iommu_groups/3/devices/0000:00:03.0
/sys/kernel/iommu_groups/4/devices/0000:00:14.0
/sys/kernel/iommu_groups/5/devices/0000:00:16.3
/sys/kernel/iommu_groups/5/devices/0000:00:16.0
/sys/kernel/iommu_groups/6/devices/0000:00:1a.0
/sys/kernel/iommu_groups/7/devices/0000:00:1b.0
/sys/kernel/iommu_groups/8/devices/0000:00:1c.0
/sys/kernel/iommu_groups/9/devices/0000:00:1c.2

cat /etc/modprobe.d/local.conf
options vfio-pci ids=10de:1380,10de:0fbc

cat /etc/initramfs-tools/modules
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
vhost-net

hugeadm --explain
Total System Memory: 31678 MB
Mount Point Options
/dev/hugepages rw,relatime
/run/hugepages/kvm rw,relatime,mode=775,gid=131
Huge page pools:
Size Minimum Current Maximum Default
2097152 9000 9000 9000 *
1073741824 0 0 0
Huge page sizes with configured pools:
A /proc/sys/kernel/shmmax value of 9437184000 bytes may be sub-optimal. To maximise
shared memory usage, this should be set to the size of the largest shared memory
segment size you want to be able to use. Alternatively, set it to a size matching
the maximum possible allocation size of all huge pages. This can be done
automatically, using the --set-recommended-shmmax option.
The recommended shmmax for your currently allocated huge pages is 18874368000 bytes.
To make shmmax settings persistent, add the following line to /etc/sysctl.conf:
kernel.shmmax = 18874368000
hugeadm:WARNING: User gpupass (uid: 1000) is not a member of the hugetlb_shm_group root (gid: 0)!
I adjusted the script for testing. since i did not want to add network or additional mouse. Also I used an ubuntu dvd for testing.

#!/bin/bash
vmname="windows10vm"
if ps -A | grep -q $vmname; then
echo "$vmname is already running." &
exit 1
else
# use pulseaudio
export QEMU_AUDIO_DRV=pa
export QEMU_PA_SAMPLES=8192
export QEMU_AUDIO_TIMER_PERIOD=99
export QEMU_PA_SERVER=/run/user/1000/pulse/native
cp /usr/share/OVMF/OVMF_VARS.fd /tmp/my_vars.fd
qemu-system-x86_64 \
-name $vmname,process=$vmname \
-machine type=q35,accel=kvm \
-cpu host,kvm=off \
-smp 2,sockets=1,cores=2,threads=2 \
-enable-kvm \
-m 16G \
-mem-path /run/hugepages/kvm \
-mem-prealloc \
-balloon none \
-rtc clock=host,base=localtime \
-vga none \
-serial none \
-parallel none \
-soundhw hda \
-device vfio-pci,host=01:00.0,multifunction=on \
-device vfio-pci,host=01:00.0 \
-drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=/tmp/my_vars.fd \
-boot order=dc \
-device virtio-scsi-pci,id=scsi \
-drive id=disk0,if=virtio,cache=none,format=raw,file=/media/user/win.img \
-drive file=/home/gpupass/Downloads/ubuntu-16.04.2-desktop-amd64.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
-drive file=/home/gpupass/Downloads/virtio-win-0.1.135.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \
exit 0
fi

When I start he machine within the CLI I get exactly nothing besides:
qemu-system-x86_64: cpu topology: sockets (1) * cores (2) * threads (2) > maxcpus (2)
I cant get rid of the third device in the group. No idea why. Its: 00:01.0 PCI bridge: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor PCI Express x16 Controller (rev 06)

Please be so kind and point me in the right direction. Really wanna get this to work and finally getting rid of the painfull dualbot. :)


Kind Regards

fastboot
Last edited by fastboot on Sun Apr 16, 2017 3:45 am, edited 1 time in total.

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Sat Apr 15, 2017 11:34 pm

You appear to have Optimus hardware. (qemu does not support Optimus, but a fluke with seabios will let it run).
Question: Have you ever run pure Windows on this hardware instead of linux? Does Windows show both the intel video and the nvidia card? What happens if you try to disable the intel card using the device manager? Does Windows object? If so you probably have Optimus.

Download your motherboard manual. Look for Optimus. If you have it then you will need to use seabios instead of OVMF. That is the only way I got around this issue. Let me know.

NOTE: Powerhouse...I think you should include a note in the tutorial to users that have Optimus hardware that they should use seabios instead. It is proven to work, at least on my system. Will windows 8/10 install without uefi? Just wondering.

fastboot
Level 1
Level 1
Posts: 2
Joined: Sat Apr 15, 2017 7:03 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by fastboot » Sun Apr 16, 2017 3:40 am

bash64 wrote:You appear to have Optimus hardware. (qemu does not support Optimus, but a fluke with seabios will let it run).
Question: Have you ever run pure Windows on this hardware instead of linux? Does Windows show both the intel video and the nvidia card? What happens if you try to disable the intel card using the device manager? Does Windows object? If so you probably have Optimus.

Download your motherboard manual. Look for Optimus. If you have it then you will need to use seabios instead of OVMF. That is the only way I got around this issue. Let me know.

NOTE: Powerhouse...I think you should include a note in the tutorial to users that have Optimus hardware that they should use seabios instead. It is proven to work, at least on my system. Will windows 8/10 install without uefi? Just wondering.


Good morning bash64,

who is "you"? If it's me, I dont think my mainboard uses any optimus. As far as I know this is only build in laptops.
Checked the vendor manual. No Optimus at all. I never used the IGPU before. It was turned off all the time @bios/uefi.

fastboot

P.S If you really think it makes a difference using Mint instead of Ubuntu 16.04 - I'll give this a shot. But actually I used the netboot for installation, then added Kernel 4.8 Support with apt.

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Sun Apr 16, 2017 9:43 am

Nvidia calls Optimus for desktops SYNERGY.
See this article dated 2011: https://www.techpowerup.com/144650/nvid ... putex-2011
And here: http://www.anandtech.com/show/4292/nvid ... op-optimus

I would imagine Synergy would give you the same problems as Optimus.
If you have Synergy switch to using seabios rather than OVMF.

I don't think Mint will make a difference.
It uses the same packages as Ubuntu.
mint17=ubuntu14.04
mint18=ubuntu16.04

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Sun Apr 16, 2017 1:02 pm

I downloaded your motherboard manual. It shows that you can disable the onboard graphics card (Intel).
Have you considered disabling it and installing a second graphics card instead?

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Sun Apr 16, 2017 4:22 pm

Sorry to have cluttered the responses.
I reviewed your code and you have defined this line wrong:
smp 2 cores 2 threads 2

smp should be 4, not 2.
you have 2 cores with 2 threads each, thus 4 cpus.

that should get past the error.
sorry for any distraction with the optimus issue.
i got a little excited when i solved my own issue.

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Mon Apr 17, 2017 12:14 am

@fastboot: Yes, start fixing the cpu assignment.

About the PCI groups and 00:01.0 this is a root bridge, which you cannot pass through! It should still work if you pass through the graphics card (both PCI).

It's definitely not connected to Optimus or Synergy.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

andr2535
Level 1
Level 1
Posts: 1
Joined: Wed Apr 19, 2017 3:22 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by andr2535 » Wed Apr 19, 2017 3:59 pm

Hi, I'm having a bit of a conundrum using this method to boot a Windows virtual machine and two Linux virtual machines.

I started using qemu-kvm around 7 months ago following this guide, and then it worked just fine.
Then last weekend I reinstalled Linux Mint because it had too much stuff installed etc.

After a reinstall and setup of the virtual machines, everything seems to be working fine,
that is until I try to start the Windows virtual machine after another virtual machine has been powered down.
For some reason Windows becomes very sluggish after restarting it, that also goes if I just restart it from within itself.
Incidentally the Linux Mint virtual machine that uses nouveau works fine.

By the way, thanks very much for this tutorial, being able to boot Windows and other Linux systems as virtual machines
has improved my computers flexibility immensely :D

EDIT:
After reinstalling again using the new guide and changing /dev/hugepages for /run/hugepages/kvm, the Windows virtual machine seems to work fine again.
Last edited by andr2535 on Thu Apr 20, 2017 3:37 pm, edited 1 time in total.

Divo
Level 1
Level 1
Posts: 4
Joined: Mon Mar 06, 2017 9:45 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by Divo » Thu Apr 20, 2017 3:26 am

Hi,
I'm new to linux and the gpu passthrough but thanks to your instructions and a little research I managed to make it work perfectly (I think so anyway).
All games I tried so far work without issues but I play very few and rather specific games so I can't say everything works 100%.
Not all games require windows, Dota2 or Arma3 for example are available in linux version so I would like to know its possible to easily use gpu in host machine and only use gpu passthrough when I want to play windows bound game. I am aware that restarting host will be a must if I want to swap gpu between host and vm.
So far I tried to install proprietary driver in host machine and removing "modprobe.blacklist=nouveau" from grub entry but gpu did not load in host anyway.

I have intel i7-7700k and currently use built-in intel hd630 for host display and gtx1070 for vm.

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Mon Apr 24, 2017 2:53 pm

Which VM performs better in your opinion?
Xen, Qemu, or VMWare commercial?

Just a note on my performance:
I play Fallout 4.
I had such bad performance level lately that I would stop the cinnamon desktop before launching qemu from the shell to get some more ooompf. I would also change the priority of the game to realtime using the task manager. Even with all of that the game would lag or eventually lag and it used to run better.
Then I remembered that I had lowered the ram from 6gb to 4gb. Fallout 4 uses 2.5->3.5gb depending on how much is going on.
The short of it is that eventually memory paging occurs and this becomes a qemu killer.
Bumping the ram back up to 6gb did wonders but after about 30 mins or moving to a new location that needs tons of mem leads back to lag.
I installed two different memory defraggers in Windows 7 and set one to autodefrag when ever free mem goes below 2gb and now everything is dreamy. I do still change the game to at least high priority but I also am now streaming to twitch on top of running the game and I leave the cinnamon desktop running so I would not say it was a cpu issue like I did before, it was the poor performance of a memory fragmented and starved windows trying to run in an emulator.

Memory seemed to be the whole issue, especially the paging.

I'd like to find out what causes such a poor performance when paging of memory occurs. It does not seem to be a Windows issue, but a qemu issue.
I do have hugepages enabled and set to 6gb.

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Wed Apr 26, 2017 5:00 pm

bash64 wrote:Which VM performs better in your opinion?
Xen, Qemu, or VMWare commercial?

Just a note on my performance:
I play Fallout 4.
I had such bad performance level lately that I would stop the cinnamon desktop before launching qemu from the shell to get some more ooompf. I would also change the priority of the game to realtime using the task manager. Even with all of that the game would lag or eventually lag and it used to run better.
Then I remembered that I had lowered the ram from 6gb to 4gb. Fallout 4 uses 2.5->3.5gb depending on how much is going on.
The short of it is that eventually memory paging occurs and this becomes a qemu killer.
Bumping the ram back up to 6gb did wonders but after about 30 mins or moving to a new location that needs tons of mem leads back to lag.
I installed two different memory defraggers in Windows 7 and set one to autodefrag when ever free mem goes below 2gb and now everything is dreamy. I do still change the game to at least high priority but I also am now streaming to twitch on top of running the game and I leave the cinnamon desktop running so I would not say it was a cpu issue like I did before, it was the poor performance of a memory fragmented and starved windows trying to run in an emulator.

Memory seemed to be the whole issue, especially the paging.

I'd like to find out what causes such a poor performance when paging of memory occurs. It does not seem to be a Windows issue, but a qemu issue.
I do have hugepages enabled and set to 6gb.
I do not have any experience with VMWARE, but with Xen and kvm/qemu. Xen and kvm perform similar, but kvm requires more fine tuning in almost all aspects (Xen is straightforward). Using kvm makes sense when using Nvidia graphics.

4GB for Windows is definitely too little for graphics intensive games. Even 6GB may be borderline. I have 32GB and give Windows either 20 or 24GB. Linux on the other hand can live nicely with 4GB, even less. Important: when using hugepages you need to add some extra memory, which I described in the tutorial. In other words, you reserve more memory than you actually use in the VM.

If your PC is low on memory, adding more RAM is probably the best investment you can make except perhaps replacing your HDD with an SSD. The best is both.

As to kvm, you may need to tune your settings and benchmark. Start with a benchmark like Passmark and compare your results with those obtained by users running the same hardware but Windows on bare metal. If say your disk performance compares to that of the same disk that runs Windows without VM, there is little potential for improvement. On the other hand, if there is more than 10-15% difference, it may be worth to check the configuration.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

bash64
Level 3
Level 3
Posts: 108
Joined: Mon Mar 23, 2015 12:19 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by bash64 » Fri Apr 28, 2017 3:30 pm

Thanks for the tips.
I have 12gb of ram (8gb+4gb).
Bought this laptop used.
Not sure whose idea it was to install two non-identical sticks of ram, but it was a bad idea either way,
Going to fix that and bump the ram up.
I will give windows 8gb and see how Fallout 4 does.

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Fri Apr 28, 2017 4:38 pm

bash64 wrote:Thanks for the tips.
I have 12gb of ram (8gb+4gb).
Bought this laptop used.
Not sure whose idea it was to install two non-identical sticks of ram, but it was a bad idea either way,
Going to fix that and bump the ram up.
I will give windows 8gb and see how Fallout 4 does.
Try that 8GB before spending money on ram. 12gb should be OK. see if it improves performance.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Sat Apr 29, 2017 12:20 am

Divo wrote:Hi,
...
Not all games require windows, Dota2 or Arma3 for example are available in linux version so I would like to know its possible to easily use gpu in host machine and only use gpu passthrough when I want to play windows bound game. I am aware that restarting host will be a must if I want to swap gpu between host and vm.
So far I tried to install proprietary driver in host machine and removing "modprobe.blacklist=nouveau" from grub entry but gpu did not load in host anyway.

I have intel i7-7700k and currently use built-in intel hd630 for host display and gtx1070 for vm.
As far as I know, X is not ready yet to dynamically assign or reassign the GPU. You will have to follow the development of Xorg and see the release notes or change log.
Another possibility is to create a Linux VM with GPU passthrough. Unfortunately I never tried it and from what I read it might actually be more difficult than with Windows. Yet I think it's worth a try and it looks to me to be the best solution.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

Divo
Level 1
Level 1
Posts: 4
Joined: Mon Mar 06, 2017 9:45 am

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by Divo » Mon May 01, 2017 10:39 am

powerhouse wrote:
Divo wrote:Hi,
...
Not all games require windows, Dota2 or Arma3 for example are available in linux version so I would like to know its possible to easily use gpu in host machine and only use gpu passthrough when I want to play windows bound game. I am aware that restarting host will be a must if I want to swap gpu between host and vm.
So far I tried to install proprietary driver in host machine and removing "modprobe.blacklist=nouveau" from grub entry but gpu did not load in host anyway.

I have intel i7-7700k and currently use built-in intel hd630 for host display and gtx1070 for vm.
As far as I know, X is not ready yet to dynamically assign or reassign the GPU. You will have to follow the development of Xorg and see the release notes or change log.
Another possibility is to create a Linux VM with GPU passthrough. Unfortunately I never tried it and from what I read it might actually be more difficult than with Windows. Yet I think it's worth a try and it looks to me to be the best solution.
Thank you for the reply.
I guess I'll be better off buying second GPU for linux. It's much better option then being stuck with windows.
Massive THANK YOU for this tutorial and all the help.

mrme01
Level 1
Level 1
Posts: 2
Joined: Mon May 01, 2017 7:18 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by mrme01 » Mon May 01, 2017 7:59 pm

HI,

I've just tried this on a Dell 7566 laptop (Intel 530 bolted onto a Core i5 6300HQ and Nvidia 960M, 8gigs of RAM ), not much luck, but I hope to get it running with some help. I clicked through (op might have something wrong, unsure though) to read about how to get this to work with Optimus, all I get is a post about a bug report to QEMU? viewtopic.php?f=231&t=212692&p=1300764#p1300634

Not sure what I was looking for here, I was assuming I would see the rendered output from the VM either in a window or fullscreen. Got neither of these expected results.

I had to mess with the name of the vm as it insisted it was already running from a cold boot. Anyway, first time I got it to run, the system locked up and required holding the power button, tried again and I get this,

Code: Select all

./windows10vm1.sh 
W: /etc/qemu-ifup: no bridge for guest interface found
QEMU 2.5.0 monitor - type 'help' for more information
(qemu) qemu-system-x86_64: failed to get page size of file /run/hugepages/kvm: No such file or directory
Here's my sysctl.conf

Code: Select all

# Set hugetables / hugepages for KVM single guest using 8GB RAM
vm.nr_hugepages = 2500
kernel.shmmax = 5242880000
vm.hugetlb_shm_group = 0
8 gigs of RAM, I'm kinda clueless on how to work this out, I just went with what I thought made sense at the time.

And there's most likely mistakes with the script itself, don't ask about the VM name, because I don't know...

Code: Select all


#!/bin/bash

vmname="flergnerp"

if ps -A | grep -q $vmname; then
   echo "$vmname is already running." &
   exit 1

else

# use pulseaudio
export QEMU_AUDIO_DRV=pa
export QEMU_PA_SAMPLES=8192
export QEMU_AUDIO_TIMER_PERIOD=99
export QEMU_PA_SERVER=/run/user/1000/pulse/native

cp /usr/share/OVMF/OVMF_VARS.fd /tmp/my_vars.fd

qemu-system-x86_64 \
  -name $vmname,process=$vmname \
  -machine type=q35,accel=kvm \
  -cpu host,kvm=off \
  -smp 6,sockets=1,cores=3,threads=2 \
  -enable-kvm \
  -m 4G \
  -mem-path /run/hugepages/kvm \
  -mem-prealloc \
  -balloon none \
  -rtc clock=host,base=localtime \
  -vga none \
  -nographic \
  -serial none \
  -parallel none \
  -soundhw hda \
  -usb -usbdevice host:045e:076c -usbdevice host:045e:0750 \
  -device vfio-pci,host=01:00.0 \
  -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd \
  -drive if=pflash,format=raw,file=/tmp/my_vars.fd \
  -boot order=dc \
  -device virtio-scsi-pci,id=scsi \
  -drive id=disk0,if=virtio,cache=none,format=raw,file=/media/mrme01win.img \
  -drive file=/media/mrme01/win10.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
  -drive file=/media/mrme01/virtio-win-0.1.136.iso,id=virtiocd,format=raw,if=none -device ide-cd,bus=ide.1,drive=virtiocd \
  -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  -device virtio-net-pci,netdev=net0,mac=00:16:3e:00:01:01

   exit 0
fi
Not sure what to do or where to go from here, but here's hoping I can move away from Windows on my workhorse and still get to game!

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Tue May 02, 2017 12:00 am

@mrme01: First things first - what is the total RAM of your laptop?

According to what you posted, you reserved 8GB for hugepages, yet defined only 4GB for your VM. If that is the case, reduce the hugepages memory to slightly more than 4GB, for example 4.4GB. See the tutorial on how it's done.

The error message reads that you did not define a network bridge. Check with brctl show to see if you have defined that bridge.

The next error is related to hugepages, but it may have to do with improper hugepages definition - reduce the size.

Before running the start script, check that everything is OK. In particular, make sure that your GPU is assigned to vfio_pci. Needless to say that your CPU must support IOMMU, which is the first thing to check.

Hope it helps.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

mrme01
Level 1
Level 1
Posts: 2
Joined: Mon May 01, 2017 7:18 pm

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by mrme01 » Tue May 02, 2017 12:24 pm

@powerhouse, thanks for the reply!

I'm currently running Windows, and it'll be a few hours before I can reboot in Mint.

I have 8 gigs of RAM, but I was unsure what number to use when it come to setting up hugepages, I would like to use 4 gig (for now, increase it later)

I read the tutorial on the Debian wiki, as I am using wireless, I tried to replicate it as best as I could for my current ssid, I'll go over those setting again and make sure they're correct. It doesn't make sense that no networking means it won't start the VM, or throw a warning, saying it'll run, but without networking.

I went through the guide, made sure my processor could support this in the beginning steps.

When I reboot, I shall either post a reply or edit this one with more of the outputs from commands and what files I have edited, besides those already attached.

powerhouse
Level 6
Level 6
Posts: 1085
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: HOW-TO make dual-boot obsolete using kvm VGA passthrough

Post by powerhouse » Mon May 08, 2017 5:31 am

mrme01 wrote:@powerhouse, thanks for the reply!

I'm currently running Windows, and it'll be a few hours before I can reboot in Mint.

I have 8 gigs of RAM, but I was unsure what number to use when it come to setting up hugepages, I would like to use 4 gig (for now, increase it later)

I read the tutorial on the Debian wiki, as I am using wireless, I tried to replicate it as best as I could for my current ssid, I'll go over those setting again and make sure they're correct. It doesn't make sense that no networking means it won't start the VM, or throw a warning, saying it'll run, but without networking.

I went through the guide, made sure my processor could support this in the beginning steps.

When I reboot, I shall either post a reply or edit this one with more of the outputs from commands and what files I have edited, besides those already attached.
About hugepages: It is not necessary to set up hugepages - you can run the VM without. hugepages can help improve performance, that's why I included them.

Wireless LAN: My how-to and the bridge configuration was written for wired connections! They won't work with a wireless connection. There are other tutorials that describe how to enable networking without using a bridge. Qemu should set up some simple network connection even if you do not define any networking in the qemu start script. You could try that. See https://help.ubuntu.com/community/KVM/Networking under "Usermode networking".

Unfortunately a wireless setup is more complicated, in particular if you want a layer 2 (Ethernet) bridged network. I don't know which Debian wiki you refer to, but the one I tried a year ago didn't work for me. Back then I also tried to connect via wireless, but in the end I couldn't make it work and I gave up. It was much easier to drill a hole in the wall and install 10m CAT6 cable to directly connect my PC with the router.

I hope the usermode network approach works for you - it is a layer 3 network connection so it should work with Wifi.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3, Noctua NH-D14 CPU cooler, GTX 970 + Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk 120GB + Samsung EVO 860 1TB SSD + 4 HDD, Corsair 500R, SeaSonic 660W Gold X PS https://heiko-sieger.info

Post Reply

Return to “Virtualization”