đž Archived View for gemini.mcgillij.dev âş vfio_part3.gmi captured on 2023-11-04 at 11:30:50. Gemini links have been rewritten to link to archived content
âŹ ď¸ Previous capture (2022-03-01)
-=-=-=-=-=-=-
:author:
mcgillij
:category:
Linux
:date:
2020-12-27 14:51
:tags:
Linux, VFIO, Tutorial, Virtualization , #100DaysToOffload
:slug:
vfio-part3
:summary:
Configuring your VM
:cover_image:
machine.jpg
Now that you have one of your GPUâs loaded up with the âvfio-pciâ kernel module, we can move onto the configuration of your VM environment.
Now you have several options in how to configure the VM, and how you want to run them. However if this is your first time doing a VFIO setup, I would recommend using âvirt-managerâ to manage your VM and configuration.
Optionally you could set this up as a headless host, with guest VMâs for Linux and Windows or single GPU pass through, but thatâs beyond the scope of this particular article.
On Debian based distros:
apt install virt-manager ovmf
On Arch:
pacman -S qemu edk2-ovmf virt-manager
Your package manager should pull down all the dependencies for you. On Arch you will have to enable the service with systemctl start libvirtd.service && systemctl enable libvirtd.service
Once you have âvirt-managerâ and the open source BIOSâs downloaded and installed you can proceed to setting up your VM.
Hereâs how you can add your user to the âkvmâ and âlibvirtâ group, as the last command that requires root on your machine.
"usermod -a -G kvm,libvirt <yourusername>"
Once you login again you can check to make sure your part of the right groups with id.
The output should look something like:
uid=1000(j) gid=1000(j) groups=1000(j),975(libvirt),992(kvm)
You will need a couple of files to make the most of your virtual machine(s). For the sake of this exercise lets say your installing Windows 10, you will need a copy of the installation media, which
actually provides. Along with some
drivers from RedHat. Once you have these ISOâs downloaded you can fire them in "/var/lib/libvirt/images" if you want virt-manager to automagically see them, otherwise youâll need to browse to them on your filesystem during the installation.
Alright firstly lets create a bare bones VM, selecting all the default options and your Windows10 ISO as the installation medium. Maybe at a later date I can put together some diretions on how to use an existing disk, or block device for pass through. But for now were just going to make sure that everything is setup properly with the VM and your host OS
1. Choose local install media (ISO image or CDROM)
2. Browse to your Win10 iso
3. Assign some CPU and Memory
4. Create the default 40 GiB disk
5. Check the âCustomize configuration before installâ checkbox
Once youâve clicked the Finish button, you will want to click the âAdd Hardwareâ button in the bottom left of the UI and select âStorageâ.
In the storage options you will want to select the âSelect or create custom storageâ option, and change the âDevice Typeâ to CDROM device. Click the âManageâŚâ button and select your VirtIO ISO that you downloaded previously, click Finish. This will allow us to install some drivers that you will need after the guest installation is complete.
Adjusting your CPUs to match your Architecture will likely lead to some better VM performance, but you can adjust this anytime the VM isnât running so itâs not a huge deal to nail this down right away. Below is a shot of my settings for my VM, you will want to make sure that the âhost-passthroughâ is selected, and match the configuration to the number of cores you want to allocate to your VM.
Alright itâs time to hit âBegin Installationâ, this should fire up your VM, go ahead and install windows as you normally would. I wonât cover that in here. If you were installing onto a block device the CDROM you added with the VirtIO drivers would be used during the installation process. However with the default configuration that we are working with here, we should be able to complete the installation without them for the sake of validating that everything is working properly.
Now that Windows 10 is installed and your booted into the VM, you will want to install the Guest Agent along with the VirtIO drivers that are mounted in your CDROM. I wonât go over in detail how todo this as itâs Windows, just âWinKey+Eâ browse to your VirtIO CDROM drive and click on a bunch of EXEâs that for your architecture. Once those are installed you can shutdown your Virtual Machine, do this from the Windows Start menu selecting âShutdownâ.
So far so good? Nothing has actually been passed through yet, but you have a VM setup that we can start testing of PCI-e pass through.
1. Click on the Settings again for your Windows 10 VM
2. Click âAdd Hardwareâ -> PCI Host Device.
3. Select the GPU that you isolated in the previous steps
4. Click Finish
5. Click âAdd Hardwareâ -> PCI Host Device
6. Select the audio device that corresponds to the GPU
7. Click Finish
Now the reason we have to pass through the audio device as well, is that the Windows driver expect that all of the hardware will be present when installing the driver (so itâs technically not required, but really is required if you actually want to install the vendors drivers).
Almost! Gotcha! Thatâs how it would work in a perfect world, however we have hardware vendors that like to prevent us from actually using hardware that weâve purchased. So here we are hiding VMâs and mucking about with XML.
In your terminal you will want to execute the following command:
virsh edit <yourvmnamehere>
This will popup whatever EDITOR you have set in your environment, use that to edit the XML to add the following sections. Add a new âkvmâ block within the âfeaturesâ section.
<features> ... <kvm> <hidden state='on'/> </kvm> ... </features>
Also adding the âvendor_idâ section to the hyperv section:
<hyperv> ... <vendor_id state='on' value='randomid'/> ... </hyperv>
Save / Exit the editor to persist the changes to your VMâs configuration, and now were âactuallyâ ready to fire it up.
Meanwhile back in virt-manager, just click the play button on your VM, Windows should boot up if everything went well. And we can move onto checking the âDevice Managerâ to make sure your GPU is being passed through properly.
Now you can actually go to your hardware vendors website and download the appropriate drivers for your device, as this hardware is actually being passed through, itâs capable of loading the actual drivers required for processing and not seen by Windows as an emulated device. Install it, reboot, profit.
======================================================================
|