656 lines
30 KiB
HTML
656 lines
30 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
|
||
<head>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<script defer language="javascript" type="text/javascript" src="/js/bundle.min.14549c76bbc96f0af1574b0259efd70e52908cd36fb4d14ed3d290a1b6479eae.js"></script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
|
||
<link rel="icon" href=images/tiger.png>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!-- Open Graph image and Twitter Card metadata -->
|
||
|
||
<title itemprop="name">tinfoil-hat.net - Gpu Passtrough Mint21</title>
|
||
<meta property="og:title" content=tinfoil-hat.net - Gpu Passtrough Mint21 />
|
||
<meta name="twitter:title" content=tinfoil-hat.net - Gpu Passtrough Mint21 />
|
||
<meta itemprop="name" content=tinfoil-hat.net - Gpu Passtrough Mint21 />
|
||
<meta name="application-name" content=tinfoil-hat.net - Gpu Passtrough Mint21 />
|
||
<meta property="og:site_name" content="" />
|
||
|
||
|
||
<meta name="description" content="" />
|
||
<meta itemprop="description" content="" />
|
||
<meta property="og:description" content="" />
|
||
<meta name="twitter:description" content="" />
|
||
|
||
|
||
<base href="/posts/gpu-passtrough-mint21/" />
|
||
<link rel="canonical" href="/posts/gpu-passtrough-mint21/" itemprop="url" />
|
||
<meta name="url" content="/posts/gpu-passtrough-mint21/" />
|
||
<meta name="twitter:url" content="/posts/gpu-passtrough-mint21/" />
|
||
<meta property="og:url" content="/posts/gpu-passtrough-mint21/" />
|
||
|
||
|
||
<meta property="og:updated_time" content="2024-05-31T00:42:45+02:00" />
|
||
|
||
|
||
<link rel="sitemap" type="application/xml" title="Sitemap" href='/sitemap.xml' />
|
||
|
||
<meta name="robots" content="index,follow" />
|
||
<meta name="googlebot" content="index,follow" />
|
||
|
||
|
||
<meta name="twitter:site" content="" />
|
||
<meta name="twitter:creator" content="" />
|
||
<meta property="fb:admins" content="" />
|
||
|
||
|
||
<meta name="apple-mobile-web-app-title" content="" />
|
||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<meta name="generator" content="Hugo 0.111.3">
|
||
|
||
|
||
|
||
|
||
|
||
<link type="text/css" rel="stylesheet" href="/css/bundle.min.94a339836f89f0d25f31980cb6b0631da21e20af128308747ce44e0525eb16ef.css">
|
||
|
||
|
||
|
||
<style>
|
||
body {
|
||
--sidebar-bg-color: #202020;
|
||
--sidebar-img-border-color: #515151;
|
||
--sidebar-p-color: #909090;
|
||
--sidebar-h1-color: #FFF;
|
||
--sidebar-a-color: #FFF;
|
||
--sidebar-socials-color: #FFF;
|
||
--text-color: #222;
|
||
--bkg-color: #FAF9F6;
|
||
--post-title-color: #303030;
|
||
--list-color: #5A5A5A;
|
||
--link-color: #268BD2;
|
||
--date-color: #515151;
|
||
--table-border-color: #E5E5E5;
|
||
--table-stripe-color: #F9F9F9;
|
||
--code-color: #000;
|
||
--code-background-color: #E5E5E5;
|
||
--code-block-color: #FFF;
|
||
--code-block-background-color: #272822;
|
||
--moon-sun-color: #FFF;
|
||
--moon-sun-background-color: #515151;
|
||
}
|
||
body.dark-theme {
|
||
--text-color: #EEE;
|
||
--bkg-color: #121212;
|
||
--post-title-color: #DBE2E9;
|
||
--list-color: #9D9D9D;
|
||
--link-color: #268BD2;
|
||
--date-color: #9A9A9A;
|
||
--table-border-color: #515151;
|
||
--table-stripe-color: #202020;
|
||
--code-color: #FFF;
|
||
--code-background-color: #515151;
|
||
--code-block-color: #FFF;
|
||
--code-block-background-color: #272822;
|
||
}
|
||
body {
|
||
background-color: var(--bkg-color);
|
||
}
|
||
</style>
|
||
|
||
</head>
|
||
|
||
<body class="">
|
||
<div class="wrapper">
|
||
<aside class="sidebar">
|
||
<div class="container sidebar-sticky">
|
||
<div class="light-dark" align="right">
|
||
<button class="btn-light-dark" title="Toggle light/dark mode">
|
||
<svg class="moon" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16">
|
||
<path fill="currentColor" d="M6 .278a.768.768 0 0 1 .08.858a7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277c.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316a.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71C0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"/>
|
||
</svg>
|
||
<svg class="sun" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16">
|
||
<path fill="currentColor" d="M8 12a4 4 0 1 0 0-8a4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="sidebar-about">
|
||
<h1 class="brand">
|
||
|
||
<a href="/">
|
||
<img src="/images/tiger.png" alt="brand image">
|
||
</a>
|
||
|
||
|
||
<a href="/">
|
||
<h1>tinfoil-hat.net</h1>
|
||
</a>
|
||
|
||
</h1>
|
||
<p class="lead">
|
||
A secure home for every tinfoil-hat
|
||
</p>
|
||
</div>
|
||
|
||
<nav>
|
||
<ul class="sidebar-nav">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="heading">
|
||
<a href="/posts/">Posts</a>
|
||
</li>
|
||
|
||
<li class="sub-heading">
|
||
Recent
|
||
</li>
|
||
|
||
<li class="bullet">
|
||
<a href="/posts/bug-out-bag/">Bugout Bag</a>
|
||
</li>
|
||
|
||
<li class="bullet">
|
||
<a href="/posts/gpu-passtrough-mint21/">Gpu Passtrough Mint21</a>
|
||
</li>
|
||
|
||
<li class="bullet">
|
||
<a href="/posts/vbox-autostart/">Vbox Autostart</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="heading">
|
||
<a href="/unixporn/">Unixporn</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="heading">
|
||
<a href="/webring/">Webring</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</ul>
|
||
</nav>
|
||
|
||
|
||
|
||
<a target="_blank" class="social" title="Gitlab" href="https://git.tinfoil-hat.net">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="1.2em" height="1.2em" viewBox="-2 -2.5 24 24">
|
||
<path fill="currentColor" d='M10.006 18.443L6.326 7.118h7.36l-3.68 11.325zm0 0L1.168 7.118h5.158l3.68 11.325zM1.168 7.118l8.838 11.325-9.68-7.032a.762.762 0 0 1-.276-.852l1.118-3.441zm0 0L3.385.296a.38.38 0 0 1 .724 0l2.217 6.822H1.168zm8.838 11.325l3.68-11.325h5.157l-8.837 11.325zm8.837-11.325l1.119 3.441a.762.762 0 0 1-.277.852l-9.68 7.032 8.838-11.325zm0 0h-5.157L15.902.296a.38.38 0 0 1 .725 0l2.216 6.822z' />
|
||
|
||
</svg>
|
||
</a>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<a target="_blank" class="social" title="YouTube" href="https://tube.tinfoil-hat.net">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="1.2em" height="1.2em" viewBox="0 0 24 24">
|
||
<path fill="currentColor" d="M12.006 19.012h-.02c-.062 0-6.265-.012-7.83-.437a2.5 2.5 0 0 1-1.764-1.765A26.494 26.494 0 0 1 1.986 12a26.646 26.646 0 0 1 .417-4.817A2.564 2.564 0 0 1 4.169 5.4c1.522-.4 7.554-.4 7.81-.4H12c.063 0 6.282.012 7.831.437c.859.233 1.53.904 1.762 1.763c.29 1.594.427 3.211.407 4.831a26.568 26.568 0 0 1-.418 4.811a2.51 2.51 0 0 1-1.767 1.763c-1.52.403-7.553.407-7.809.407Zm-2-10.007l-.005 6l5.212-3l-5.207-3Z"/>
|
||
</svg>
|
||
</a>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<a target="_blank" class="social" title="RSS Feed" href="/posts/index.xml">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1.2em" viewBox="0 0 1280.000000 1280.000000">
|
||
<g transform="translate(0.000000,1280.000000) scale(0.100000,-0.100000)" fill="currentColor">
|
||
<path d="M2295 11929 c-284 -12 -642 -45 -707 -65 -17 -5 -18 -63 -18 -1039 0 -569 4 -1036 8 -1039 5 -3 74 6 153 19 510 86 1168 95 1789 25 1348 -153 2602 -677 3670 -1531 385 -308 820 -744 1126 -1129 842 -1060 1362 -2313 1514 -3650 70 -621 61 -1279 -25 -1789 -13 -79 -22 -148 -19 -153 3 -4 471 -8 1039 -8 l1035 0 5 23 c51 225 85 942 67 1419 -23 605 -77 1044 -198 1617 -294 1400 -927 2734 -1823 3846 -1043 1295 -2364 2259 -3909 2854 -1158 447 -2451 656 -3707 600z"/>
|
||
<path d="M2255 7845 c-269 -25 -620 -81 -667 -106 -17 -9 -18 -55 -18 -899 0 -706 3 -890 13 -890 6 0 66 18 132 41 130 44 288 79 467 105 154 21 577 30 749 15 1207 -107 2267 -823 2814 -1902 166 -327 268 -637 330 -1001 38 -227 48 -384 42 -662 -8 -348 -44 -590 -126 -831 -23 -66 -41 -126 -41 -132 0 -10 184 -13 890 -13 844 0 890 1 899 18 27 50 88 452 110 725 14 162 14 624 1 782 -59 703 -233 1323 -545 1945 -481 956 -1313 1788 -2270 2268 -620 310 -1239 483 -1940 542 -165 14 -669 10 -840 -5z"/>
|
||
<path d="M2519 3815 c-391 -66 -725 -336 -868 -703 -79 -201 -96 -462 -45 -677 83 -344 338 -641 666 -774 116 -47 205 -69 330 -80 412 -39 811 153 1040 500 193 292 240 648 128 981 -135 403 -492 699 -914 757 -100 14 -241 12 -337 -4z"/>
|
||
</g>
|
||
</svg>
|
||
</a>
|
||
|
||
|
||
<a target="_blank" class="social" title="Email" href="mailto://mail@tinfoil-hat.net">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1.2em" viewBox="0 0 485.211 485.211">
|
||
<path fill="currentColor" d="M301.393,241.631L464.866,424.56H20.332l163.474-182.928l58.801,51.443L301.393,241.631z M462.174,60.651H23.027 l219.579,192.142L462.174,60.651z M324.225,221.67l160.986,180.151V80.792L324.225,221.67z M0,80.792v321.029L160.972,221.64 L0,80.792z"/>
|
||
</svg>
|
||
</a>
|
||
|
||
|
||
<p class="footnote">
|
||
powered by <a target="_blank" href="https://gohugo.io">Hugo</a> | themed with <a target="_blank" href="https://github.com/lukeorth/poison">poison</a>
|
||
<br>
|
||
© 2024 . All rights reserved.
|
||
</p>
|
||
|
||
</div>
|
||
</aside>
|
||
|
||
<main class="content container">
|
||
<div class="post">
|
||
<div class="info">
|
||
<h1 class="post-title">
|
||
<a href="/posts/gpu-passtrough-mint21/">Gpu Passtrough Mint21</a>
|
||
</h1>
|
||
|
||
<div class="headline">
|
||
<div>
|
||
|
||
<time datetime=" 2024-05-31T00:42:45+0200" class="post-date">
|
||
May 31, 2024
|
||
</time>
|
||
|
||
<span> - </span>
|
||
<span class="reading-time">
|
||
|
||
|
||
|
||
|
||
<span>9 mins read</span>
|
||
</span>
|
||
</div>
|
||
|
||
|
||
<ul class="tags">
|
||
|
||
<li class="tag-Linux">
|
||
<a href="/tags/linux">Linux</a>
|
||
</li>
|
||
|
||
<li class="tag-Server">
|
||
<a href="/tags/server">Server</a>
|
||
</li>
|
||
|
||
<li class="tag-Technology">
|
||
<a href="/tags/technology">Technology</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
|
||
</div>
|
||
|
||
<p>Before we begin, let’s install some necessary packages:</p>
|
||
<pre tabindex="0"><code>sudo apt install libvirt-daemon-system libvirt-clients qemu-kvm qemu-utils virt-manager ovmf
|
||
</code></pre><p>Enable required services <code>sudo systemctl enable --now libvirtd</code></p>
|
||
<p>You should add your user to libvirt group (many times it’s automatically done)</p>
|
||
<pre tabindex="0"><code>usermod -aG kvm,input,libvirt <username>
|
||
</code></pre><p>Restart your machine and boot into BIOS. Enable a feature called <strong>IOMMU</strong>. You’ll also need to enable CPU virtualization. For Intel processors, look for something called <strong>VT-d</strong>. For AMD, look for something called <strong>AMD-Vi</strong>. My motherboard is unique so I had to enable a feature called <strong>SVM Mode</strong>. Save any changes and restart the machine.</p>
|
||
<p>Once you’ve booted into the host, make sure that IOMMU is enabled: <code>dmesg | grep IOMMU</code></p>
|
||
<p>Also check that CPU virtualization is enabled:</p>
|
||
<ul>
|
||
<li>For Intel: <code>dmesg | grep VT-d</code></li>
|
||
<li>For AMD: <code>dmesg | grep AMD-Vi</code></li>
|
||
</ul>
|
||
<p>Now you’re going to need to pass the hardware-enabled IOMMU functionality into the kernel as a kernel parameter. For our purposes, it makes the most sense to enable this feature at boot-time. Depending on your boot-loader (i.e. grub, systemd, rEFInd), you’ll have to modify a specific configuration file. Since my machine uses systemd and these configuration files are often overwritten on updates, I will be using a tool called kernelstub:</p>
|
||
<ul>
|
||
<li>For Intel: <code>sudo kernelstub --add-options "intel_iommu=on"</code></li>
|
||
<li>For AMD: <code>sudo kernelstub --add-options "amd_iommu=on"</code></li>
|
||
</ul>
|
||
<p>Similarly, if your system is configured with GRUB2, you can achieve the same result by editing the /etc/default/grub file with sudo permissions and including the kernel parameter as follows:</p>
|
||
<ul>
|
||
<li>For Intel: <code>GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on"</code></li>
|
||
<li>For AMD: <code>GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on"</code></li>
|
||
</ul>
|
||
<p>Edit <code>/etc/default/grub</code></p>
|
||
<pre tabindex="0"><code>GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on"
|
||
</code></pre><p>or for AMD</p>
|
||
<pre tabindex="0"><code>GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on"
|
||
</code></pre><h1 id="2-creating-a-stub-for-the-gpu">2. Creating a stub for the GPU</h1>
|
||
<p>Next, we need to update the kernel command line to configure <strong>vfio-pci</strong> to consume each passthrough device to prevent it from being used by the hypervisor. If using GRUB, add another argument to <strong>GRUB_CMDLINE_LINUX_DEFAULT</strong> in <strong>/etc/default/grub</strong> in the following format (where PLACEHOLDER should be replaced with a comma-separated list of hardware IDs for your passthrough devices):</p>
|
||
<pre tabindex="0"><code>vfio_pci.ids=PLACEHOLDER
|
||
</code></pre><p>Once you modify this variable, it should look similar to the following example:</p>
|
||
<pre tabindex="0"><code>GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on vfio_pci.ids=10de:1c03,10de:10f1"
|
||
</code></pre><p>Finally, run the following commands (in the listed order) and reboot the hypervisor yet again:</p>
|
||
<pre tabindex="0"><code>update-initramfs -u
|
||
</code></pre><pre tabindex="0"><code>update-grub
|
||
</code></pre><p>After the hypervisor reboots, check that each required device was consumed by the vfio-pci kernel module. You should see vfio-pci on the line starting with “Kernel driver in use:” for each passthrough device:</p>
|
||
<pre tabindex="0"><code>03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 23 [Radeon RX 6600/6600 XT/6600M] [1002:73ff] (rev c7)
|
||
Subsystem: XFX Limited Navi 23 [Radeon RX 6600/6600 XT/6600M] [1eae:6505]
|
||
Kernel driver in use: vfio-pci
|
||
Kernel modules: amdgpu
|
||
03:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] [1002:ab28]
|
||
Subsystem: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] [1002:ab28]
|
||
Kernel driver in use: vfio-pci
|
||
Kernel modules: snd_hda_intel
|
||
</code></pre><h1 id="3-imaging-the-gpu-rom">3. Imaging the GPU ROM</h1>
|
||
<p>Before you can image the GPU ROM, you need to make sure that you’ve successfully completed the prior steps to blacklist the GPU and that you’ve configured your motherboard to use another graphics device as the primary video output. This is important because the GPU needs to be uninitialized when it is imaged or the ROM file may be garbled from previous initializations.</p>
|
||
<p>For some graphics cards or other PCI-e devices, this step may be unnecessary. Some GPUs can operate just fine without mapping a static ROM file; the virtual machine can just directly access the device ROM. Your results may vary, though. The primary purpose of this step is to ensure that successive virtual machine reboots won’t require the hypervisor to be rebooted to reset the GPU’s ROM to an uninitialized state.</p>
|
||
<p>First, make sure that your hypervisor has been freshly rebooted so that your GPU’s ROM is uninitialized. Next, run the following commands (replacing the example BDF identifier with your device’s BDF identifier) to obtain an image of the GPU ROM:</p>
|
||
<pre tabindex="0"><code>export PCIE_BDF_IDENT='01:00.0'
|
||
echo 1 > /sys/bus/pci/devices/0000\:"${PCIE_BDF_IDENT}"/rom
|
||
cat /sys/bus/pci/devices/0000\:"${PCIE_BDF_IDENT}"/rom > \
|
||
/usr/share/qemu/gpu-"$(date +%Y%m%dT%H%m%S)".rom
|
||
$ echo 0 > /sys/bus/pci/devices/0000\:"${PCIE_BDF_IDENT}"/rom
|
||
</code></pre><p>Note: The process of extracting your GPU’s ROM only needs to be done for the primary function of your device, i.e. the “graphics” portion of the device.</p>
|
||
<p>The GPU ROM is now available at /usr/share/qemu/gpu-YYYYMMDDTHHMMSS.rom for use by libvirt and QEMU. You can name this file whatever you want for your own convenience.</p>
|
||
<h1 id="4-preparing-the-virtual-machine">4. Preparing the Virtual Machine</h1>
|
||
<p>Now that the hypervisor is prepared for GPU passthrough, we need to configure the Windows® 10 virtual machine so that the GPU’s driver is unable to detect the virtualization environment. For the purposes of this tutorial, we’ll be using virsh to manually edit the virtual machine configuration. All of these changes will remain intact, even if you use Virtual Machine Manager.</p>
|
||
<h2 id="configuring-the-virtual-cpu">Configuring the Virtual CPU</h2>
|
||
<p>First, we must ensure that the virtual machine’s CPU model is set to <code>host-passthrough</code>. <strong>It is very important that you understand the difference between the “Copy host CPU configuration” checkbox and the</strong> <code>host-passthrough</code> CPU model: The former picks a similar virtual CPU that simply covers the feature set of the host CPU, where the latter configures QEMU’s virtual CPU to directly masquerade as the host’s CPU model.</p>
|
||
<p>The below figure containing screenshots of Task Manager in the guest operating system demonstrates the difference between the two configurations:</p>
|
||
<p><a href="/images/GPU/cpu.png"><img src="/images/GPU/cpu.png" alt="tpm.png"></a></p>
|
||
<p>Run virsh edit <code><machine></code> to edit the configuration of your virtual machine (where <code><machine></code> is the name of your virtual machine’s libvirt profile). Find the <code><cpu></code> node in the XML tree and edit the value of its <code>mode</code> attribute so that it looks similar to the following line.</p>
|
||
<pre tabindex="0"><code><cpu mode='host-passthrough' check='partial'>
|
||
</code></pre><p><em>Note: You may save the configuration and reboot after every modification to observe how it modifies the virtualization environment from your guest operating system’s perspective.</em></p>
|
||
<h2 id="hiding-the-virtualization-environment">Hiding the Virtualization Environment</h2>
|
||
<p>The first step to hide the virtualization environment is to disable the machine specific registers relating to KVM paravirtualization. Add the following code inside the <code><features></code> node of your virtual machine’s configuration using the <code>virsh edit <machine></code>command.</p>
|
||
<pre tabindex="0"><code><kvm>
|
||
<hidden state='on'/>
|
||
</kvm>
|
||
</code></pre><p>Next, select one of the following methods to try to defeat virtualization detection from the guest operating system. There are two methods that can be used to hide the virtualization environment in Windows® 10:</p>
|
||
<ul>
|
||
<li>
|
||
<p>Method A is the preferred method since it makes the virtualization environment harder to detect in the guest operating system and provides great performance if your CPU supports <code>constant_tsc</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p>Method B is an alternative that uses Hyper-V enlightenments for improved performance on systems that don’t support <code>constant_tsc</code>, but it may be easier to defeat via driver updates.</p>
|
||
</li>
|
||
</ul>
|
||
<p><em>Note: Each method is mutually exclusive since Method B requires the hypervisor CPUID bit to be set so that Windows® will recognize and use the Hyper-V clock.</em></p>
|
||
<p>Open your virtual machine’s configuration for editing again by running virsh edit <!-- raw HTML omitted --> and pick one of the following methods to follow. It is recommended to reboot and perform benchmarks after each modification (where permitted by applicable end-user license agreements) so that you may determine which is the best performing configuration for your system.</p>
|
||
<p>Open your virtual machine’s configuration for editing again by running <code>virsh edit <machine></code> and pick one of the following methods to follow. It is recommended to reboot and perform benchmarks after each modification (where permitted by applicable end-user license agreements) so that you may determine which is the best performing configuration for your system.</p>
|
||
<h2 id="method-a-disabling-the-hypervisor-cpuid-bit">Method A: Disabling the Hypervisor CPUID Bit</h2>
|
||
<p>Inside the <code><cpu></code> block of your virtual machine’s configuration, add the following line to disable the hypervisor CPUID bit.</p>
|
||
<pre tabindex="0"><code><feature policy='disable' name='hypervisor'/>
|
||
</code></pre><p>This line should completely hide the virtualization environment from the perspective of the guest operating system, thus causing any virtualization check to pass.</p>
|
||
<h2 id="method-b-adjusting-the-hyper-v-enlightenments">Method B: Adjusting the Hyper-V Enlightenments</h2>
|
||
<p>Inside the <code><features></code> node of your virtual machine’s configuration, make sure that you have a <code><hyperv></code> node that looks similar to the below example. You may use this example verbatim in your configuration.</p>
|
||
<pre tabindex="0"><code><hyperv>
|
||
<relaxed state='on'/>
|
||
<vapic state='on'/>
|
||
<spinlocks state='on' retries='8191'/>
|
||
<vendor_id state='on' value='ahb6Wah2geeb'/>
|
||
</hyperv>
|
||
</code></pre><p>The <code><hyperv></code> node’s contents will ensure that Hyper-V enlightenments are available to the guest operating system for higher performance. The <code>vendor_id</code> tag overrides the default Hyper-V vendor ID to something unexpected by the graphics drivers, causing them to successfully pass the virtualization check.</p>
|
||
<p>Next, inside the <code><clock></code> node of your virtual machine’s configuration, add the following line to enable the Hyper-V clock.</p>
|
||
<pre tabindex="0"><code> <timer name='hypervclock' present='yes'/>
|
||
</code></pre><h2 id="tpm">TPM</h2>
|
||
<p><a href="/images/GPU/tpm.png"><img src="/images/GPU/tpm.png" alt="tpm.png"></a></p>
|
||
<h2 id="passing-keyboardmouse-via-evdev">Passing keyboard/mouse via Evdev</h2>
|
||
<p>If you do not have a spare mouse or keyboard to dedicate to your guest, and you do not want to suffer from the video overhead of Spice, you can setup evdev to share them between your Linux host and your virtual machine.</p>
|
||
<p><em>Note: By default, press both left and right Ctrl keys at the same time to swap control between the host and the guest.
|
||
You can change this hotkeys. You need to set grabToggle variable to one of available combination Ctrl+Ctrl, Alt+Alt, Shift+Shift, Meta+Meta, ScrollLock or Ctrl+ScrollLock for your keyboard. More information: <a href="https://github.com/libvirt/libvirt/blob/master/docs/formatdomain.rst#input-devices" target="_blank">https://github.com/libvirt/libvirt/blob/master/docs/formatdomain.rst#input-devices</a></em></p>
|
||
<p>First, find your keyboard and mouse devices in /dev/input/by-id/. Only devices with event in their name are valid. You may find multiple devices associated to your mouse or keyboard, so try cat /dev/input/by-id/device_id and either hit some keys on the keyboard or wiggle your mouse to see if input comes through, if so you have got the right device. Now add those devices to your configuration:</p>
|
||
<pre tabindex="0"><code>$ virsh edit vmname
|
||
...
|
||
<devices>
|
||
...
|
||
<input type='evdev'>
|
||
<source dev='/dev/input/by-id/MOUSE_NAME'/>
|
||
</input>
|
||
<input type='evdev'>
|
||
<source dev='/dev/input/by-id/KEYBOARD_NAME' grab='all' repeat='on' grabToggle='ctrl-ctrl'/>
|
||
</input>
|
||
...
|
||
</devices>
|
||
</code></pre><p>Replace MOUSE_NAME and KEYBOARD_NAME with your device path. Now you can startup the guest OS and test swapping control of your mouse and keyboard between the host and guest by pressing both the left and right control keys at the same time.</p>
|
||
<p>You may also consider switching from PS/2 to Virtio inputs in your configurations. Add these two devices:</p>
|
||
<pre tabindex="0"><code>$ virsh edit vmname
|
||
...
|
||
<input type='mouse' bus='virtio'/>
|
||
<input type='keyboard' bus='virtio'/>
|
||
...
|
||
</code></pre><p>The virtio input devices will not actually be used until the guest drivers are installed. QEMU will continue to send key events to the PS2 devices until it detects the virtio input driver initialization. Note that the PS2 devices cannot be removed as they are an internal function of the emulated Q35/440FX chipsets.</p>
|
||
<h2 id="sources">Sources:</h2>
|
||
<ul>
|
||
<li><a href="https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF" target="_blank">https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF</a></li>
|
||
<li><a href="https://clayfreeman.github.io/gpu-passthrough/" target="_blank">https://clayfreeman.github.io/gpu-passthrough/</a></li>
|
||
<li><a href="https://github.com/bryansteiner/gpu-passthrough-tutorial/" target="_blank">https://github.com/bryansteiner/gpu-passthrough-tutorial/</a></li>
|
||
<li><a href="https://github.com/vanities/GPU-Passthrough-Arch-Linux-to-Windows10" target="_blank">https://github.com/vanities/GPU-Passthrough-Arch-Linux-to-Windows10</a></li>
|
||
<li><a href="https://github.com/martinopiaggi/Single-GPU-Passthrough-for-Dummies" target="_blank">https://github.com/martinopiaggi/Single-GPU-Passthrough-for-Dummies</a></li>
|
||
</ul>
|
||
|
||
|
||
<hr>
|
||
<div class="footer">
|
||
|
||
|
||
<a class="previous-post" href="/posts/vbox-autostart/?ref=footer"><span style="font-weight:bold;">« Previous</span><br>Vbox Autostart</a>
|
||
|
||
|
||
<div class="next-post">
|
||
<a href="/posts/bug-out-bag/?ref=footer"><span style="font-weight:bold;">Next »</span><br>Bugout Bag</a>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</div>
|
||
</main>
|
||
|
||
|
||
<div class="article-toc ">
|
||
<div class="toc-wrapper">
|
||
<h4 id="contents"></h4>
|
||
<nav id="TableOfContents">
|
||
<ul>
|
||
<li><a href="#configuring-the-virtual-cpu">Configuring the Virtual CPU</a></li>
|
||
<li><a href="#hiding-the-virtualization-environment">Hiding the Virtualization Environment</a></li>
|
||
<li><a href="#method-a-disabling-the-hypervisor-cpuid-bit">Method A: Disabling the Hypervisor CPUID Bit</a></li>
|
||
<li><a href="#method-b-adjusting-the-hyper-v-enlightenments">Method B: Adjusting the Hyper-V Enlightenments</a></li>
|
||
<li><a href="#tpm">TPM</a></li>
|
||
<li><a href="#passing-keyboardmouse-via-evdev">Passing keyboard/mouse via Evdev</a></li>
|
||
<li><a href="#sources">Sources:</a></li>
|
||
</ul>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
</div>
|
||
</body>
|
||
</html>
|