# nvidia optimus problems and uevents problems

## jacobr8893

I have a laptop that has an nvidia optimus system. I can't turn off one of the gpus in my bios, so i wanted to set xorg to render using the nvidia gpu. I followed the arch and gentoo wikis for setting all of this up and found eventually that it will work if i manually modprobe -r nouveau and nvidiafb and then insert nvidia. So my first question is how can i set up my system so that will happen from the start? Otherwise i was thinking of just make a shell script and adding that to boot or default runlevel. 

My second problem is which may be related to the fist, is that when booting my system hangs for about a minute while waiting for uevents to be processed. Are these related? what should i do to fix this? can i send what modules to load or unload as kernel parameters through grub?

----------

## [n00b@localhost]

I am in a similar situation but approaching it from the other end:  I have a working optimus system using the proprietary nvidia-drivers and am working on getting nouveau installed so I can switch between them by stopping xorg, bumblebee and virtualgl, swapping the kernel modules and bumblebee and xorg configs then restarting xorg.  Currently I've got all that implemented but can't get the external output working as both modules are blacklisted (Xorg still starts using the intel card, but to use an external monitor I have to turn the intel card off in the BIOS and use the nvidia card exclusively - which doesn't work automatically as the modules are blacklisted).  Luckily my laptop BIOS allows me to turn off either GPU or leave them both on and this can be controlled in userspace by bumblebee.  The aim is to test out the nouveau driver while sticking to nvidia for day-to-day work (and higher performance in games).

Which page did you follow on the wiki?  This page probably has some pointers to solve your problem, if you have not seen it before.  You will have to either blacklist one or both the modules or delete the nvidia udev rules file to prevent both from getting loaded accidentally.  It would appear that your system is defaulting to using nouveau so I would blacklist the nvidia module and delete the udev file to prevent anything automatically loading them.  Nouveau should then get loaded automatically and be used for Xorg.  If not then a boot script as you suggest (and also in the wiki page above) would do the trick.  This will not prevent you from using the nvidia driver:  you will be able to modprobe -r nouveau && modprobe nvidia after stopping the appropriate services as I am currently doing.

I'm using bumblebee's optimus command with the virtualgl bridge to offload games to the nvidia card.  This might be useful to you even if you are unable to use the bbswitch module to switch the nvidia GPU on and off but I can't find the wiki page (non-gentoo) that I used to set it up (possibly arch). xrandr can also be configured to do this but I'm not familiar with that (and it might be a better option for you if you don't require bbswitch).

I'm not sure about the uevent problem you're experiencing, but if you have both nvidia-drivers and nouveau installed and neither module blacklisted it may be that udev is attempting to load both which could be causing that behaviour.

----------

## Fitzcarraldo

jacobr8893, if you're having to unload the nouveau driver, why don't you uninstall the package x11-drivers/xf86-video-nouveau and build the kernel with CONFIG_DRM_NOUVEAU=n? If it's of any help, my NVIDIA Optimus laptop (using KDE 4) remains using the NVIDIA closed-source driver at every boot with the following configuration (I'm not sure it's a 100% pukka configuration, but the desired result is achieved in my case):

/etc/conf.d/modules:

```
modules="r8169 nvidia agpgart fuse bnep rfcomm hidp uvcvideo cifs mmc_block sdhci-pci rtsx_pci snd-seq-midi vboxdrv vboxnetadp vboxnetflt"
```

/etc/X11/xorg.conf:

```
Section "ServerLayout"

    Identifier     "Layout0"

    Screen      0  "nvidia" 0 0

    Inactive       "intel"

EndSection

 

Section "Monitor"

    Identifier     "Monitor0"

    Option         "DPMS"

EndSection

 

Section "Device"

    Identifier     "nvidia"

    Driver         "nvidia"

    BusID          "PCI:1:0:0"

EndSection

 

Section "Device"

    Identifier     "intel"

    Driver         "modesetting"

    BusID          "PCI:0:2:0"

EndSection

 

Section "Screen"

    Identifier     "nvidia"

    Device         "nvidia"

    Monitor        "Monitor0"

    DefaultDepth    24

    Option         "UseDisplayDevice" "none"

    SubSection     "Display"

        Depth       24

        Virtual     1920 1080

    EndSubSection

EndSection

 

Section "Screen"

    Identifier     "intel"

    Device         "intel"

    Monitor        "Monitor0"

EndSection
```

/usr/share/config/kdm/Xsetup:

```
#! /bin/sh

# Xsetup - run as root before the login dialog appears

#xconsole -geometry 480x130-0-0 -notify -verbose -fn fixed -exitOnFail -file /dev/xconsole &

xrandr --setprovideroutputsource modesetting NVIDIA-0

xrandr --auto
```

OpenGL libraries:

```
$ eselect opengl list

Available OpenGL implementations:

  [1]   nvidia *

  [2]   xorg-x11
```

Below is an excerpt from my kernel configuration, although I have no idea if all of them are relevant or if the list is exhaustive.

```
CONFIG_DRM_KMS_HELPER=y

CONFIG_DRM_KMS_FB_HELPER=y

CONFIG_DRM_I915=y

CONFIG_DRM_I915_FBDEV=y

CONFIG_DRM_I915_KMS=y

CONFIG_SND_HDA_I915=y

CONFIG_AGP=y

CONFIG_AGP_INTEL=y

CONFIG_TREE_RCU=y

CONFIG_RCU_STALL_COMMON=y

CONFIG_RCU_FANOUT=64

CONFIG_RCU_FANOUT_LEAF=16

CONFIG_RCU_FAST_NO_HZ=y

CONFIG_RCU_CPU_STALL_TIMEOUT=21

CONFIG_DRM_NOUVEAU=n
```

I have the following in the file /etc/default/grub which I used to generate the file grub.cfg:

```
GRUB_CMDLINE_LINUX_DEFAULT="drm_kms_helper.edid_firmware=edid/1920x1080_Clevo_W230SS.bin i915.modeset=1 rcutree.rcu_idle_gp_delay=1"
```

I created the EDID firmware file by following the instructions in the Gentoo Wiki article https://wiki.gentoo.org/wiki/NVIDIA_Driver_with_Optimus_Laptops.

```
# emerge x11-misc/read-edid

# mkdir /lib64/firmware/edid

# get-edid > /lib/firmware/edid/1920x1080_Clevo_W230SS.bin
```

Perhaps useful:

[SOLVED] Optimus and Nvidia

NVIDIA Driver with Optimus Laptops 

A new laptop (my blog)

Switching between Intel and NVIDIA graphics processors on a laptop with NVIDIA Optimus hardware running Gentoo Linux (my blog)

----------

## Yamakuzure

Your configuration means, that your nvidia card is always powered on, right?

----------

## Fitzcarraldo

Correct. That's the way I want it to be. I don't want to use Bumblebee. I want to be able to use only the NVIDIA GPU with the NVIDIA closed-source driver all the time, or only the Intel IGP and Intel open-source driver all the time, as I choose.

If I want to switch to the Intel IGP I run a bash script (by clicking on an icon on the desktop), log out of KDE then back in again. If I want to switch to the NVIDIA GPU I run a bash script (by clicking on an icon on the desktop), log out of KDE then back in again. That's the way I want to do it. The two bash scripts, two xorg.conf files, two Xsetup files and two .desktop files I use are all listed on the following Web page:

Switching between Intel and NVIDIA graphics processors on a laptop with NVIDIA Optimus hardware running Gentoo Linux

----------

## jacobr8893

Thanks for the help. I rebuilt my kernel without nouveau, blacklisted nvidiafb, and removed the file in modprobe.d that had been installed with the nvidia driver. https://wiki.gentoo.org/wiki/Nouveau_%26_nvidia-drivers_switching that page helped a lot. Now everything works well and video from mplayer and vlc doesn't have weird artifacts. I'm not sure why using my intel card caused that. 

Also what is nvidiafb? Everytime i tried to either use it or unload it my kernel crashed. Is it just for using in the console with framebuffers?

----------

## [n00b@localhost]

 *jacobr8893 wrote:*   

> Also what is nvidiafb? Everytime i tried to either use it or unload it my kernel crashed. Is it just for using in the console with framebuffers?

 

nvidiafb is the nvidia framebuffer driver.  It is known to conflict with the proprietary drivers from nvidia so that's where the kernel crashes would be coming from.  It is just for using in the console (i.e. the ones you get with CTRL+SHIFT+F1-6 outside of X).  The alternative is to use uvesafb which works extremely well or, on a UEFI system, efifb, which is also known to cause conflicts with the proprietary drivers, but in a vanishingly small number of cases (https://wiki.gentoo.org/wiki/NVidia/nvidia-drivers at the bottom of the "required kernel options" section, just under the box marked "important", which explains what the nvidiafb driver is, and to avoid it with the proprietary drivers).

----------

## Yamakuzure

 *Fitzcarraldo wrote:*   

> Correct. That's the way I want it to be. I don't want to use Bumblebee. I want to be able to use only the NVIDIA GPU with the NVIDIA closed-source driver all the time, or only the Intel IGP and Intel open-source driver all the time, as I choose.
> 
> If I want to switch to the Intel IGP I run a bash script (by clicking on an icon on the desktop), log out of KDE then back in again. If I want to switch to the NVIDIA GPU I run a bash script (by clicking on an icon on the desktop), log out of KDE then back in again.

 That's a pity. I use my laptop on batteries a lot, and was hoping you had a solution to switch without the log out / log in stuff. Because that is what I am not willing to do, close all programs and log out.

So it seems I am stuck with bumblebee... (Not whining, though. Bumblebee works rock solid, reliable and does what the windows driver does.  :Wink: )

----------

