Switching from VFIO to NVIDIA

bland_man_studios
3 min readMar 9, 2022

--

I’ve made a lot of videos like this one about how I play video games in a Windows 10 VM running on Linux

My setup is pretty basic, I configure it using the same steps I described in this tutorial series. There you can find out everything about my setup, and all the basics needed for configuring VFIO.

I got a really good question recently. How do I switch the GPU from the guest to the host?

For AMD cards you might be able to do something like this.

For NVIDIA cards, there is no perfect answer, but I wanted to write-up my quick, dirty, and do-able answer.

Add the following two lines to ~/.bashrc (this is a file that lives in your home directory and executes every time you start up a terminal)

alias vfio-reboot='sudo grubby --update-kernel=ALL --args="pci-stub.ids=10de:2182,10de:1aeb,10de:1aec,10de:1aed" && sudo grub2-mkconfig -o /boot/grub2/grub.cfg && reboot'
alias nvidia-reboot='sudo grubby --update-kernel=ALL --remove-args="pci-stub.ids=10de:2182,10de:1aeb,10de:1aec,10de:1aed" && sudo grub2-mkconfig -o /boot/grub2/grub.cfg && reboot'

I told you it is quick and dirty, but here is how it works

Every time I start up a terminal, anything inside ~/.bashrc executes before I’m allowed to run any commands. These two commands add new commands (that are just aliases to combinations of other commands)

The first one vfio-reboot reboots my system and when it turns back on it will be VFIO ready (assuming everything is setup correctly for VFIO like in the tutorial linked above)

The second one nvidia-reboot reboots my system to be ready to use the NVIDIA graphics card on the host OS (assuming the NVIDIA drivers and everything are installed)

If you want to set this up for yourself, you’ll need to change the listed pci-stub.ids 10de:2182,10de:1aeb,10de:1aec,10de:1aed to match your graphics card like I discussed here and here

So while it is a less convenient to reboot every time I you want to switch what I’m doing, I still find this easier than dual booting (because I can just type one command and my computer changes modes, instead of needing to press a button at the right time to select the right OS)

The thing that I really like about this too is that it is idempotent.

This means if my computer is in VFIO mode and I run vfio-reboot it will reboot, but nothing will change. Same thing if I’m in nvidia mode and I run nvidia-reboot. It will reboot into nvidia mode, but the computers config wont accidentally get double-changed

This is a super quick write up so let me know if this was helpful and maybe I’ll do more of these.

Or if you have improvement ideas or thoughts on how this can be more clear, same thing, let me know in the comments.

Thanks and happy VMing!

EDIT: This post has been made into a youtube video here

--

--

bland_man_studios

We make creative stuff and talk about the technology behind it - Check us out on itch.io and YouTube