User Tools

Site Tools


tech:cheatsheets:linux:kvm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tech:cheatsheets:linux:kvm [2024/01/15 07:32] – removed - external edit (Unknown date) 127.0.0.1tech:cheatsheets:linux:kvm [2024/04/04 06:15] (current) waldemar
Line 1: Line 1:
 +====== Linux KVM ======
 +===== How to install =====
 +  * https://linuxize.com/post/how-to-install-kvm-on-ubuntu-20-04/
 +
 +===== How to boot Dual Boot Windows Partition =====
 +  * https://jianmin.dev/2020/jul/19/boot-your-windows-partition-from-linux-using-kvm/
 +  * http://disq.us/p/2ltujmy
 +
 +==== Windows Partition Dual Mount ====
 +  * https://superuser.com/a/1010125
 +
 +==== Spoof BIOS & Mainboard to avoid re-activation ====
 +  * https://www.remembertheusers.com/2021/06/0758-windows-10-p2v.html
 +  * https://gist.github.com/smoser/290f74c256c89cb3f3bd434a27b9f64c
 +  * https://libvirt.org/formatdomain.html#smbios-system-information
 +
 +===== GPU Acceleration =====
 +  * https://wiki.archlinux.org/title/QEMU/Guest_graphics_acceleration
 +  * https://arccompute.com/blog/libvfio-commodity-gpu-multiplexing/
 +  * https://github.com/Arc-Compute/LibVF.IO/
 +    * https://github.com/manalito/LibVF.IO
 +  * https://askubuntu.com/a/1389829
 +  * https://www.spice-space.org/download.html (spice-guest-tools)
 +  * https://github.com/mysteryx93/GPU-Passthrough-with-Optimus-Manager-Guide
 +  * https://forum.level1techs.com/t/solved-unable-to-isolate-gpu-for-vfio-workaround/196250/69?page=4
 +  * https://github.com/tuh8888/libvirt_win10_vm
 +  * https://github.com/QaidVoid/Complete-Single-GPU-Passthrough
 +  * https://superuser.com/questions/1804067/how-do-i-get-a-multi-display-virgl-3d-accelerated-qemu-vm-on-a-nvidia-card-in-vi
 +
 +Due to NVIDIA GPUs needing a license to be able to use vGPU it's currently not really recommended to passthrough a vGPU but instead the whole GPU. The best approach for a desktop machine is to use the single GPU passthrough approach which stops the X server and starts up a pre-configured virtual machine.
 +
 +===== Seamless Windows =====
 +  * https://github.com/Fmstrat/winapps
 +    * Newer/More up-to-date: https://github.com/winapps-org/winapps
 +  * https://github.com/Xpra-org/xpra
 +    * Snap does not work inside xpra (or so it seems).
 +    * https://www.baeldung.com/linux/snap-remove-disable
 +
 +===== Input Passthrough =====
 +  * https://passthroughpo.st/using-evdev-passthrough-seamless-vm-input/
 +
 +===== Hooks =====
 +  * https://github.com/portellam/libvirt-hooks/tree/master
 +  * https://github.com/PassthroughPOST/VFIO-Tools/tree/master
 +
 +===== Nested Virtualization =====
 +  * https://docs.fedoraproject.org/en-US/quick-docs/using-nested-virtualization-in-kvm/
 +
 +===== Drivers =====
 +==== NVIDIA ====
 +  * https://www.nvidia.com/download/driverResults.aspx/213194/en-us/
 +  * https://cloud.google.com/compute/docs/gpus/grid-drivers-table
 +  * https://foxi.buduanwang.vip/pan/vGPU/vgpu_unlock/drivers/
 +
 +=== 535.129.03 ===
 +  * https://us.download.nvidia.com/XFree86/Linux-x86_64/535.129.03/NVIDIA-Linux-x86_64-535.129.03.run
 +  * https://storage.googleapis.com/nvidia-drivers-us-public/GRID/vGPU16.2/NVIDIA-Linux-x86_64-535.129.03-grid.run
 +  * https://foxi.buduanwang.vip/pan/vGPU/vgpu_unlock/drivers/NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-custom.run
 +
 +
 +===== Sample Configurations =====
 +==== Old Notebook ====
 +[[infrastructure:inventory:hardware:notebooks:g500s]]
 +<file xml win11.xml>
 +<domain type="kvm">
 +  <name>win11</name>
 +  <uuid>4d99fd4a-4ffc-486f-8cf8-652c23f07b46</uuid>
 +  <metadata>
 +    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
 +      <libosinfo:os id="http://microsoft.com/win/11"/>
 +    </libosinfo:libosinfo>
 +  </metadata>
 +  <memory unit="KiB">7168000</memory>
 +  <currentMemory unit="KiB">7168000</currentMemory>
 +  <memoryBacking>
 +    <source type="memfd"/>
 +    <access mode="shared"/>
 +  </memoryBacking>
 +  <vcpu placement="static">4</vcpu>
 +  <os firmware="efi">
 +    <type arch="x86_64" machine="pc-q35-6.2">hvm</type>
 +    <boot dev="hd"/>
 +  </os>
 +  <features>
 +    <acpi/>
 +    <apic/>
 +    <hyperv mode="custom">
 +      <relaxed state="on"/>
 +      <vapic state="on"/>
 +      <spinlocks state="on" retries="8191"/>
 +    </hyperv>
 +    <vmport state="off"/>
 +  </features>
 +  <cpu mode="host-passthrough" check="none" migratable="on"/>
 +  <clock offset="localtime">
 +    <timer name="rtc" tickpolicy="catchup"/>
 +    <timer name="pit" tickpolicy="delay"/>
 +    <timer name="hpet" present="no"/>
 +    <timer name="hypervclock" present="yes"/>
 +  </clock>
 +  <on_poweroff>destroy</on_poweroff>
 +  <on_reboot>restart</on_reboot>
 +  <on_crash>destroy</on_crash>
 +  <pm>
 +    <suspend-to-mem enabled="no"/>
 +    <suspend-to-disk enabled="no"/>
 +  </pm>
 +  <devices>
 +    <emulator>/usr/bin/qemu-system-x86_64</emulator>
 +    <disk type="block" device="disk">
 +      <driver name="qemu" type="raw" cache="none" io="native"/>
 +      <source dev="/dev/md0"/>
 +      <target dev="sdb" bus="sata"/>
 +      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
 +    </disk>
 +    <controller type="sata" index="0">
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x1f" function="0x2"/>
 +    </controller>
 +    <controller type="usb" index="0" model="qemu-xhci" ports="15">
 +      <address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/>
 +    </controller>
 +    <controller type="pci" index="0" model="pcie-root"/>
 +    <controller type="pci" index="1" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="1" port="0x10"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" multifunction="on"/>
 +    </controller>
 +    <controller type="pci" index="2" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="2" port="0x11"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x1"/>
 +    </controller>
 +    <controller type="pci" index="3" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="3" port="0x12"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x2"/>
 +    </controller>
 +    <controller type="pci" index="4" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="4" port="0x13"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x3"/>
 +    </controller>
 +    <controller type="pci" index="5" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="5" port="0x14"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x4"/>
 +    </controller>
 +    <controller type="pci" index="6" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="6" port="0x15"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x5"/>
 +    </controller>
 +    <controller type="pci" index="7" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="7" port="0x16"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x6"/>
 +    </controller>
 +    <controller type="pci" index="8" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="8" port="0x17"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x7"/>
 +    </controller>
 +    <controller type="pci" index="9" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="9" port="0x18"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0" multifunction="on"/>
 +    </controller>
 +    <controller type="pci" index="10" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="10" port="0x19"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x1"/>
 +    </controller>
 +    <controller type="pci" index="11" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="11" port="0x1a"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x2"/>
 +    </controller>
 +    <controller type="pci" index="12" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="12" port="0x1b"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x3"/>
 +    </controller>
 +    <controller type="pci" index="13" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="13" port="0x1c"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x4"/>
 +    </controller>
 +    <controller type="pci" index="14" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="14" port="0x1d"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x5"/>
 +    </controller>
 +    <controller type="pci" index="15" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="15" port="0x1e"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x6"/>
 +    </controller>
 +    <controller type="pci" index="16" model="pcie-to-pci-bridge">
 +      <model name="pcie-pci-bridge"/>
 +      <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
 +    </controller>
 +    <controller type="virtio-serial" index="0">
 +      <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
 +    </controller>
 +    <interface type="network">
 +      <mac address="52:54:00:0f:45:19"/>
 +      <source network="default"/>
 +      <model type="e1000e"/>
 +      <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
 +    </interface>
 +    <channel type="unix">
 +      <target type="virtio" name="org.qemu.guest_agent.0"/>
 +      <address type="virtio-serial" controller="0" bus="0" port="2"/>
 +    </channel>
 +    <channel type="spicevmc">
 +      <target type="virtio" name="com.redhat.spice.0"/>
 +      <address type="virtio-serial" controller="0" bus="0" port="1"/>
 +    </channel>
 +    <input type="tablet" bus="usb">
 +      <address type="usb" bus="0" port="1"/>
 +    </input>
 +    <input type="mouse" bus="ps2"/>
 +    <input type="keyboard" bus="ps2"/>
 +    <tpm model="tpm-crb">
 +      <backend type="emulator" version="2.0"/>
 +    </tpm>
 +    <graphics type="spice">
 +      <listen type="none"/>
 +      <image compression="off"/>
 +      <gl enable="yes" rendernode="/dev/dri/by-path/pci-0000:00:02.0-render"/>
 +    </graphics>
 +    <sound model="ich9">
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x1b" function="0x0"/>
 +    </sound>
 +    <audio id="1" type="spice"/>
 +    <video>
 +      <model type="virtio" heads="1" primary="yes">
 +        <acceleration accel3d="yes"/>
 +      </model>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x0"/>
 +    </video>
 +    <redirdev bus="usb" type="spicevmc">
 +      <address type="usb" bus="0" port="2"/>
 +    </redirdev>
 +    <redirdev bus="usb" type="spicevmc">
 +      <address type="usb" bus="0" port="3"/>
 +    </redirdev>
 +    <memballoon model="virtio">
 +      <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
 +    </memballoon>
 +  </devices>
 +</domain>
 +</file>
 +
 +==== Desktop ====
 +[[infrastructure:inventory:kiryu|kiryu]]
 +<file xml win11-gpu.xml>
 +<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
 +  <name>win11-gpu</name>
 +  <uuid>6b1631e5-82b1-4667-ae10-d3fa5d436a2b</uuid>
 +  <metadata>
 +    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
 +      <libosinfo:os id="http://microsoft.com/win/11"/>
 +    </libosinfo:libosinfo>
 +  </metadata>
 +  <memory unit="KiB">20971520</memory>
 +  <currentMemory unit="KiB">20971520</currentMemory>
 +  <memoryBacking>
 +    <source type="memfd"/>
 +    <access mode="shared"/>
 +  </memoryBacking>
 +  <vcpu placement="static">20</vcpu>
 +  <os firmware="efi">
 +    <type arch="x86_64" machine="pc-q35-6.2">hvm</type>
 +    <bootmenu enable="no"/>
 +  </os>
 +  <features>
 +    <acpi/>
 +    <apic/>
 +    <hyperv mode="custom">
 +      <relaxed state="on"/>
 +      <vapic state="on"/>
 +      <spinlocks state="on" retries="8191"/>
 +      <vendor_id state="on" value="fuckyou"/>
 +    </hyperv>
 +    <kvm>
 +      <hidden state="on"/>
 +    </kvm>
 +    <vmport state="off"/>
 +  </features>
 +  <cpu mode="host-passthrough" check="none" migratable="on">
 +    <topology sockets="1" dies="1" cores="20" threads="1"/>
 +    <feature policy="disable" name="smep"/>
 +  </cpu>
 +  <clock offset="localtime">
 +    <timer name="rtc" tickpolicy="catchup"/>
 +    <timer name="pit" tickpolicy="delay"/>
 +    <timer name="hpet" present="no"/>
 +    <timer name="hypervclock" present="yes"/>
 +  </clock>
 +  <on_poweroff>destroy</on_poweroff>
 +  <on_reboot>restart</on_reboot>
 +  <on_crash>destroy</on_crash>
 +  <pm>
 +    <suspend-to-mem enabled="no"/>
 +    <suspend-to-disk enabled="no"/>
 +  </pm>
 +  <devices>
 +    <emulator>/usr/bin/qemu-system-x86_64</emulator>
 +    <disk type="block" device="disk">
 +      <driver name="qemu" type="raw"/>
 +      <source dev="/dev/sdf"/>
 +      <target dev="sdb" bus="sata"/>
 +      <boot order="2"/>
 +      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
 +    </disk>
 +    <controller type="usb" index="0" model="qemu-xhci" ports="15">
 +      <address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/>
 +    </controller>
 +    <controller type="pci" index="0" model="pcie-root"/>
 +    <controller type="pci" index="1" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="1" port="0x10"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" multifunction="on"/>
 +    </controller>
 +    <controller type="pci" index="2" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="2" port="0x11"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x1"/>
 +    </controller>
 +    <controller type="pci" index="3" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="3" port="0x12"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x2"/>
 +    </controller>
 +    <controller type="pci" index="4" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="4" port="0x13"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x3"/>
 +    </controller>
 +    <controller type="pci" index="5" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="5" port="0x14"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x4"/>
 +    </controller>
 +    <controller type="pci" index="6" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="6" port="0x15"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x5"/>
 +    </controller>
 +    <controller type="pci" index="7" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="7" port="0x16"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x6"/>
 +    </controller>
 +    <controller type="pci" index="8" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="8" port="0x17"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x7"/>
 +    </controller>
 +    <controller type="pci" index="9" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="9" port="0x18"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0" multifunction="on"/>
 +    </controller>
 +    <controller type="pci" index="10" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="10" port="0x19"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x1"/>
 +    </controller>
 +    <controller type="pci" index="11" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="11" port="0x1a"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x2"/>
 +    </controller>
 +    <controller type="pci" index="12" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="12" port="0x1b"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x3"/>
 +    </controller>
 +    <controller type="pci" index="13" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="13" port="0x1c"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x4"/>
 +    </controller>
 +    <controller type="pci" index="14" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="14" port="0x1d"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x5"/>
 +    </controller>
 +    <controller type="pci" index="15" model="pcie-root-port">
 +      <model name="pcie-root-port"/>
 +      <target chassis="15" port="0x1e"/>
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x6"/>
 +    </controller>
 +    <controller type="pci" index="16" model="pcie-to-pci-bridge">
 +      <model name="pcie-pci-bridge"/>
 +      <address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
 +    </controller>
 +    <controller type="sata" index="0">
 +      <address type="pci" domain="0x0000" bus="0x00" slot="0x1f" function="0x2"/>
 +    </controller>
 +    <controller type="virtio-serial" index="0">
 +      <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
 +    </controller>
 +    <interface type="network">
 +      <mac address="52:54:00:5c:d0:4a"/>
 +      <source network="default"/>
 +      <model type="e1000e"/>
 +      <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
 +    </interface>
 +    <channel type="unix">
 +      <target type="virtio" name="org.qemu.guest_agent.0"/>
 +      <address type="virtio-serial" controller="0" bus="0" port="2"/>
 +    </channel>
 +    <input type="mouse" bus="virtio">
 +      <address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
 +    </input>
 +    <input type="keyboard" bus="virtio">
 +      <address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
 +    </input>
 +    <input type="mouse" bus="ps2"/>
 +    <input type="keyboard" bus="ps2"/>
 +    <tpm model="tpm-crb">
 +      <backend type="emulator" version="2.0"/>
 +    </tpm>
 +    <audio id="1" type="spice"/>
 +    <hostdev mode="subsystem" type="pci" managed="yes">
 +      <source>
 +        <address domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
 +      </source>
 +      <rom file="/usr/share/vgabios/gtx2070-vbios.rom"/>
 +      <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="pci" managed="yes">
 +      <source>
 +        <address domain="0x0000" bus="0x01" slot="0x00" function="0x1"/>
 +      </source>
 +      <rom file="/usr/share/vgabios/gtx2070-vbios.rom"/>
 +      <address type="pci" domain="0x0000" bus="0x09" slot="0x00" function="0x0"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="pci" managed="yes">
 +      <source>
 +        <address domain="0x0000" bus="0x01" slot="0x00" function="0x2"/>
 +      </source>
 +      <rom file="/usr/share/vgabios/gtx2070-vbios.rom"/>
 +      <address type="pci" domain="0x0000" bus="0x0a" slot="0x00" function="0x0"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="pci" managed="yes">
 +      <source>
 +        <address domain="0x0000" bus="0x01" slot="0x00" function="0x3"/>
 +      </source>
 +      <rom file="/usr/share/vgabios/gtx2070-vbios.rom"/>
 +      <address type="pci" domain="0x0000" bus="0x0b" slot="0x00" function="0x0"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="usb" managed="yes">
 +      <source>
 +        <vendor id="0x046d"/>
 +        <product id="0xc32b"/>
 +      </source>
 +      <address type="usb" bus="0" port="2"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="usb" managed="yes">
 +      <source>
 +        <vendor id="0x1050"/>
 +        <product id="0x0407"/>
 +      </source>
 +      <address type="usb" bus="0" port="3"/>
 +    </hostdev>
 +    <hostdev mode="subsystem" type="usb" managed="yes">
 +      <source>
 +        <vendor id="0x046d"/>
 +        <product id="0xc539"/>
 +      </source>
 +      <address type="usb" bus="0" port="1"/>
 +    </hostdev>
 +    <memballoon model="virtio">
 +      <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
 +    </memballoon>
 +  </devices>
 +  <qemu:commandline>
 +    <qemu:arg value="-device"/>
 +    <qemu:arg value="ich9-intel-hda,bus=pcie.0,addr=0x1b"/>
 +    <qemu:arg value="-device"/>
 +    <qemu:arg value="hda-micro,audiodev=hda"/>
 +    <qemu:arg value="-audiodev"/>
 +    <qemu:arg value="pa,id=hda,server=/tmp/pulse-socket"/>
 +  </qemu:commandline>
 +</domain>
 +</file>
 +
 +<file bash /etc/libvirt/hooks/qemu>
 +#!/bin/bash
 +
 +GUEST_NAME="$1"
 +HOOK_NAME="$2"
 +STATE_NAME="$3"
 +MISC="${@:4}"
 +
 +BASEDIR="$(dirname $0)"
 +
 +HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME"
 +set -e # If a script exits with an error, we should as well.
 +
 +echo "QEMU hook: $GUEST_NAME/$HOOK_NAME/$STATE_NAME" >> /var/log/libvirt/custom_hooks.log
 +
 +if [ -f "$HOOKPATH" ]; then
 +eval \""$HOOKPATH"\" "$@" >> /var/log/libvirt/custom_hooks.log
 +elif [ -d "$HOOKPATH" ]; then
 +while read file; do
 +  eval \""$file"\" "$@" >> /var/log/libvirt/custom_hooks.log
 +done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)"
 +fi
 +</file>
 +
 +<file bash /etc/libvirt/hooks/qemu.d/win11-gpu/prepare/begin/start.sh>
 +#!/bin/bash
 +set -x
 +
 +# Stop display manager
 +systemctl stop display-manager
 +# systemctl --user -M YOUR_USERNAME@ stop plasma*
 +
 +# Unbind VTconsoles: might not be needed
 +echo 0 > /sys/class/vtconsole/vtcon0/bind
 +echo 0 > /sys/class/vtconsole/vtcon1/bind
 +
 +# Unbind EFI Framebuffer
 +echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
 +
 +# Unload NVIDIA kernel modules
 +modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
 +
 +# Unload AMD kernel module
 +# modprobe -r amdgpu
 +
 +# Detach GPU devices from host
 +# Use your GPU and HDMI Audio PCI host device
 +virsh nodedev-detach pci_0000_01_00_0
 +virsh nodedev-detach pci_0000_01_00_1
 +virsh nodedev-detach pci_0000_01_00_2
 +virsh nodedev-detach pci_0000_01_00_3
 +
 +# Load vfio module
 +modprobe vfio-pci
 +</file>
 +
 +<file bash /etc/libvirt/hooks/qemu.d/win11-gpu/release/end/stop.sh>
 +#!/bin/bash
 +set -x
 +
 +# Attach GPU devices to host
 +# Use your GPU and HDMI Audio PCI host device
 +virsh nodedev-reattach pci_0000_01_00_0
 +virsh nodedev-reattach pci_0000_01_00_1
 +virsh nodedev-reattach pci_0000_01_00_2
 +virsh nodedev-reattach pci_0000_01_00_3
 +
 +# Unload vfio module
 +modprobe -r vfio-pci
 +
 +# Load AMD kernel module
 +#modprobe amdgpu
 +
 +# Rebind framebuffer to host
 +echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
 +
 +# Load NVIDIA kernel modules
 +modprobe nvidia_drm
 +modprobe nvidia_modeset
 +modprobe nvidia_uvm
 +modprobe nvidia
 +
 +# Bind VTconsoles: might not be needed
 +echo 1 > /sys/class/vtconsole/vtcon0/bind
 +echo 1 > /sys/class/vtconsole/vtcon1/bind
 +
 +# Restart Display Manager
 +systemctl start display-manager
 +</file>
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki