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

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Thanks for the reply.
Over the last few days I have learned from Microsoft that only Windows 7 64bit with service pack 1 is uefi compatible.
I have wasted a lot of time trying to get w7 sp0 to work. A lot of time.

Apparently Microsoft did not provide a way to add sp1 to a sp0 install disc.
I used a tool called RT Seven Lite.
It seems to have worked fine. It added sp1 to my install ISO with no service pack.

Currently, I fail to boot off the ISO using your script.
Back when I couldn't get w7 sp0 to boot I created a usb thumb with it and it booted, but couldn't finish the install.
Perhaps I can convert the w7 sp1 ISO into a thumb and get this done.
I will let you know if it worked.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Here is all you need to use windows 7 with uefi without secureboot using the scripts in this tutorial:

1) An ISO image of windows 7 64bit with service pack 1
2) A copy of Rufus.
https://rufus.akeo.ie/
3) A 4gb thumb drive or larger.
4) qemu 2.6.x (qemu 2.5.x is bugged and unusable)

Run Rufus in vmware with windows 7. Use Rufus to write out the ISO image to the thumb and select GTP and UEFI for the mode of install.
Select the fat32 filesystem.

Assign the thumbdrive to qemu as such in your script:
-usbdevice host:{vid}:{pid}

Make sure you running qemu 2.6.x and not 2.5.x. Here is the bug report on 2.5.x: https://bugs.launchpad.net/qemu/+bug/1591724
Download and compile the source code for 2.6.x if you have to, otherwise find a PPA for qemu 2.6.x or maybe your OS has a package for it.

NOTE: I am running Linux Mint 18.1 (ubuntu 16.04). The highest qemu available is 2.5.x. 2.5.x has a nasty bug that prevents any sort of use of standard vga. I also experience a bug where I cannot boot off of the emulated CD using the windows ISO image. Using a thumbdrive gets around the CD issue. I had to compile qemu 2.6.2 from source to get around the vga bug.

ok, so start your script and the UEFI will find the thumb and start the windows 7 installer.
If you have upgraded to at least qemu 2.6.x you will get to the install screen...if not you will watch the windows logo forever.
When no hard drive is found browse for the virtio driver on the ISO provided in your script in the virtstor folder.
That is it.
I got an error telling me windows wouldn't be able to install to this drive, but it did anyway.

IF YOU DO NOT HAVE W7 SP1:
I have a w7 sp0 ISO.
I had to create a new ISO with sp1 slipstreamed into it.

Here is the easy way to do that:

1) Download a copy of RT Seven Lite.
http://www.softpedia.com/get/System/Boo ... Lite.shtml

2) Download a copy of the service pack one executable from Microsoft.
Click download. On the pop up checkmark the file called windows6.1-KB976932-X64.exe only.
https://www.microsoft.com/en-us/downloa ... px?id=5842

Follow these instructions to make a new iso with sp1:
https://www.sevenforums.com/tutorials/1 ... -file.html
powerhouse
Level 6
Level 6
Posts: 1144
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 »

Thanks bash64 for this information - had I known that back when I switched from Xen to kvm I'd still be running Windows 7.

I will link to your post once I'm at a PC. Great stuff!
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

UPDATE:
I did complete an install of windows 7 using uefi.
However, I was back to the error code 43 nvidia issue.

I tried switching to i440fx instead of the q35 machine type.
Same deal. Code 43 error in the device manager.
I wish I had better news.
If anyone gets around this let me know.
:-D

Everything in the previous post is correct and verifiable.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

According to this article:
https://forums.lime-technology.com/topi ... 43-errors/

as of 337.88 nvidia began causing issues for users for KVM.
I have downloaded various drivers leading up to this driver.
They all fail to recognize my gtx 880m 8gb video card.
337.88 does recognize it but , once again, I get code 43.

If you have an earlier nvidia card it is possible that a driver before 337.88 will fix this issue for you.
Once again, I only have this issue when using uefi (w10 or W7), not with seabios.
Switching between the q35 motherboard emulation and the i440fx made no difference.
So for now I shall remain on seabios. A regular bios hides the video card from windows such that the failure does not happen.
Perhaps a better OVMF can fix this.

P.S. When I write the qemu chapter for my 3rd self help ebook I'd like to link to this article as a guide for users.
I will be adding my personal recommendations and setups that have worked for me.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

UPDATE:
Downloaded the latest OVMF.
No improvement.
Still get code 43 errors.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

UPDATE:
I am determined to defeat or understand error code 43. :-D

What my research has found:
1) Users of windows (no linux) can get this same error.
2) Some have fixed it by updating their BIOS.
3) I only get it when using UEFI, not seabios.

Conclusion:
Nvidia made a change to their drivers to fully support the uefi standard as well as the old bios standard. However, not all UEFI firmware produced for PC motherboards conforms to the entire uefi standard, thus some PC owners needed a BIOS (UEFI) update to get rid of error code 43.

See this article from the nvidia developers forum:
https://devtalk.nvidia.com/default/topi ... 0-update/3

Since this only happens when using OVMF and not seabios this simply means that OVMF is not fully compliant with uefi standards.

That is my final conclusion. Waiting on a better copy of OVMF.

P.S. If anyone out there has gotten around this issue I want you to email me a copy of your OVMF file today!
You can email it to lm17fapmfa@twc.com
Thanks
powerhouse
Level 6
Level 6
Posts: 1144
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 »

deleted by author
Last edited by powerhouse on Sat Apr 01, 2017 4:07 pm, edited 1 time in total.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
powerhouse
Level 6
Level 6
Posts: 1144
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 »

@bash64:

Edit3: According to https://www.techpowerup.com/vgabios/154 ... 192-131219 your card may not support UEFI. That would explain your error 43 and your success with Seabios.

First check at techpowerup.com if your card actually supports UEFI. If not, or not with the current VGA BIOS, you may find an updated or modified VGA BIOS that supports UEFI.

For your reference: I'm running Nvidia driver version 375, the latest is 378 using the cpu host,kvm=off option in the startup script.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Thanks.

I posted a bug to qemu.
Their conclusion is that I have Optimus. In other words, becuase I have Optimus hardware Windows requires that I have a working nvidia card and a working intel card in order to make the nvidia driver work. OVMF somehow lets Windows see that I use Optimus and then Windows gives off the code 43 error when it cannot see the Intel card also, Seabios hides this and the nvidia driver works as expected. There is therefore no cure for my system using uefi. It isn't possible. Laptops with optimus need to stick to Seabios. I hate Optimus, officially.

My bug report:
https://bugs.launchpad.net/qemu/+bug/1680679
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Helpful hint:

With gpu passthrough you cannot see if Windows is asking you to do startup repair and you cannot tell it no. If startup repair begins you never get to a desktop. Just a blank screen. To prevent w7 from offering the 'launch startup repair' option due to a bad shutdown:

---------------------------------------------------------------------------------------
Open a command prompt as administrator and do the following:
>bcdedit /set bootstatuspolicy ignoreshutdownfailures
>bcdedit /set {default} recoveryenabled No
powerhouse
Level 6
Level 6
Posts: 1144
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 »

bash64 wrote:Thanks.

I posted a bug to qemu.
Their conclusion is that I have Optimus. In other words, becuase I have Optimus hardware Windows requires that I have a working nvidia card and a working intel card in order to make the nvidia driver work. OVMF somehow lets Windows see that I use Optimus and then Windows gives off the code 43 error when it cannot see the Intel card also, Seabios hides this and the nvidia driver works as expected. There is therefore no cure for my system using uefi. It isn't possible. Laptops with optimus need to stick to Seabios. I hate Optimus, officially.

My bug report:
https://bugs.launchpad.net/qemu/+bug/1680679
Hello bash64: again thanks for your update.

Based on your reply, I can assume that your VGA BIOS supports UEFI.

Optimus is a pain in the neck. Laptops equipped with Optimus have a BIOS that handles the switching between the IGD (CPU onboard graphics) and the discrete Nvidia GPU. That is something difficult to get by.

I didn't know you were using a laptop, but when you mentioned your GPU I should have realized that.

I used SEABIOS for more than 3 years and it's not that bad. The only reason I'm not using seabios in the tutorial is the fact that it brings with it a tail of problems with certain CPUs and hardware configurations that I didn't want to get into. Most users with modern hardware have a GPU that supports UEFI, and don't face the Optimus problem. But it's good that you shared your experiences so others will know what to do. I will link to your post once I'm at a normal computer.

EDIT: Please pay attention to posts 6 and 10 in your qemu bug report. Alex describes 2 different causes for error 43: lack of UEFI support in the GPU ROM; Optimus firmware.

Typically, error 43 is a tell-tale sign for lack of UEFI support, or for not using the -cpu ...,kvm=off option. Here some background:

In the old days, the Nvidia driver didn't care about whether it is running on bare metal or inside a VM. Newer Nvidia drivers are checking for the presence of a hypervisor and if detected, they would quit with error 43. The qemu/kvm team have discovered the mechanism by which the Nvidia driver detects the hypervisor, and the -cpu ...,kvm=off option tells qemu/kvm to hide the hypervisor flags from the VM and the Nvidia driver, at the cost of some performance loss (if any).

In your bug description you mention "Qemu appears to corrupt something in linux when exiting" and that you cannot restart the Windows guest. This may have to do with FLR or "Function Level Reset", something that is not always supported properly by the graphics card. In that case you need to shut down the PC and reboot. It has nothing to do with Qemu corrupting Linux, but with your graphics card not properly resetting.

Now about Optimus: Until quite recently, Linux had a hard time to work with laptops using Optimus. Nvidia developed Optimus as a proprietary feature to allow the use of their mobile GPUs together with Intel IGD (Intel's onboard graphics on the CPU). Optimus would allow laptop users to utilize the Intel graphics for simple office, web etc. work, and switch to the Nvidia GPU for demanding graphics such as 3D games etc. This would conserve battery lifetime.

KVM or qemu have not addressed Optimus, and I doubt they ever will. Aside from the difficulties handling the proprietary Optimus firmware, a laptop is not the typical platform to run VMs, much less VGA passthrough. As to VGA passthrough, some laptop users report success, others sink into frustration. You are the lucky one!
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

I ran a tool to test if my video card has uefi firmware and it does.
I do use the kvm=off switch.
So I still think I cannot run in uefi mode due to Optimus.
I am glad I can run.
I worked hard on it for a long time to get it to work.

Thankyou for your lengthy response.
Learning something new all the time.
powerhouse
Level 6
Level 6
Posts: 1144
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 »

bash64 wrote:I ran a tool to test if my video card has uefi firmware and it does.
I do use the kvm=off switch.
So I still think I cannot run in uefi mode due to Optimus.
I am glad I can run.
I worked hard on it for a long time to get it to work.

Thankyou for your lengthy response.
Learning something new all the time.
Yes, it looks like an Optimus issue.

About my comment on the qemu/kvm team not working on an Optimus solution: This is my guess. It will be best to address this to Alex who responded to your bug report. He's a developer and responsible for some of the features we use. I have no connections whatsoever with the developers, other than via forum communications.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

I am attempting to switch to using pulseaudio.
I get permission errors.
This is not affected by using sudo to run qemu (which I normally do) or not using sudo.Happens either way.
I tested qemu for a list of backends.

$ qemu-system-x86_64 --audio-help | grep Name
Name: spice
Name: pa
Name: alsa
Name: sdl
Name: oss
Name: none
Name: wav


pa is there....


with sudo:
Home directory not accessible: Permission denied
pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
Home directory not accessible: Permission denied

without sudo:
Home directory not accessible: Permission denied
pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
Home directory not accessible: Permission denied
tt7753

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

Post by tt7753 »

I followed the guide . But the graphics card(gtx 1060) does not output a picture. If i start without -vga none and -nographic everything works fine. What should i do?
Qemu outputs the following: e1000 writing to register at offset: it is not fully implemented.
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

tt7753 wrote:I followed the guide . But the graphics card(gtx 1060) does not output a picture. If i start without -vga none and -nographic everything works fine. What should i do?
Qemu outputs the following: e1000 writing to register at offset: it is not fully implemented.
Hello,

What I encountered is a very long boot time and having no patience I always assumed it failed.
You do need -vga none \
You also need to give it at least 10 minutes to boot.

1) install without -vga none
2) install the nvidia driver
3) remove the standard vga driver from the device manager and then do a full shutdown (do not restart).
4) add -vga none to your script
5) boot and give it ten minutes or more. gpu passthrough will kick in. your nvidia driver will take over. however, you won't see anything until windows is all the way to the desktop login.

my personal recommendations
powerhouse
Level 6
Level 6
Posts: 1144
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 »

@tt7753: I second bash 64 advice.

However, sometimes it is simply a matter of switching inputs on your screen. Also, make sure the OVMF files are set up correctly, and given the right permissions.

e1000 is the network interface driver.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
bash64
Level 3
Level 3
Posts: 116
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 »

Question:

CPU Affinity

I'd like to try a setup where Linux is limited to the first 4 cpus and qemu uses the last 4 on my i7-4810mq processor.
Have you tried this sort of setup before?

I looked into maxcpus and taskset. I am not sure either will do what I want.

I found that qemu 2.4.x has a new switch:

-vcpu0,affinity=4

I can set each virtual cpu to a specific physical cpu.
powerhouse
Level 6
Level 6
Posts: 1144
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 »

bash64 wrote:Question:

CPU Affinity

I'd like to try a setup where Linux is limited to the first 4 cpus and qemu uses the last 4 on my i7-4810mq processor.
Have you tried this sort of setup before?

I looked into maxcpus and taskset. I am not sure either will do what I want.

I found that qemu 2.4.x has a new switch:

-vcpu0,affinity=4

I can set each virtual cpu to a specific physical cpu.
Hi, see my tutorial, part 12, my VM start script. I use taskset.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
Locked

Return to “Virtual Machines”