📜 ⬆️ ⬇️

How to save gaming system from home PC with virtualization tools

Thanks to the competition and the development of NTP, modern PCs allow you to perform many simple and complex tasks simultaneously, such as playing and playing videos on TV, rendering graphics and reading news on the Internet, distributing torrents in parallel, etc. etc. Many go further and use multiple PCs for work and play. However, with the help of virtualization technologies, on the one hand, you can expand the capabilities of your PC, and on the other, save, because in fact, you can run multiple operating systems on the same hardware at the same time.


This article will be posted host settings for use in the "home", i.e. Talk about GPU PASSTHROUGH .

Introduction


First, a few words about virtualization in general. According to Wikipedia :
Virtualization - the provision of a set of computational resources or their logical combination, abstracted from the hardware implementation, while ensuring the logical isolation from each other of computational processes running on the same physical resource.
It is achieved both with the help of applications (for example VirtualBox, VMware) and at the level of systems that support hardware virtualization (for example, KVM, ESXi, Hyper-V). In the latter case, the performance loss compared with the native systems is minimal .

Here and later in the article there will be a description of the open source Proxmox virtualization system settings because it is moderately friendly, there is easy access to the console via a web form, as well as based on the Debian + kvm bundle, which has a lot of guides and descriptions i.e. documentation including and in Russian.

Iron requirements


We will need:

- processor and motherboard with support for VT-x, VT-d from Intel or AMD-Vi, IOMMU from AMD. Do not be lazy and ask if your copy supports these requirements.

As for the motherboard. I strongly recommend not to drive iron with mediocre wiring on the power board. By Z270 and Z390 ignore the orange zone or leave to work in stock.


Installation and Settings


I used the following game configuration:

- The PC for the host config was built on a far from the best motherboard, but in English-language forums this company is often praised for the fact that its hardware is most often suitable for such things:
The processor - i7 8700k
Mother - ASRock Z390M Pro4
Video card - INNO3D GeForce GTX 1070 iChill X4
- second PC (Morefine-M1s Mini PC),
- 2 mice
- 1 keyboard on the host, on other devices I used software,
- 3 connections to the Dell U2713HM monitor (VGA - for the integrated video card, HDMI - for the GTX1070, the Mini-PC is on DVI. Switched between video signals via the monitor menu)

Stage 0 - On the motherboard, we enable VT-d: Enable, Intel Vitrualization Technology: Enable, Primary Graphx adapter: VGA, Above 4G Decoding: Enable. If there is an opportunity, we must choose the one on which the host will work, i.e. weaker video card and switch to it.

1st stage - Install Proxmox on the host. For this:

1.1. Download the disk image from the official site

1.2. We write an image on a flash drive using special programs

1.3. Boot from the flash drive, and install it with an indication of which hard drive to install, enter the password for the future root user, and also set the network settings explicitly.

2nd stage - We connect over the network via the web interface using a second PC or
tablet (in my case it was a Mini-PC) to the host and configure Proxmox on this guide through the text console.

image

There is a small nuance that can be managed programmatically, but I decided that it would be easier to change the previous motherboard, since Gigabyte's motherboard did not meet this requirement:
1) Run the "dmesg | grep ecap »command.

2) On the IOMMU lines, the hexadecimal value after “ecap” indicates whether interrupt remapping is supported. 8, 9, a, b, c, d, e, or an f, interrupt remapping is supported. For example, "ecap 1000" indicates no interrupt remapping support. "Ecap 10207f" indicates interrupt remapping support.

Interrupt remapping support it IOMMU supports it.
If the condition is satisfied - continue.

So settings:

Open the file with a command from the console (you do not need to enter the double-lattice character, so I will separate in the command text from what needs to be added to the file)

## nano /etc/default/grub 

replace

 GRUB_CMDLINE_LINUX_DEFAULT="quiet" 

for intel processors

 GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on" 

for AMD processors

 GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on" 

next we give the command

 ## update-grub 

then reboot the host via the web interface

PC grub file in article
 # If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="Proxmox Virtual Environment" GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on" GRUB_CMDLINE_LINUX="" # Disable os-prober, it might add menu entries for each guest GRUB_DISABLE_OS_PROBER=true # Uncomment to enable BadRAM filtering, modify to suit your needs # This works with Linux (no patch required) and with any kernel that obtains # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef" # Uncomment to disable graphical terminal (grub-pc only) #GRUB_TERMINAL=console # The resolution used on graphical terminal # note that you can use only modes which your graphic card supports via VBE # you can see them in real GRUB with the command `vbeinfo' #GRUB_GFXMODE=640x480 # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux #GRUB_DISABLE_LINUX_UUID=true # Disable generation of recovery mode menu entries GRUB_DISABLE_RECOVERY="true" # Uncomment to get a beep at grub start #GRUB_INIT_TUNE="480 440 1" 


Add the necessary drivers to the configuration file

 ## nano /etc/modules 

 # /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. vfio vfio_iommu_type1 vfio_pci vfio_virqfd 

Register in console

 ## lspci 

A list of devices available for forwarding will be displayed, we find a block with a video card that interests us, in my case it is 2 devices in a group of video cards and the sound is at 01: 00.0 and 01: 00.1, so I prescribe the group right away.

 ## nano /etc/pve/qemu-server/vmid.conf 

 hostpci0: 01:00 

Register a command in the console to determine the model and its id

## lspci -n -s 01:00
01: 00.0 0300: 10de: 1b81 (rev a2)
01: 00.1 0403: 10de: 10f0 (rev a1)

Now we edit the file for our video card (in your case, the id will be different)

 ## nano /etc/modprobe.d/vfio.conf 

 options vfio-pci ids=10de:1b81,10de:10f0 

Blacklist driver

 ## nano /etc/modprobe.d/blacklist.conf 

 blacklist radeon blacklist nouveau blacklist nvidia 

Now we create the interface of the virtual machine through the web interface and edit the console. Here the string "args:" decides, because without it, the video card driver will detect virtualization, but by changing the name of the hardware, or rather hv_vendor_id = willitwork, we fix the problem with error 43 , which the video driver of the device can issue. There is a virtual machine number in proxmox used as a name.

 ## nano /etc/pve/qemu-server/<vmid>.conf 

 args: -cpu 'host,+kvm_pv_unhalt,+kvm_pv_eoi,hv_vendor_id=willitwork,kvm=off' ..... bios: ovmf ..... hostpci0: 01:00.0,pcie=1 ..... machine: q35 

Virtual machine settings file for PC in the article
 args: -cpu 'host,+kvm_pv_unhalt,+kvm_pv_eoi,hv_vendor_id=willitwork,kvm=off' bios: ovmf boot: dcn bootdisk: sata0 cores: 8 cpu: host hostpci0: 01:00.0,pcie=1 ide2: local:iso/ru-en_windows_10_1803_x86-x64.iso,media$ machine: q35 memory: 16384 net0: e1000=EA:20:FA:6A:D6:A0,bridge=vmbr0 numa: 0 ostype: win10 sata0: local-lvm:vm-100-disk-0,size=120G scsihw: virtio-scsi-pci smbios1: uuid=751edeca-d249-4c0d-9ded-b59d929df0f1 sockets: 1 usb0: host=1-8.4 usb1: host=1-8.3 vmgenid: b75aeb27-3102-458d-8e23-18cd27796dc1 


Now we reboot the host and start the virtual machine.

3rd stage - Through the Remote Video Console install Windows and drivers. In my case, Windows first recognized the proxmox video driver for working via the video console, then found the driver for the GTX1070, and after updating via the Internet (forced search for drivers on the network) I downloaded and installed the driver I needed for the gaming video card.

4th stage - Restart the Virtual Machine, switch the display of the video stream on the monitor to the video card connector and ... in my case everything worked right away, no errors 43 ... At the same time, the desktop is defined as # 2.

I tried to start the Blue-ray video - no problem, there are no delays and friezes with the video sequence, I launched Warhammer online - it started up and it was comfortable to play PvP, I launched GTA5 and a storyline jumped out quite comfortably. Visually there is no loss in performance.

If we need to forward the entire hard disk, we need to add the line in the virtual machine settings file:
ide0: volume = / dev / sda

or
sata0: volume = / dev / sda

Specifically, which sda / sdb / sdc / etc. can be specified in the web interface.

image

PS

There is also a fly in the ointment. The integrated sound can not be thrown separately, because there are other devices in its group, which, after a sound card is sent to a virtual machine, disappear for the host until the next host overload. In my case it is

00: 1f.0 ISA bridge: Intel Corporation Device a305 (rev 10)
00: 1f.3 Audio device: Intel Corporation Device a348 (rev 10)
00: 1f.4 SMBus: Intel Corporation Device a323 (rev 10)
00: 1f.5 Serial bus controller [0c80]: Intel Corporation Device a324 (rev 10)
00: 1f.6 Ethernet controller: Intel Corporation Device 15bc (rev 10)

Those. sound or through the video cable to the monitor or external sound card. USB ports are forwarding without problems. Unfortunately, the current is unsolvable. There is a remote connection option from another PC to the game, via RDP or SPICE . In this case, everything will be fine

Video card probing is not always perfect as in my case, either error 43 or something else interferes. Here are other settings that may help. Ideally, you need to search the network for successful setups and focus on them, which this one was for me, besides there is a list of hardware that allows you to achieve the same thing as me, but it is not complete.

UPDATE1:
A few notes on the periphery:
1. How to push the keyboard from the PS / 2 port into the VM:
first enter the command in the console
## dmesg | grep input
We are looking for a text in the text
...
input: AT Translated Set 2 keyboard as / devices / platform / i8042 / serio0 / input / input 2
...
We remember the number 2 at the end, it may be different. Then we add to the VM settings file in the line:
args: -object 'input-linux, id = kbd, evdev = / dev / input / event 2 , grab_all = on, repeat = on'
inserting 2 at the end evdev = / dev / input / event 2

For the mouse - the same.

2. By USB:
As for USB devices, everything is simpler there, devices are thrown straight from the web form by ID, or the port can be completely skipped. However, there is a nuance - if you for some reason cannot and, like me, throw an audio device into a VM, because it is contained in a group with key controllers without which the host cannot fully function, then port / device forwarding via USB solves this problem, but the sound may begin to fall off after a while, sizzle / buzz and other ... other things, while native system everything will be fine. In this case, you should not forward the port / device, but the USB controller itself as a PCIe device according to the method specified in the article. And everything will improve dramatically. But at the same time, after launching the VM with such settings through the host, it will no longer be possible to forward other devices from this controller.

3. Hard drives can be forwarded as via forwarding the controller as a PCIe device according to the method specified in the article (I do not recommend forwarding the controller integrated into the motherboard, only connected to PCIe), or directly:
go in
## cd / dev / disk / by-id
through dir look listing ...
we copy strings of the form ata-WDC_WD40EFRX-68WT0N6_WD-WCC4E1AC9SХ9, in which the connection interface, brand and serial number of the hard disk are registered. Then open the VM Configuration File and write:
sata1: volume = / dev / disk / by-id / ata-WDC_WD40EFRX-68WT0N6_WD-WCC4E1AC9SХ9
and everything works, while keeping in mind that sata0-sata5, i.e. for one VM, the number of disks connected in this way, including virtual ones, cannot exceed 6pcs.

Source: https://habr.com/ru/post/437598/