Sunshine: Self Hosted Cloud Gaming Part 2

Profile picture of Christopher Bell

Draft

Apr 7, 2024

·

9 min read

·

477 Views

This will be part 2 of my guide to a cloud gaming rig, with remote access available from any device that supports Moonlight game streaming client. You can find the Sunshine installation article written by Ben Herbst here and you can find the Part 1 of my self hosted series here. If you are just starting out on this article I would encourage you to read these 2 articles first. This article will include fewer pictures and be more technical.

This article will focus on virtualizing your machine and using a display driver software to emulate a monitor. Virtualizing your gaming machine has several benefits. Reduced power usage if you already run a 24/7 server/lab, or the ability to add new services or self host services using the overhead your PC doesn't. Most gaming PCs have more RAM and CPU power than they need, and sharing this with other services allows your equipment to pull double duty. It also provides the ability to easily access and maintain your PC from any computer with an internet connection.

I will be using ProxMox VE (PVE) as a hypervisor, and will explain creating the VM, setting up GPU passthrough for an Nvidia GPU, and installing the display driver with proper configuration. To install PVE download the ISO image here and install it through USB using Rufus, Ventoy or your preferred installation media.

Creating the Windows 11 VM

Creating the Windows VM is pretty straightforward. Open a browser and navigate to your PVE GUI and login. Navigate to your "local" drive, or any storage that allows ISO Images to be stored and downloaded. Choose the option for "ISO Images" and click the "Download from URL" button. Open a new browser tab and navigate to here. Follow the instructions in the section for download the disk image. When you get to the end right click the download link, copy the link URL and past it in PVE.

Once the ISO has finished downloading click the "Create VM" button in the top right of your PVE UI. Name your VM and check the "Advanced" option at the bottom of the window, you should also check the box "Start at boot". Click "Next" and for OS mount the ISO image we downloaded earlier, click "Next". The system settings should be as follows:

  • Graphic Card: Default

  • Machine: q35

  • BIOS: OVMF (UEFI)

  • Add EFI Disk: Enabled

  • EFI Storage: Choose a disk

  • Pre-Enroll keys: Enabled

  • SCSI Controller: VirtIO SCSI single

  • QEMU Agent: Disabled

  • Add TPM: Enabled

  • TPM Storage: Choose a disk

Click "Next", choose an installation disk in the drop down next to "Storage", then choose the amount of space you'd like to allocate the VM OS drive. If it's an SSD check the box for "SSD Emulation", if you use ProxMox Backup Server check tha "Backup" box then hit "Next". In CPU assign as many cores as you'd like, for "Type" choose host, then hit "Next". Under "Memory" assign at least 9GB of memory, leave the. Leave "Network" default, hit "Next", review the settings, then click "Finish". Your VM will be created but we aren't quite done.

Before we start the VM we need to add some CPU configurations, type the following command:

sudo nano /etc/pve/qemu-server/<you_vmid>.conf

Edit the following lines to look like this:

cpu: host,hidden=1,flags=+pcid
args: -cpu 'host,+kvm_pv_unhalt,+kvm_pv_eoi,hv_vendor_id=NV43FIX,kvm=off'

CTL+X and save. Now you can boot the VM and go through the Windows 11 installation steps. When you have finished this shutdown the VM. Navigate to the VM's "Hardware" tab in PVE and add any storage media you would like. We will also add the GPU here but we need to complete a couple steps first.

Passthrough a GPU to the VM

There are several things we will need to do from the PVE CLI to enable GPU passthrough. If you're using Intel or AMD configure the Grub:

sudo nano /etc/default/grub

Look for the line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet"

Then change it to look like this:

Intel: GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

AMD: GRUB_CMDLINE_LINUX_DEFAULT="quiet amd"

It is also recommended to add extra commands to this line like so:

GRUB_CMDLINE_LINUX_DEFAULT="quiet iommu=pt pcie_acs_override=downstream,multifunction nofb nomodeset video=vesafb:off,efifb:off"

Here is some information on what these commands do:

When you have finished editing Grub run CTL+X and save then run this command:

update-grub

Next you need to add some VFIO modules to PVE:

sudo nano /etc/modules

Add the following to the file:

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

CTL+X, and save the file. You will then run 2 commands:

echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" > /etc/modprobe.d/iommu_unsafe_interrupts.conf
echo "options kvm ignore_msrs=1" > /etc/modprobe.d/kvm.conf

Next you will blacklist the host from using the drivers. WARNING: This will make it so that you can't manage the host from the GPU hardware

echo "blacklist radeon" >> /etc/modprobe.d/blacklist.conf
echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf

Last command will be

lspci -v

This will display a lot of information about attached devices you are looking for something like:

01:00.0 VGA compatible controller: NVIDIA Corporation GA104 [GeForce RTX 3070 Ti] (rev a1) (prog-if 00 [VGA controller])

Then run the command, replace the number with your GPU:

lspci -n -s 01:00

This should output your GPU Vendor IDs, one for the GPU and the other for Audio. It will look something like this:

01:00.0 0000: 10de:1b81 (rev a1)
01:00.1 0000: 10de:10f0 (rev a1)

You will need these vendor ids in our next command:

echo "options vfio-pci ids=10de:1b81,10de:10f0 disable_vga=1"> /etc/modprobe.d/vfio.conf

Then you will run this command:

update-initramfs -u

And restart:

reboot

Now you should be ready to passthrough a GPU. Go back to the VM "Hardware" section and add a PCI device. Find your GPU from the dropdown and select it. On the options screen you should configure it like this:

  • All Functions: Enabled

  • Rom-Bar: Enabled

  • Primary GPU: Disabled

  • PCI-Express: Enabled

Now start the Windows VM up and install Nvidia Geforce Experience or the appropriate Nvidia driver, or your appropriate GPU driver(s). Refer to the first guide written by Ben Herbst to setup Sunshine and Moonlight. Next we will setup a display driver that will allow us to create a dummy monitor and access the machine headless.

IDDSampleDriver and Headless

To go headless we first need to create a dummy monitor. This will also allow us to specify a range of common resolutions for the dummy monitor. Some resolutions, like mobile devices, will still need to be added using CRU, you can find the download link in part one of this guide. To setup the dummy display we need to download a display driver called IDDSampleDriver, download it here. There are links to download an HDR version as well as a non-HDR version. If you have any HDR screens you will stream to download the HDR version. Take these, note that you can edit the options.txt before installing the driver to add resolutions:

  • Download the latest version, and extract the contents to a folder.

  • Copy option.txt to C:\IddSampleDriver\option.txt before installing the driver (important!).

  • Right click and run the *.bat file as an Administrator to add the driver certificate as a trusted root certificate.

  • Don't install the inf. Open device manager, click on any device, then click on the "Action" menu and click "Add Legacy Hardware".

  • Select "Add hardware from a list (Advanced)" and then select Display adapters

  • Click "Have Disk..." and click the "Browse..." button. Navigate to the extracted files and select the inf file.

  • You are done! Go to display settings to customize the resolution.

Once you have installed the driver Windows will show 2 monitors, one from PVE and one from the display driver. Now that we have Sunshine setup, a Moonlight client connected and the dummy display driver attached we can disable the standard display driver.

NOTE: Disabling this will remove the ability to access the VM from console, or PVE. You will have to connect a monitor directly to the GPU and passthrough USB for access to the VM, or use the Moonlight client.

We now have a virtualized Windows PC, with GPU passthrough enabled, drivers installed and remote capability ready. If you encounter any errors leave a comment below and I can update this guide or write another article with troubleshooting, and resolutions for common issues. My next article will focus on setting up Playnite, creating save game backups, and using it as your console style launcher. Once you have read these articles you will have a polished, professional remote capable gaming setup with all the features and benefits you would expect from a high end gaming system.

A Word on Security

It is possible to have Moonlight accessible from the internet using the Moonlight Internet Hosting tool. I will not cover that here, it requires exposing ports and in my opinion that is very dangerous,. If you want to be able to access it outside your home network with that security risk, the guide is available here.

I would instead encourage you to use a VPN tunnel such as Wireguard, Netmaker, Tailscale or something similar. This will provide more security, and some routers may support Wireguard directly. This eliminates the need for open ports except the single port for the VPN tunnel. There are many articles on setting up VPN tunnels, a quick simple solution would be wg-easy found here.

**I plan to update this article to include MonitorSwapAutomation and ResolutionAutomation for better monitor management.


Profile picture of Christopher Bell

Written By

@Christopher Bell

No bio found