 Hi, I'm Denshi, and in today's video we're doing a comfy guide on Nvidia Optimus. More specifically, we're going to be taking a look at how to configure Nvidia Optimus manually on your gaming laptop. For all of you uninitiated folk, Optimus is the name we use for the technology that basically makes the system work when it has both an integrated and a dedicated GPU. So in your gaming laptop case, you probably have an Nvidia GPU, like a GTX something or whatever, and an integrated GPU, an Intel or AMD, whatever. And that integrated GPU is what's actually plugged in in powering your display on your laptop. And through some clever trickery and all that, we're able to get the Nvidia GPU rendering through the integrated GPU. This works by default and perfectly fine on Windows, and it's pretty easy to configure. But on Linux, this can be a little bit more complicated, you could end up having some problems, you could end up with a black screen when you try to open programs and stuff like that. And today's video is hopefully going to help you clear all of that knowledge to try to understand what's actually going on and how to set all of this up manually. Now I'm going to say that before we begin with any setup at all, you want to install the following things to your system. You want the Nvidia driver and Xorg X Render, which is a basic little tool you can use to change resolution and DPI on your system. Now for most distributions, you can probably just use the latest Nvidia driver and that will work with your card. You'd have to look specifically if you're having trouble, but in my case, I'm using Arch Linux so I can just run sudo pacman dash s Nvidia to install the Nvidia package, which is the latest Nvidia driver, and Xorg X Render, which is the latest version of the X Render tool. I'm not going to run that because I already run it before and I have the Nvidia driver installed. But basically, once you've installed that, you now have the driver and you can now proceed to the next step, which is actually configuring your programs and all that to work properly with your Nvidia GPU. Now before we begin with the manual configuration, I want to tell you that those are very useful script you can do that does most of this for you. So if you scroll down all the way down here, there's this script over here called NV Control. Now NV Control is a Python script and I'll have this linked in the description so you can go check it out. You can install this in the AUR as well. It's this little Python script that will automatically go through and check your system and figure out how to set up everything for Nvidia Optimus, depending on what options you give it. So for example, you can say sudo NV Control. If I can spell right NV Control dash dash switch and then Nvidia or dash dash switch integrated or dash dash switch hybrid to get the three different modes for Nvidia Optimus. Now this will only apply after a reboot because you know, you gotta reload everything. However, this script basically does everything we're about to do automatically. The only difference is that sadly, no computer script on the internet can give you knowledge. You cannot learn anything from running a Python program. However, you can learn something by watching this video and running through the steps manually, especially if you want to configure something in a custom way. So we're going to run through all the steps manually and all this is is really what that script is doing, but we're going to be doing it step by step configuration file by configuration file. We're going to take a look at all the various ways you can get around this and set this up and hopefully by the end of the day, we'll have something proper set up. But anyways, let's begin with the first most important step, which is setting your PCI bus. So if you run the following command, LSPCI, you will get a list of all the PCI devices on your computer. So things like, you know, your processor, your audio cards, your network cards, all that stuff that's plugged into your motherboard. Now one of those things, if you've got quite a keen eye, as you can see over here, is your Nvidia GPU. So the first thing we're going to do is we're going to run this command over here, which is a one line command that just searches the LSPCI output for any Nvidia cards. In this case, we got 0100.0 and if we run LSPCI again, you'll see that yeah, that's accurate over here, the VGA compatible controller for the Nvidia is 0100.0. In this guide, we're going to be using the PCI address 100, which is what we got over here. If you have two or three or something else, then replace all of the occurrences of PCI with whatever you got when running this command. Now that we know the PCI bus, we can move on to the next step, which is configuring XORC. So in our case, the first thing we're going to do is we're going to edit this file at CX11XORC.D and 90-invidia.com. So sudo vim at CX11XORC.D, which is the extra configuration directory, 90-invidia.com. Then we're going to copy paste all of this content over here. And as you can see, the PCI bus over here once again is set to the one that I have on my system and you want to change this according to yours. Now, all this is doing is telling XORC to render everything using the Nvidia GPU by specifying its PCI address. So now that we've set that up, we can call on WQ or whatever text editor you have, and then we can move on to the next configuration file, which is this one over here. So sudo vim at CmodPro.D and then invidia.conf. And in here, we can copy paste this over here. Options, invidia, DRM, mode set equals one. And then write and quit. All right, now there's one more thing we want to do. We need to tell our display manager or Exinit to set the correct DPI and also set the correct provider output source. So in my case, you can add the following lines to my Exinit RC file. So in my home directory, I have this file, which is what I run when I run XORC. And what I can do is I can add the following lines. I can go through and copy paste these from the wiki and add them here. However, you're probably not using Exinit. You're probably using KDE Plasma or something like that. And in that case, what you want to do is you want to modify any of the following files. So I'll have this linked in description. All these are the different configuration files that you have to edit, depending on your display manager or your login manager or whatever you call it. So if you're using LightDM, which is what you're probably using for XFC or something. If you're using SDDM, which is probably what you're using for KDE. And if you're using GDM, then you want to go through and make all of the configuration changes stated in here, and then your invidia card should work. Anyways, now that we've done that, I'm going to go and test it. Because all of this configuration only starts applying after I've rebooted, because the proprietary driver only starts applying once I've rebooted. I'm going to go reboot my computer and log back into X. And then we're going to run the following command. GLX Info, then pipe, grep, render. So if I run that command in my terminal, you'll see that I get Mesa Intel Ultra HD Graphics, which is the graphics card in my CPU, the integrated one. When I come back after rebooting my computer, I should get an invidia output instead. So I'm just going to come back in a second. All right, I'm back after rebooting my computer. And now if I run GLX Info, grep, render. As you can see, it tells me that I'm rendering on the invidia card. So that configuration we did for Xorg and all that, that worked. And we're now rendering on video. But let's say I got to go to school tomorrow or something like that happens. And I want to use my Intel card. I want to completely disconnect my invidia card from my system. So it's not even powered on when I turn on my computer to save as much battery as possible. For this, we're going to scroll down all the way down to the section that says, only use the IGPU. And we're going to just follow the commands and the configuration files here. So first of all, you want to make sure that any display manager or Exynit configuration for invidia is removed. So in my case, remember when I changed the Exynit RC file, I'm going to go in there and delete the lines pertaining to invidia. And then write and quit. And in your case, you might want to go through and get rid of your GDM configuration or your SDDM configuration or whatever you've done for LightDM just to make sure you're not enabling invidia when you turn it on. Next up, we're going to get rid of the other configuration files that we made for invidia. So the exorg one and the modprobe one. So I'm just going to copy paste this command and run it over here to get rid of those files. Now that I've done that, I'm going to go and add this file over here, blacklist-invidia.conf. This file is going to let us completely remove the invidia card by disabling all drivers for it. So we're going to run sudo vim at cmodprobe.d blacklist-invidia.conf. We're going to go in here and we're going to copy paste the following content. All this is going to do is it's going to blacklist all these drivers, which the kernel normally does load when we turn on our computer. So they don't load. Next, we're going to go down here and we're going to create this new file, which is called 50-remove-invidia.rules. What this does is it modifies udev. Now, if you don't know what udev is, that's the program that runs that boot that loads or unloads different drivers in different parts of your system. It's very kernel level. It's very hardware level stuff. And in our case, we can run this entire command and copy paste it. And what this will do is it will essentially borderline unplug our card, so it's not even loaded. It won't even show up when we run lspci, as if it didn't even exist. So we don't even power it on when we turn on the computer to save as much battery as possible. But anyways, now that we've done that, we can reboot. And if I run glxinfo again, when I'm back, this should show mesa and not invidia. So see you then. All right, I'm back after rebooting one more time and running glxinfo-grep render. As you can see, we're back on mesa. And more importantly, if we run lspci and grep4invidia, we get nothing. In fact, what we just put in the configuration files before, all of this blacklisting and all of these udev rules completely removed any traces of invidia from our system to save as much power as possible. So this is essentially the polar opposite of running everything on invidia. We're running nothing on invidia. But anyways, most people tend to want some kind of hybrid solution where they're able to run some things with Intel and some things with invidia, which offers a compromise between battery life and performance. And in this case, we want something called a hybrid system. Now, in the case of Arch Linux, there's a package that does pretty much all of this for you. It's called invidia-prime. So if you run sudo pacman-s invidia-prime, this will automatically install a tool that essentially lets you manage this automatically. So you can run prime-run and then any program after it, like let's say st, which is my terminal, and then it will run on the invidia card. The only problem here is that prime-run isn't actually doing anything. If we run GLX info, as you can see, it won't give us any proper meaningful output because, yeah, it fails to request it because the invidia card has been blacklisted. We blacklisted it before. So what we want to do is we want to get rid of all these config files and then reboot and then we'll be in hybrid mode. So if we want to get a hybrid mode going on, where we're rendering everything on the Intel GPU, but then we can run prime run before programs to render them on the invidia GPUs or like selectively rendering them, we want to go through and basically get rid of all the configuration files. So get rid of all the invidia configuration files, first of all, and then get rid of all the Intel configuration files, which are these ones over here. So just get rid of all of those and then we'll reboot and then we'll be able to run under a hybrid system. All right, I've rebooted and now I'm in my hybrid system. So all the configuration files are gone and we can run stuff with prime run. So if we run GLX info by default, as you can see, we'll get Mesa. But if we run prime dash run and then GLX info, we'll get invidia and the same thing goes if we render a separate window like this. So if we do prime run SD, for example, so opening the terminal in prime run. So this is now an invidia terminal. I can run GLX info, grep render, and I'll still get invidia and the same goes for any games or whatever, any kind of software that you can start with prime dash run. And you can add this as a prefix in steam or whatever gaming software. You can set this as an option in Lutris. So it automatically runs prime run to get all your games running on invidia. So while most things are rendered by Intel on your system, you have the option to render them with the invidia card if you so wish. But anyways, that's pretty much it when it comes to invidia optimus. That's I'm assuming most people's requirements to this. Some people want to go more complex and start setting up systems where depending on battery levels or things like that, their system renders on invidia or not. But the truth is is that honestly, invidia optimus is not that flexible on Linux. It's quite hard to get a very interactive and automatic system with this. Even the script that I showed you, NV control has problems when you try to run it on Intel mode because like I said, remember when we tried to run LSPCI and we didn't get any address? Well, this entire script relies on that command to find the PCI address of your invidia card. So stuff like that happens. So scripts for this are quite hard to make, which is why it's important that you learn step by step what configuration files to edit and all that. But anyways, with all of that out of the way, I hope you enjoyed this video. I hope you find it useful. If you have any problems, you can email me or join our matrix or XMPP or our discord chats, which are all bridged by the way. So you can chat one of them and talk to people on the other side. Besides that, I've been Denshi. This has been a comfy invidia optimus guide. Goodbye.