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
powerhouse
Level 5
Level 5
Posts: 994
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

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

Postby powerhouse » Tue Dec 05, 2017 6:40 am

Misairu_G wrote:kvm VGA passthrough with an Optimus laptop is not impossible anymore. Just did that myself, with OVMF.

The Code 43 error bash64 once encounter might be the incorrect Subsystem ID. Which can actually be masquerade using some vfio-pci option.

Spent days working on a complete tutorial. Check my Github Gist here https://gist.github.com/Misairu-G/616f7 ... addc940b28


Many thanks for sharing the link here. I included it in the tutorial. Kudos for your guide to VGA passthrough on Optimus laptops!
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Sun Dec 17, 2017 12:29 am

Hello,

Powerhouse,
Have you tried using looking glass yet?
You have to have a quadro professional card, but it changes qemu so that you do not need an external monitor for the gaming card.
You see your VM in a window with full gaming.

https://looking-glass.hostfission.com/

I will never buy a quadro so will never use this.

odtech
Level 2
Level 2
Posts: 95
Joined: Sat Jan 21, 2017 9:25 am

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

Postby odtech » Sun Dec 17, 2017 4:26 am

bash64 wrote:Hello,

Powerhouse,
Have you tried using looking glass yet?
You have to have a quadro professional card, but it changes qemu so that you do not need an external monitor for the gaming card.
You see your VM in a window with full gaming.

https://looking-glass.hostfission.com/

I will never buy a quadro so will never use this.


You don't need a quadro. Their demo rig uses 1080ti for guest and host uses R9-390X
https://youtu.be/okMGtwfiXMo

Other links
https://forum.level1techs.com/t/looking ... ort/122387
https://github.com/gnif/LookingGlass
https://looking-glass.hostfission.com/quickstart

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Mon Dec 18, 2017 10:13 pm

ok, i was able to compile the client.
how do i integrate it with qemu and my existing config file?

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Mon Dec 18, 2017 11:10 pm

bash64 wrote:ok, i was able to compile the client.
how do i integrate it with qemu and my existing config file?



found instructions to start an ivshem server and then install a redhat driver in qemu with windows.
working on this

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Tue Dec 19, 2017 10:32 pm

bash64 wrote:
bash64 wrote:ok, i was able to compile the client.
how do i integrate it with qemu and my existing config file?



found instructions to start an ivshem server and then install a redhat driver in qemu with windows.
working on this


got computer meeting on 23rd. have all day to try looking glass.
merry christmas

ersatzhero
Level 1
Level 1
Posts: 1
Joined: Thu Dec 28, 2017 1:51 pm

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

Postby ersatzhero » Thu Dec 28, 2017 2:14 pm

Hello,

I would like to give a big thank you to powerhouse and everyone who helped to create this guide.
I love my setup with the Windows VM. It just works :>

But still, I got a networking problem when I have installed Docker following the official guide.
The VM can't reach the internet anymore after Docker has been installed.

I can't figure out what the problem is:
Is it the iptables rules installed by Docker or
is the problem the two added bridge networks or
something completely else?

I don't have any idea how to look for that, so I hope, someone can point me in the right direction.

Regards

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Thu Dec 28, 2017 9:29 pm

hey powerhouse.

I need help switching to using a real drive.
I followed your link to using qemu images but there is nothing there about using real drives or LVM.
I bought a 512gb pny thumb drive,. it has read/write at 400/250mbsec.
I used pv to copy my existing image file to it. I can see the partitions on it,

I need the hard drive line for this to go into my bash script. it usually comes up as /dev/sdc.

p.s. i got lookingglass setup. as you know i have a laptop with nvidia optimus and i cannot run anything but seabios. well, lookingglass only has a w10 driver. i managed to convert window7/seabios to windows10/seabios using the microsoft mediacreationtool.exe.
it upgraded just fine and nvidia does not produce the code 43 error. seabios saves the day. but took over 8 hrs to finish. jeeeeesh. in the end the lookingglass driver wont install. wait for the official redhat release, i guess. w10/seabios is on the thumb. i just need help getting it booted. it already works, but slowly. the thumb should speed it up. i upgraded my laptop ram from 12gb to 28gb and gave qemu 20gb for gaming.

cyberspectre
Level 1
Level 1
Posts: 2
Joined: Sun Dec 31, 2017 4:09 pm

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

Postby cyberspectre » Sun Dec 31, 2017 4:51 pm

Hi powerhouse, thanks for making this tutorial. If you don't mind, I'd like some guidance.

I just built a new system specifically for VGA passthrough. Specs are as follows:

Gigabyte GA-AX370-Gaming K7
AMD Ryzen 1600x
Nvidia GTX760FTW (for Linux)
Nvidia GTX970FTW (for passthrough)
32GB memory
120GB SSD
2TB HDD
Ubuntu 16.04 host

I got to part 7 successfully before noticing the link you posted to the tutorial for Ubuntu 16.04 using virt-manager, and now I'm wondering whether I should continue with this method or go the virt-manager route — and, if going with the second, how to continue after completing steps 1-6 of this guide.

The windows VM will be used for Adobe creative cloud and gaming. All of my files and games will be on the 2TB HDD, which I need to be accessible by both OSes. How do you suggest I proceed?

odtech
Level 2
Level 2
Posts: 95
Joined: Sat Jan 21, 2017 9:25 am

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

Postby odtech » Wed Jan 03, 2018 2:07 pm

cyberspectre wrote:Hi powerhouse, thanks for making this tutorial. If you don't mind, I'd like some guidance.

I just built a new system specifically for VGA passthrough. Specs are as follows:

Gigabyte GA-AX370-Gaming K7
AMD Ryzen 1600x
Nvidia GTX760FTW (for Linux)
Nvidia GTX970FTW (for passthrough)
32GB memory
120GB SSD
2TB HDD
Ubuntu 16.04 host

I got to part 7 successfully before noticing the link you posted to the tutorial for Ubuntu 16.04 using virt-manager, and now I'm wondering whether I should continue with this method or go the virt-manager route — and, if going with the second, how to continue after completing steps 1-6 of this guide.

The windows VM will be used for Adobe creative cloud and gaming. All of my files and games will be on the 2TB HDD, which I need to be accessible by both OSes. How do you suggest I proceed?


Did you stop at step 7 because you ran into a issue or purely because you can't decide between qemu-kvm and virt-manager?

I've personally only used qemu-kvm so i can't help with pros and cons between the two but i image coming from windows the gui of virt-manager would be more friendly. The qemu console is however by no means difficult to use when you need to for examle add a usb thumb drive to the VM.

As for the drive i would reformat is to ext4 filesystem and have mint manage it then setup samba shares (windows shares) for the files you want to access from the windows guest.

With Ryzen just make sure you have one of the latest kernels installed for maximum compatibility. You can install kernel through the build in update manager in mint.

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

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

Postby powerhouse » Sat Jan 06, 2018 4:14 pm

bash64 wrote:Hello,

Powerhouse,
Have you tried using looking glass yet?
You have to have a quadro professional card, but it changes qemu so that you do not need an external monitor for the gaming card.
You see your VM in a window with full gaming.

https://looking-glass.hostfission.com/

I will never buy a quadro so will never use this.


Hi bash64,

This is a very late reply but I'm literally traveling all the time now, except these few days.

I've never tried looking glass, but it sounds interesting. Not having the need for 2 graphics cards and perhaps screens (or the wiring) will definitely help the migration towards Linux with a gaming Windows VM when needed.

I do use a Quadro 2000 card, but currently in the host. My VM runs a Nvidia GTX 970.

It should work with the GTX 970 but then there is the issue with administrative tasks in Windows, or the login screen, both of which cannot be captured unless when using an Nvidia professional Quadro 2000 and higher card (Tesla, etc.). This is prohibitive for most users.

I would have liked to try Looking Glass with my Quadro, but this is my work station I use on a day to day basis. Until I have enough time and a good reason to tinker with my hardware, I won't touch the system.

Since you already compiled Looking Glass, you could give it a try with your system. The instructions are here: https://looking-glass.hostfission.com/node/9. In the qemu script you'll need to add something like:

Code: Select all

-device ivshmem-plain,memdev=ivshmem \
-object memory-backend-file,id=ivshmem,share=on,mem-path=/dev/shm/looking-glass,size=32M


Let us know if and how it works.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

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

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

Postby powerhouse » Sat Jan 06, 2018 5:13 pm

bash64 wrote:hey powerhouse.

I need help switching to using a real drive.
I followed your link to using qemu images but there is nothing there about using real drives or LVM.
I bought a 512gb pny thumb drive,. it has read/write at 400/250mbsec.
I used pv to copy my existing image file to it. I can see the partitions on it,

I need the hard drive line for this to go into my bash script. it usually comes up as /dev/sdc.

p.s. i got lookingglass setup. as you know i have a laptop with nvidia optimus and i cannot run anything but seabios. well, lookingglass only has a w10 driver. i managed to convert window7/seabios to windows10/seabios using the microsoft mediacreationtool.exe.
it upgraded just fine and nvidia does not produce the code 43 error. seabios saves the day. but took over 8 hrs to finish. jeeeeesh. in the end the lookingglass driver wont install. wait for the official redhat release, i guess. w10/seabios is on the thumb. i just need help getting it booted. it already works, but slowly. the thumb should speed it up. i upgraded my laptop ram from 12gb to 28gb and gave qemu 20gb for gaming.


Regarding Looking Glass, I just posted my answer above, having missed your post here.

Now to the drive configuration. Since you use a thumb drive, it is plugged into a USB port. You can try this line in the qemu script:

Code: Select all

-usb -usbdevice disk:/dev/sdc

where /dev/sdc is the thumb drive (make sure it is).

To test it, I used a Linux Mint thumb drive:

Code: Select all

sudo qemu-system-x86_64 -m 4G -machine type=q35,accel=kvm -cpu host,kvm=off -smp 4,sockets=1,cores=2,threads=2 -usb -usbdevice disk:/dev/sdc


Works like a charm.

LVM won't be that easy. Let me know if above option works.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

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

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

Postby powerhouse » Sat Jan 06, 2018 8:14 pm

ersatzhero wrote:Hello,

I would like to give a big thank you to powerhouse and everyone who helped to create this guide.
I love my setup with the Windows VM. It just works :>

But still, I got a networking problem when I have installed Docker following the official guide.
The VM can't reach the internet anymore after Docker has been installed.

I can't figure out what the problem is:
Is it the iptables rules installed by Docker or
is the problem the two added bridge networks or
something completely else?

I don't have any idea how to look for that, so I hope, someone can point me in the right direction.

Regards


Hello ersatzhero,

Great to hear that your Windows VM works!

I have no experience with Docker. However, I saw somewhere in the documentation you linked to that Docker uses IP forwarding, that is a routed network - see https://docs.docker.com/engine/installation/linux/linux-postinstall/.

My tutorial uses a bridged network for communication between the VM and the host, as well as to the outside world.

My suggestion is this:

Remove the entire network configuration in the qemu script. Qemu will automatically use IP forwarding to connect the VM to the network. You may have to change the network configuration in Network Manager and remove the bridge.

Let me know if it helps.

Also, can you post a Passmark or Userbenchmark or your VM here: https://forums.linuxmint.com/viewtopic.php?f=225&t=153482. The user benchmark is free and can be downloaded here: http://www.userbenchmark.com. This helps in troubleshooting and establishes comparable performance data.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

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

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

Postby powerhouse » Sat Jan 06, 2018 9:09 pm

cyberspectre wrote:Hi powerhouse, thanks for making this tutorial. If you don't mind, I'd like some guidance.

I just built a new system specifically for VGA passthrough. Specs are as follows:

Gigabyte GA-AX370-Gaming K7
AMD Ryzen 1600x
Nvidia GTX760FTW (for Linux)
Nvidia GTX970FTW (for passthrough)
32GB memory
120GB SSD
2TB HDD
Ubuntu 16.04 host

I got to part 7 successfully before noticing the link you posted to the tutorial for Ubuntu 16.04 using virt-manager, and now I'm wondering whether I should continue with this method or go the virt-manager route — and, if going with the second, how to continue after completing steps 1-6 of this guide.

The windows VM will be used for Adobe creative cloud and gaming. All of my files and games will be on the 2TB HDD, which I need to be accessible by both OSes. How do you suggest I proceed?


I hope odtech's reply got you in the right direction.

If you already made it to step 7, you may as well go through with the tutorial. I personally have had bad experiences with virt-manager, but that is very subjective. Many people have used virt-manager and been successful.

My issue with virt-manager is that it does about 90-95% of the job, and for the rest of it one has to edit the xml file. It's more work and less flexible, and you never know where to start looking when things don't work the way they should.

About using the HDD: It's best to use LVM to create a physical volume (PV), a volume group (VG) and a logical volume (LV). After creating the LV for Windows, DON'T format it under Linux! When you install the Windows VM, specify the LV as the installation disk (like /dev/VG/LV).

With LVM you always have the option to grow the volume by adding a new disk and making it available to the VG and LV. If you intend to use it for Adobe CC then 2TB is not much - trust me. My photos take up around 2-3TB alone, and I'm constantly adding more capacity.

Have a second drive and use it for backup. You can do it easily in LVM using mirroring.

From the host you can access the LVM volume using kpartx. See my post here: https://forums.linuxmint.com/viewtopic.php?t=111783. I have written a small script to mount the Windows volume under Linux using kpartx. If you are interested, I can post it here.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Sun Jan 07, 2018 10:13 am

powerhouse wrote:
bash64 wrote:hey powerhouse.

Now to the drive configuration. Since you use a thumb drive, it is plugged into a USB port. You can try this line in the qemu script:

Code: Select all

-usb -usbdevice disk:/dev/sdc

where /dev/sdc is the thumb drive (make sure it is).

To test it, I used a Linux Mint thumb drive:

Code: Select all

sudo qemu-system-x86_64 -m 4G -machine type=q35,accel=kvm -cpu host,kvm=off -smp 4,sockets=1,cores=2,threads=2 -usb -usbdevice disk:/dev/sdc


Works like a charm.

LVM won't be that easy. Let me know if above option works.


qemu-system-x86_64: -usbdevice disk:/dev/sdc: '-usbdevice' is deprecated, please use '-device usb-...' instead
WARNING: Image format was not specified for '/dev/sdc' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.

cyberspectre
Level 1
Level 1
Posts: 2
Joined: Sun Dec 31, 2017 4:09 pm

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

Postby cyberspectre » Sun Jan 07, 2018 5:10 pm

odtech wrote:
cyberspectre wrote:Hi powerhouse, thanks for making this tutorial. If you don't mind, I'd like some guidance.

I just built a new system specifically for VGA passthrough. Specs are as follows:

Gigabyte GA-AX370-Gaming K7
AMD Ryzen 1600x
Nvidia GTX760FTW (for Linux)
Nvidia GTX970FTW (for passthrough)
32GB memory
120GB SSD
2TB HDD
Ubuntu 16.04 host

I got to part 7 successfully before noticing the link you posted to the tutorial for Ubuntu 16.04 using virt-manager, and now I'm wondering whether I should continue with this method or go the virt-manager route — and, if going with the second, how to continue after completing steps 1-6 of this guide.

The windows VM will be used for Adobe creative cloud and gaming. All of my files and games will be on the 2TB HDD, which I need to be accessible by both OSes. How do you suggest I proceed?


Did you stop at step 7 because you ran into a issue or purely because you can't decide between qemu-kvm and virt-manager?

I've personally only used qemu-kvm so i can't help with pros and cons between the two but i image coming from windows the gui of virt-manager would be more friendly. The qemu console is however by no means difficult to use when you need to for examle add a usb thumb drive to the VM.

As for the drive i would reformat is to ext4 filesystem and have mint manage it then setup samba shares (windows shares) for the files you want to access from the windows guest.

With Ryzen just make sure you have one of the latest kernels installed for maximum compatibility. You can install kernel through the build in update manager in mint.



powerhouse wrote:
cyberspectre wrote:Hi powerhouse, thanks for making this tutorial. If you don't mind, I'd like some guidance.

I just built a new system specifically for VGA passthrough. Specs are as follows:

Gigabyte GA-AX370-Gaming K7
AMD Ryzen 1600x
Nvidia GTX760FTW (for Linux)
Nvidia GTX970FTW (for passthrough)
32GB memory
120GB SSD
2TB HDD
Ubuntu 16.04 host

I got to part 7 successfully before noticing the link you posted to the tutorial for Ubuntu 16.04 using virt-manager, and now I'm wondering whether I should continue with this method or go the virt-manager route — and, if going with the second, how to continue after completing steps 1-6 of this guide.

The windows VM will be used for Adobe creative cloud and gaming. All of my files and games will be on the 2TB HDD, which I need to be accessible by both OSes. How do you suggest I proceed?


I hope odtech's reply got you in the right direction.

If you already made it to step 7, you may as well go through with the tutorial. I personally have had bad experiences with virt-manager, but that is very subjective. Many people have used virt-manager and been successful.

My issue with virt-manager is that it does about 90-95% of the job, and for the rest of it one has to edit the xml file. It's more work and less flexible, and you never know where to start looking when things don't work the way they should.

About using the HDD: It's best to use LVM to create a physical volume (PV), a volume group (VG) and a logical volume (LV). After creating the LV for Windows, DON'T format it under Linux! When you install the Windows VM, specify the LV as the installation disk (like /dev/VG/LV).

With LVM you always have the option to grow the volume by adding a new disk and making it available to the VG and LV. If you intend to use it for Adobe CC then 2TB is not much - trust me. My photos take up around 2-3TB alone, and I'm constantly adding more capacity.

Have a second drive and use it for backup. You can do it easily in LVM using mirroring.

From the host you can access the LVM volume using kpartx. See my post here: https://forums.linuxmint.com/viewtopic.php?t=111783. I have written a small script to mount the Windows volume under Linux using kpartx. If you are interested, I can post it here.


Odtech, powerhouse, thanks for your replies! Mainly, the reasons I was debating whether to use this or virt-manager were / are:

- Memory usage; using hugepages, I can dedicate 24 GB of ram to Windows, but the memory isn't usable in Linux even when the VM isn't running. I'd like to be able to use all of the memory in Linux when the VM is off. Is there a way to do this?

- VNC; I'd like to be able to display the VM via VNC, which seems well integrated by virt-manager. I hear it's painful to set it up yourself.

- The HDD question. Setting up a samba share works for general purposes, but I doubt you could run games very well. But powerhouse has the answer, I think. Powerhouse, with kpartx, could I access the partition in Nautilus (as well as back it up continually with SpiderOak on Linux) while the Windows VM is running? In other words, seamless concurrent access?

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

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

Postby powerhouse » Mon Jan 08, 2018 12:18 am

bash64 wrote:
qemu-system-x86_64: -usbdevice disk:/dev/sdc: '-usbdevice' is deprecated, please use '-device usb-...' instead
WARNING: Image format was not specified for '/dev/sdc' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.

Thanks for the feedback!

What version of qemu do you run, it's not 2.5?

EDIT: This is exactly the reason I sometimes hate KVM. The documentation is all over the place, they keep changing syntax by the hour, and try figure...

So what I dug out on the usb storage front is this:

https://github.com/qemu/qemu/blob/master/docs/usb-storage.txt

and

https://www.linux-kvm.org/page/USB

Of course the linux-kvm website is probably meant to be joke, with some of the info dating to 2017, whereas most of it was published in 2007 or so. The nice thing about this website is that it never says when something was posted, and usually forgets to mention which version of kvm the information relates to.

Perhaps I'm beating a dead horse. Am I?

Back to the issue - how to configure USB storage:

The best place to look for current information is actually on your hard drive. Go to

Code: Select all

/usr/share/doc/qemu-system-common

and open the file

Code: Select all

qdev-device-use.txt.gz

Somewhere in there you'll find this:

Code: Select all

-device usb-storage,drive=DRIVE-ID,removable=RMB


At least this is the documentation provided with qemu 2.5.

Here is perhaps a better, more up-to-date syntax for assigning USB thumb drives to a VM (taken from the Arch Linux forum):

Code: Select all

-device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-host,hostbus=3,hostaddr=2

The above would emulate a USB 2 controller (usb-ehci) and attach the USB stick to it.

Perhaps the best information can be obtained from the ArchLinux tutorial here: https://wiki.archlinux.org/index.php/QEMU#Pass-through_host_USB_device

Using the -machine type=q35 option, the best way to go about is to create a USB 2 or USB 3 device and then attach the USB drive to it:
For USB 2:

Code: Select all

-device usb-ehci,id=ehci

For USB 3:

Code: Select all

-device nec-usb-xhci,id=xhci

Attach the USB drive:

Code: Select all

-device usb-host,bus=controller_id.0,vendorid=0xvendor_id,productid=0xproduct_id


I just hope I'm on the right track here.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

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

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

Postby powerhouse » Mon Jan 08, 2018 2:59 pm

cyberspectre wrote:...Odtech, powerhouse, thanks for your replies! Mainly, the reasons I was debating whether to use this or virt-manager were / are:

- Memory usage; using hugepages, I can dedicate 24 GB of ram to Windows, but the memory isn't usable in Linux even when the VM isn't running. I'd like to be able to use all of the memory in Linux when the VM is off. Is there a way to do this?

- VNC; I'd like to be able to display the VM via VNC, which seems well integrated by virt-manager. I hear it's painful to set it up yourself.

- The HDD question. Setting up a samba share works for general purposes, but I doubt you could run games very well. But powerhouse has the answer, I think. Powerhouse, with kpartx, could I access the partition in Nautilus (as well as back it up continually with SpiderOak on Linux) while the Windows VM is running? In other words, seamless concurrent access?


Memory: Thanks for the question. This let me to explore hugepages a little bit more.

My first suggestion: Install the linux-doc package. This will give you access to the kernel documentation and hugepages configuration. After installation, open the hugetlbpage.txt.gz file under:

Code: Select all

/usr/share/doc/linux-doc/vm


Here a quote:
/proc/sys/vm/nr_hugepages indicates the current number of "persistent" huge
pages in the kernel's huge page pool. "Persistent" huge pages will be
returned to the huge page pool when freed by a task. A user with root
privileges can dynamically allocate more or free some persistent huge pages
by increasing or decreasing the value of 'nr_hugepages'.


Here are the steps to change the number of persistent huge pages to 20:

Code: Select all

sudo -i
echo 20 > /proc/sys/vm/nr_hugepages


I configured my system to allocate 11000 huge pages (~24 GB). Here is the output when changing the allocated huge pages:

Code: Select all

root ~ # free -m
              total        used        free      shared  buff/cache   available
Mem:          32175       24336         946          97        6892        7247
Swap:          8187           0        8187
root ~ # echo 20 > /proc/sys/vm/nr_hugepages
root ~ # free -m
              total        used        free      shared  buff/cache   available
Mem:          32175        2364       22918          97        6892       29219
Swap:          8187           0        8187
root ~ #

It works!

You should allocate the required number of huge pages at boot, as described in my tutorial. At the end of the boot process, you could write a simple script to where you reduce the number of huge pages, like shown here.

Then modify the VM startup script and allocate the required amount just before the qemu-... line. At the end of the script, make sure to reduce the number again. You might run into problems when your host - or other VMs - take up too much memory and you don't have enough to allocate to the VM. The document mentioned above will offer more information on that and how to go about.

VNC: This tutorial describes how to pass through a graphics card to the VM, so that you would be able to run Windows on its own screen (or switch your screen from host to guest and back, as I do). Access to the VM via VNC offers some convenience when you run (background-)processes in Windows, while working under the Linux host. Using virt-manager to accomplish the same will give you the same results, but will also allow you to switch back to the host and perhaps control the VM via VNC (I'm not sure now if that works).

I have been using RDP to control the Linux host from within Windows, in full-screen. It may not be the best solution, but it was simple and worked.

qemu has options to run a Spice client to control the VM. You might want to check that out - I haven't tried it.

HDD: Yes and no. kpartx allows you to mount and access partitions in a raw disk image. You can also mount file.img image files. In my case, I created a LVM raw partition - that is a partition that has not been formated - to hold my Windows installation. When installing Windows, Windows would see this LVM raw partition as an unformated drive, create some partitions, and format the main partition to NTFS. These partitions you can mount using kpartx.

However, you should never mount your Windows partition(s) for read-write when Windows is running. Doing so can create havoc with the file system, as Windows is totally unaware that some other system (the Linux host) is writing to its file system. You can safely mount the Windows partition for read-only!

I use kpartx in conjunction with LVM snapshots to backup Windows. However, it's a bad idea to backup the Windows VM while it is running. When Windows is running, it creates all sorts of temporary files etc. that can get in the way when you want to boot from an image you made of the VM. Snapshots allow you to freeze the current state, so while the system is being backed up, any changes to the running system will be written into a snapshot logical volume that will, upon completion and deletion of the snapshot, be merged with the VM partition.

SAMBA, on the other hand, is a network storage protocol. When you use Samba to access a running Windows VM from your host, Windows will be totally aware of that. So with Samba, two or more systems can access the same storage device and read and write (depending on the permissions you grant) at will.

I use Samba all the time to exchange files between my Windows VM and my Linux host. Since the virtual Ethernet bridge between the VM and the host has a bandwidth of around 10Gbit, the transfer speed is currently limited by the (slow) speed of my SSDs.

I assume that your Linux host won't need access to the games (apps and data) running on Windows, unless to back them up. For backup purposes it is best to close the VM and use Linux tools such as kpartx to mount the VM partitions under Linux and back them up to another (external) disk or system using Linux tools.

SpiderOak: I'm not familiar with SpiderOak, but I'm using both Dropbox and Google Drive for cloud backup and remote file synchronization. I suppose SpiderOak is similar. If you want to secure your Windows installation, just install SpiderOak inside the Windows VM and, once configured, it should do its magic. The same goes for installing SpiderOak on Linux. BUT, SpiderOak will not be able to see and backup your Windows VM unless you mount it using kpartx. I would not do that since you never know if the Linux version is capable of handling these things correctly.

To summarize the HDD solutions:
1. Use Samba to share files between Windows VM and Linux host (when both are running);
2. Use kpartx and a backup tool of your choice to make a local backup copy of your Windows VM disk image WHILE WINDOWS IS OFF.
3. Use SpiderOak or another commercial cloud backup solution to backup your Linux host and/or Windows VM to the cloud. Install and run SpiderOak under the respective OS. Make sure SpiderOak under Linux does not touch your Windows drive.

I hope that helps.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Gigabyte GTX 970 + PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB + Samsung EVO 850 250GB SSD + 5 HDD, Corsair 500R case, SeaSonic 660W Gold X PS

bash64
Level 2
Level 2
Posts: 65
Joined: Mon Mar 23, 2015 12:19 am

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

Postby bash64 » Fri Jan 12, 2018 3:36 pm

After many years of trying to achieve the perfect setup for playing DX11 games in linux I am finally there.
One of the main hurdles was overcoming audio stutter.
I traced down the issue to virtual hardfile lag. Not even using the redhat virtio drivers helped.
So, yesterday I got in a 1tb ssd, an intel 540s.
It fixed the issue.
Fallout 4 loads instantly and the audio never stutters.

The lag of emulating a hard drive is real.

I am using qemu 2.5 (which btw wont work with kernel 4.4. had to use 4.8 ).
I tried 2.11.50 which claims to have a whole new pulseaudio buffering system which fixes the audio stutter. It didn't.
Only removing the virtual hardfile emulation lag fixed it.
I must admit I was ready to give up for a long time, but hey, since nothing ever fully worked, what was there to lose?
I cannot recommend enough that everyone at least put their QEMU hardfile onto an SSD.

BTW: I did finally get windows 10 installed by upgrading windows7 using seabios to windows10 using the microsoft mediacreationtool.exe. it is quite slow without an ssd but i will be checking that.


For giggles here is my script to boot windows 7 (the nbd section does not work with windows 10 so i commented it out so as not to confuse anyone). lookingglass is disabled also. not done experimenting with that:


#!/bin/bash

#lookingglass...
#ivshmem-server -p /tmp/ivshmem.pid -S /tmp/ivshmem_socket -l 16M -n 8

cd /media/dad/QEMU-SSD/qemu-wd

#I have commented out nbd section for windows 10...made for windows 7 only
<<NBDSECTION
echo 'Creating nbd device nodes...'
sudo modprobe nbd max_part=63
sleep 2
echo 'Attach hardfile to device node nbd0...'
qemu-nbd -f raw -c /dev/nbd0 windows7.img
echo 'Create folder to mount hardfile to...'
mkdir -p /media/w7
echo 'Mount nbd0p1 to the folder...'
mount /dev/nbd0p1 /media/w7
echo 'Display the contents of the mounted folder...'
ls /media/w7/Boot/
echo 'Replace BOOTSTAT.DAT with backup copy...'
cp BOOTSTAT.DAT /media/w7/Boot/
cp BCD.LOG /media/w7/Boot/
cp BCD.LOG1 /media/w7/Boot/
cp BCD.LOG2 /media/w7/Boot/
echo 'Wait 5 seconds...'
sleep 5
echo 'Unmount and remove folder...'
umount /media/w7
echo 'Disconnect nbd device node...'
qemu-nbd -d /dev/nbd0
NBDSECTION

configfile=/media/dad/QEMU-SSD/qemu-wd/vfio-pci1.cfg

#vfiobind function....
vfiobind() {
dev="$1"
vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
device=$(cat /sys/bus/pci/devices/$dev/device)
echo $dev $vendor $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
}

modprobe vfio-pci

cat $configfile | while read line;do
echo $line | grep ^# >/dev/null 2>&1 && continue
vfiobind $line
done

# use pulseaudio
# 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

#export QEMU_PA_BUFFER_SIZE_OUT=5000
#export QEMU_PA_BUFFER_SIZE_IN=5000
#export QEMU_PA_TLENGTH=5000
#export QEMU_PA_FRAGSIZE=5000

#use ALSA
#export QEMU_ALSA_DAC_BUFFER_SIZE=512
#export QEMU_ALSA_DAC_PERIOD_SIZE=170
#export QEMU_AUDIO_DRV=alsa

# display current time and expected boot time for Windows...
echo "Windows expected to reach desktop at ..."
boottime1=$(date -d "$starttime today + 6 minutes" +'%I:%M:%S')
boottime2=$(date -d "$starttime today + 7 minutes" +'%I:%M:%S')
echo "between $boottime1 and $boottime2..."

#launch windows 7 64bit using SEABIOS (non-uefi bios)....
#/home/dad/qemu/build/x86_64-softmmu/
qemu-system-x86_64 -machine type=q35,accel=kvm -cpu host,kvm=off \
-smp 8,sockets=1,cores=4,threads=2 \
-bios /usr/share/seabios/bios.bin \
-serial none \
-parallel none \
-m 20G \
-vga none \
-soundhw hda \
-mem-prealloc \
-balloon none \
-rtc clock=host,base=localtime \
-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
-device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
-device virtio-scsi-pci,id=scsi \
-drive id=disk0,if=virtio,cache=none,format=raw,file=/media/dad/QEMU-SSD/qemu-wd/windows7.img \
-drive file=/media/dad/QEMU-SSD/qemu-wd/virtio-win-0.1.126.iso,id=isocd,format=raw,if=none -device scsi-cd,drive=isocd \
-netdev type=tap,id=net0,ifname=tap0 \
-device virtio-net-pci,netdev=net0,mac=00:16:3e:00:01:01 \
-usbdevice host:276d:1119 \
-boot menu=on \
-boot order=c

exit 0


Return to “Virtualization”