Skip to content

Latest commit

 

History

History
442 lines (262 loc) · 16.5 KB

diy-vm.md

File metadata and controls

442 lines (262 loc) · 16.5 KB

🛸 DIY From Scratch

UPDATE: Windows 11 has been tested and works just as well, and the support will be added soon!

If you want to go adjust every little aspect of the VM to suit your needs, this section is for you. This guide works regardless of your Linux distribution.

NOTE: Using a recent version of Windows is recommended (anything after 20H1 or May 2020) as older revisions are known to have some issues, and hence are not mentioned in this guide.

Enabling Virtualization in your UEFI/Coreboot

You may need to enable AMD-V or Intel VT-x/VT-d depending on your CPU brand in your UEFI before going further.

THIS VARIES BETWEEN VARIOUS MOTHERBOARDS

Take a look at how to do it below:

How to enable Virtualization on your Motherboard

STEPS WILL VARY BETWEEN DIFFERENT MOTHERBOARD MANUFACTURERS

Please follow the steps to enable virtualization (SVM) in the BIOS for AMD motherboards:

1. Press Del or F2 in the keyboard after power on, then go to the appropriate menu for AMD SVM/ Intel Virtualization (VT-x).

Screenshot

2. Click F7 if you are not in advanced mode already

Screenshot

3. Click [Advanced] - [CPU Configuration]

Screenshot

4. Enable Virtualization

  • Enable SVM (AMD)

Screenshot

  • Enable VT-x and Intel Virtualization (Intel)

Screenshot

  • OLD BIOS (Intel and AMD)

Screenshot

5. Finally, Save and Reboot.

Instructions and media taken from Asus Forums.


Verify on System76 Computers

Screenshot

Screenshot


If you have a laptop with UEFI, you can also check this video.

For Coreboot devices, refer to your manufacturer's instructions or check the official documentation here.

Installing Dependencies

Boot into your preferred Linux OS and install the packages. You may search the packages in your package manager or compile them yourself.

Installing Dependencies

Install Qemu-KVM, Virt-Manager, Libvirt and other dependencies on your distro.

Note: Any Linux distribution will work just fine. You do need to install libvirt, virt-manager, qemu, and other required dependencies.

# Debian & Ubuntu (Linux Mint, PopOS, ElementaryOS)
sudo apt install -y qemu qemu-kvm libvirt-bin libvirt-daemon libvirt-clients bridge-utils virt-manager
# Fedora based ditros  
sudo dnf -y install qemu-kvm libvirt bridge-utils virt-install virt-manager
# Arch (Manjaro, Arco Linux, EndeavourOS) 
sudo pacman -S --noconfirm qemu libvirt bridge-utils edk2-ovmf vde2 ebtables dnsmasq openbsd-netcat virt-manager

After installing the dependencies, make sure you enable the following services.

Instead of Systemd, you can use OpenRC, Runit, SysVinit as well.

 # Enable Libvirt Service
 sudo systemctl enable --now libvirtd

 # Enable VM Console logging 
 sudo systemctl enable --now virtlogd 

 # Enable Virtual Network Bridge 
 sudo virsh net-autostart default
 sudo virsh net-start default

Linux Kernel 5.4 LTS or newer is recommended

Downloading ISOs

If you want to run Anti-Cheat games and use Winapps, you will need Windows 10 Pro/Pro N/Pro Workstation/Enterprise, as they have Hyper-V Support which is required.

You may even supply your own custom Windows Image (like Windows Ameliorated Edition)

Note: Place ISOs in /var/lib/libvirt/images/ to avoid permission issues.

Creating a VM

Step by Step Guide - Click Me!
  • Open Virt Manager from your applications menu or type virt-manager in terminal.

  • Click on the ➕ icon or the first icon in Virt Manager to create a VM.

Screenshot

Screenshot

  • Select the Windows 10 ISO that you downloaded earlier, and choose the OS from the list if it isn't detected automatically.

Screenshot

  • Allocate Memory and CPUs as per requirement.

Screenshot

  • Either create a new disk or create one as big as you want, and later select the disk here. You can enter any directory you wish, as well as how big you want it to be.

  • Enter this command to create a disk. qemu-img create -f qcow2 /var/lib/libvirt/images/Windows10Vanilla.qcow2 1024G

Screenshot

  • Check Customize configuration before install and click Finish.

Screenshot

  • In the Overview section, Select OVMF_CODE.fd in Firmware.

Screenshot

  • In the CPU section, check Copy host CPU configuration if you aren't planning to make a Stealth VM, and host-passthrough otherwise.

  • You may manually set CPU Topology if you know the exact layout of your CPU.

for example: Ryzen 5 3600 has 6 Cores, 12 Threads and is only available in 1 Socket motherboards.

Screenshot

  • In the Memory section, enter Current allocation = 1024 to make initial RAM usage less.

Screenshot

  • In SATA Disk section, Change the Disk Bus to VirtIO to make operations faster by reducing overhead.

Screenshot

  • In NIC section, Change the Device model to VirtIO to enable Virtual Network Bridge for interfacing between VM and Host.

Screenshot

  • Click Add Hardware and select the Storage section to add VirtIO Drivers ISO and change the Device type to CDROM device and click Finish.

Screenshot

Screenshot

  • In the Boot Options section, select Windows ISO CDROM and VirtIO Disk that we created earlier, and check 'Enable boot menu'.

  • Finally, Click Begin Installation to save and start the VM.

Screenshot

If you encounter an OVMF/edk2 problem, check out OVMF Fix

Or you can enter the following command in terminal (only applicable this VM)

Ubuntu/Debian ➜ sudo cp /usr/share/OVMF/OVMF_CODE.fd /var/lib/libvirt/qemu/nvram/Windows10-default_VARS.fd

Fedora ➜ sudo cp /usr/share/edk2/ovmf/OVMF_CODE.fd /var/lib/libvirt/qemu/nvram/Windows10-default_VARS.fd

Arch ➜ sudo cp /usr/share/ovmf/x64/OVMF_VARS.fd /var/lib/libvirt/qemu/nvram/Windows10-default_VARS.fd

  • Click inside the VM Window and press any key when asked.

Screenshot

Screenshot

  • Select your language and keyboard input and click Next.

Screenshot

Screenshot

  • Enter your product key now, or you can skip and enter your product key after installation.

Screenshot

  • Selecting Windows 10 Pro N will install Windows 10 Pro without extra bloat.

Note: Choose Windows 10 Pro XXX or Enterprise if you need Hyper-V for Stealth VM.

Screenshot

Screenshot

  • Select Custom Install (because the other one is useless)

Screenshot

  • Click on Load Driver to install disk drivers.

Screenshot

Screenshot

  • Double-Click on CD Drive virtio-winamd64w10 and click OK.

Screenshot

  • Just click Next to select the default one.

Screenshot

  • Select Unallocated Space and click Next to begin the installation.

Screenshot

Screenshot

  • After installation, Windows will boot normally and you will need to set up your user account and password.

  • Avoid Microsoft Sign in if you can at all 😉


Optimization

There usually isn't much that needs to be done for optimizing Performance in VM, but there are a couple of things that need to be taken into consideration for more than just a basic VM.

Check out this video by SomeOrdinaryGamers for an easy tutorial on the same.

GPU Passthrough

TLDR;

Writen Guides:

Video Guides:

For laptops, see Laptop Compatibility


Ideally you need to have 2 GPUs (one dedicated and one integrated) in order to access Windows as well as Linux desktop simultaneously, by using 2 monitors or switching the display output on one monitor.

However, if you are living in the world after 2020, I know your pain and why you have only one (or possibly none) GPU.

You might be in one of the following situations:

  1. You have ONLY one GPU, either discrete (NVIDIA/AMD RX) or iGPU (Intel/AMD Radeon)
  2. You have a discrete GPU (NVIDIA/AMD) + iGPU (Intel UHD/AMD Radeon)
  3. You have two discrete GPUs (then integrated graphics don't matter)

Refer the following sections according to your current system specifications. If your system has,

Only one discrete GPU (no iGPU):

  1. SomeOrdinaryGamers' Single GPU Passhrough Video (NVIDIA)
  2. Fedora 34 Single GPU Passthrough on Level1Forums
  3. joeknock90 central repository

NOTE: Before you passthrough your GPU, make sure you enable your integrated graphics and set it to default in UEFI/Coreboot first, or else you won't be able to view your Linux Host.

One discrete GPU to dedicate completely to the VM:

  1. Level1Tech's GPU Passthrough Guide
  2. SomeOrdinaryGamers' KVM Guide

In the past, it was required that you have two different GPUs (typically AMD + NVIDIA), but that's not the case anymore!

NOTE: The GPU used by the VM will be unavailable for the Linux System for use. Using the iGPU/low-cost GPU for the Linux system is recommended.

Only integrated graphics:


If you want to be able to use GPU Accelerated Applications (like Video Games, Adobe CC, etc) on a Windows VM without dedicating an entire monitor to Windows VM, check out the Looking Glass Project:

  • Looking Glass - An extremely low latency Memory-to-Memory frame copy from the Guest to Host.
  • Level1Techs Video - It has gotten better than what this video demonstrates!

Code 43/Black Screen fix

NVIDIA's driver 465 and newer support GPU Passthrough to a Windows Guest on a Linux Host.

Check out LinusTechTips' Video, Wendell's Video and SomeOrdarinaryGamers' Video to get an idea about what could be possible down the line.

NOTE: NVIDIA still doesn't support SR-IOV so you will need an iGPU or a separate GPU if you want to be able to access the Linux Host.

If you don't want to use a second GPU, check out Single GPU Passthrough

Check Out NVIDIA GRID on GeForce and Quadro GPUs, NVIDIA's Proprietary alternative to SR-IOV.

You can read the Community made Wiki.

So if you need to passthrough an NVIDIA or AMD GPU without making it obvious that you are using a VM, add the following lines to your XML.

1. List all VMs

sudo virsh list --all

Screenshot

2. Edit the VM config

  • Replace Windows10 with the name shown in the previous step.
sudo virsh edit Windows10

3. Enter the following text between the already existing sections

You can replace randomid with AuthenticAMD to fix a few issues on RX 5000 and older AMD GPUs.

...
<features>
...
  <hyperv>
  ...
    <vendor_id state="on" value="randomid"> 

  </hyperv>
  
  <kvm>
      <hidden state="on"/>
  </kvm>
...
</features>

Gotchas

For any issues not just limited to the following, check the following sections on the Arch Wiki.

Section 1:

  • Unisolated IOMMU Groupings
  • Problems with vfio-pci loading correctly

Section 2:

  • Using a non-EFI image on EFI based VM

Section 3:

  • Passing through a device that does not support resetting via kernel

💻 Laptop Compatibility

Screenshot

According to the image above, if you have a MUXless laptop, it is a little tricky to dedicate your GPU to a VM and have its own separate display, because the GPU doesn't connect to the HDMI/DisplayPort Port directly, and instead uses the iGPU as a bridge to the laptop screen. Read more about it on this post in Level1Forums

You might be able to get around this by passing the iGPU to the VM, as shown here

You can still get past through this sometimes like this reddit post mentions, using an ROG Zephyrus G14 w/ RTX 2060.

NVIDIA Issues on Laptops

Sometimes on Optimus/Max-Q laptops, NVIDIA wants to check for the battery info in Windows or else it returns Code 43.

If you experience that issue, check out the SSDT Workaround on ArchWiki.

If you still get a Code 43, perhaps batmanfeynman's post or alterNERDtive's post could help.

AMD Reset Bug Fixes

Making your VM Stealth

If you need to mask your VM from checks that a few programs do to restrict users from using certain programs inside a VM for various reasons (like Video Games), then this section is for you.

It goes over running DRM/Anti-Cheat games under VMs that have built in VM detection techniques.