Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

Nouveau & nvidia-drivers switching

From Gentoo Wiki
(Redirected from Nouveau & Nvidia Switching)
Jump to: navigation, search

Switching between nVidia's binary driver and the open source nouveau driver can be tricky, but definitely doable. This article will detail how to go about switching between them at different stages (i.e. at boot, in a runlevel, etc.)

Switching using two kernels

On Boot

This method assumes the following:

  • Two kernels, one with the nouveau driver enabled and one with the nouveau driver disabled (or built as a module).
  • The nouveau-less kernel needs to have a -nvidia suffix.
  • The GRUB bootloader.

It is assumed you already have a nouveau kernel and want to build the one that will use the nvidia driver. Begin with appending the -nvidia suffix to the kernel name:

Kernel configuration

General setup  --->
    (-mykernel-nvidia) Local version - append to kernel release

Now make sure the nouveau driver is disabled or built as a module:

Kernel configuration

Device Drivers  --->
    Graphics support  --->
        <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
            <M> Nouveau (nVidia) cards

Now recompile and install the kernel. Make sure you update GRUB to take the new kernel into account. Note that kernels with the same version but with different names are considered unique. So if you want to emerge an out-of-tree kernel module to be used with the nouveau kernel you'll first need to copy over the nouveau kernels config file to /usr/src/linux/.config.

Portage uses the variable VIDEO_CARDS for enabling support for various graphics cards in packages. Setting VIDEO_CARDS to nvidia nouveau will pull in the correct driver:

File/etc/portage/make.conf

 VIDEO_CARDS="nvidia nouveau"

After setting this you want to update your system so the changes take effect:

root # emerge --ask --changed-use --deep world

Blacklist the nvidia and nouveau modules as you don't want udev to try and autoload them.

root # echo -e "blacklist nouveau\nblacklist nvidia" >> /etc/modprobe.d/nvidia-n-nouveau.conf

And finally use the local.d script below to switch graphics driver depending on what kernel you booted with:

File/etc/local.d/nvidia.start

#!/bin/bash

depend() {
	need localmount
	before xdm
}

if [[ $(uname -r) == *-nvidia ]] ; then
	modprobe -q nvidia
	if [[ $(eselect opengl show) != nvidia ]] ; then
		eselect opengl set nvidia &>/dev/null
	fi
cat > /etc/X11/xorg.conf.d/01-nvidia.conf << EOF
Section "Device"
  Identifier   "Device0"
  Driver       "nvidia"
  Option       "NoLogo" "True"
EndSection
EOF
else
	modprobe -q nouveau
	if [ -f /etc/X11/xorg.conf.d/01-nvidia.conf ] ; then
		rm /etc/X11/xorg.conf.d/01-nvidia.conf
	fi
	if [[ $(eselect opengl show) != xorg-x11 ]] ; then
		eselect opengl set xorg-x11 &>/dev/null
	fi
fi

Copy it to /etc/local.d/nvidia.start and set the executable bit:

root # chmod +x /etc/local.d/nvidia.start

Switching using a single kernel and hprofile

Another method is switching between two profiles with hprofile, using a single kernel: /etc/init.d/hprofile has to be modified adding a few lines for vga switching. Warning: hprofile shall be added in boot runlevel.