TIP Switching between the nv free driver and the 3D nVidia driver

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

[edit] Introduction

Ever wanted to be able to switch between the free 2D in-kernel nv driver and the 3D nVidia driver?

The only possibility, as those drivers are incompatible, is to do 2 different kernels. We need an init boot script to change Xorg configuration and the opengl configuration.

[edit] The kernels

The kernels can be of the same version or of different versions. We will use here 2 different kernels from the same sources.

[edit] Kernel for the 2D nv driver

Warning: According to the maintainer of the xf86-video-nv driver nVidia Framerbuffer / Riva support has to be disabled. There also shouldn`t be the need for two different kernels. See discussion page!

Follow the Gentoo Linux Kernel Configuration Guide

Linux Kernel Configuration: Graphics configuration
Device Drivers --->
Graphics Support --->
<m>   nVidia Framebuffer Support
    or
<m>   nVidia Riva support

Compile and install your kernel as usual.

The sources of the 2 kernels will be the same, so it will be safer to install all your extra drivers, as those from the alsa-driver package if you don't use the in-kernel alsa driver, before to begin the second kernel configuration. Or use 2 sources trees in /usr/src.

[edit] Kernel for the 3D nVidia driver

mv /usr/src/linux/.config /.config
cd /usr/src/linux
make mrproper
mv /.config /usr/src/linux/.config
make oldconfig

Follow the Gentoo Linux nVidia Guide. But a special step is neccessary:

Linux Kernel Configuration: append string configuration
General setup --->
(-3D) Local version - append to kernel release

With this append string, the modules will not be messed when running make modules_install and we will get a second directory in /lib/modules for this version of the kernel.

Warning: The Gentoo Linux nVidia Guide tell you to add the nvidia driver in /etc/modules.autoload.d/kernel-<ver>. Don't do that because this script will take care of this when needed.

If you already have nvidia in /etc/modules.autoload.d/kernel-<ver>, remove it from the file and run

update-modules

[edit] Grub configuration

Edit /boot/grub/menu.lst and do 2 configurations as usual, one for each of the 2 kernels. Here are the relevant part of my file as example:

File: /boot/grub/menu.lst
 
 title           Gentoo 2.6.16-rt29-3D
 root            (hd0,0)
 kernel          /vmlinuz-2.6.16-rt29-3D root=/dev/hda3 ro acpi=off X_DRIVER=nvidia
 savedefault
 boot

 title           Gentoo 2.6.16-rt29
 root            (hd0,0)
 kernel          /vmlinuz-2.6.16-rt29 root=/dev/hda3 ro acpi=off X_DRIVER=nv
 savedefault
 boot
  

I need the acpi=off for my rt kernel to work well. Your configuration can be different. What is relevant here for you is only the /vmlinuz-* and the X_DRIVER=*.

Tip: Boot environement variable:

X_DRIVER is a boot parameter that grub will pass to the kernel. As the kernel will not understand this boot parameter, it will pass this parameter as environment variable to init.

[edit] Installing Xorg

Follow the X Server Configuration HOWTO and in code listing 2.1 select both the nv and the nvidia driver.

[edit] Xorg configuration

The script removes the xorg.conf file and creates a symlink xorg.conf that points to xorg.${X_DRIVER}.conf. For that to work, we need 2 files: xorg.nv.conf and xorg.nvidia.conf.

First, rename your existing xorg.conf file.

cd /etc/X11

I suppose that your xorg.conf uses the nv driver. Otherwise, just change nv to nvidia and nvidia to nv in the 2 following commands:

mv xorg.conf xorg.nv.conf

Do a copy:

cp xorg.nv.conf xorg.nvidia.conf

xorg.nv.conf must contain:

File: /etc/X11/xorg.nv.conf
 
 Section "Device"
  ...
  Driver       "nv"
  ...
 EndSection 
  

And xorg.nvidia.conf must contain:

File: /etc/X11/xorg.nvidia.conf
 
 Section "Device"
  ...
  Driver       "nvidia"
  ...
 EndSection 
  

For the other options, follow the X Server Configuration HOWTO and the Gentoo Linux nVidia Guide.

[edit] Init switch script

Open an editor and paste the following code:

File: nv-nvidia
#!/sbin/runscript
depend() {
        need bootmisc localmount
        after modules isapnp coldplug hotplug
        before xdm
}

start() {
        ebegin "Loading: ${X_DRIVER} X infrastructure"
        if [[ ${X_DRIVER} != "nv" && ${X_DRIVER} != "nvidia" ]] ; then
            eerror "We failed to switch to ${X_DRIVER}"
            return 1
        else
            if [[ ! -f /etc/X11/xorg.${X_DRIVER}.conf ]] ; then
                eerror "We failed to find /etc/X11/xorg.${X_DRIVER}.conf"
                return 1
            else
                rm /etc/X11/xorg.conf
                ln -s /etc/X11/xorg.${X_DRIVER}.conf /etc/X11/xorg.conf
                    if [[ ${X_DRIVER} == "nv" ]] ; then
                        if [[ $(eselect opengl show) == "nvidia" ]] ; then
                        eselect opengl set xorg-x11
                        fi
                    else
                        modprobe -q ${X_DRIVER} &>/dev/null
                        if [[ $(eselect opengl show) == "xorg-x11" ]] ; then
                            eselect opengl set nvidia
                        fi
                    fi
            fi
        fi
        eend $?
}


Save this file as nv-nvidia. We must change the owner and the permissions. The last command will move the file to /etc/init.d

chown root:root nv-nvidia
chmod +x nv-nvidia
mv nv-nvidia /etc/init.d

This script uses the X_DRIVER parameter to symlink the corresponding xorg.${X_DRIVER}.conf and run eselect accordingly to set the opengl interface. As it take time to change the opengl infrastructure, I added a test that check which version of the opengl is in use and skip the change if it is not needed.

Added a X_DRIVER test, just to be sure at a non valid symlink will not be created. If X_DRIVER is non valid, the script do nothing but issue an error message.

Added a /etc/X11/xorg.${X_DRIVER}.conf test to be sure at xorg.conf will not be erased by mistake. So now, this script will be safe to use.

[edit] Init configuration

We need to add the X_DRIVER variable in /etc/conf.d/env_whitelist, because this variable must be allowed to be passed from the environment to the rc-system.

echo X_DRIVER >> /etc/conf.d/env_whitelist

The last thing to do is to add our new init script in the default runlevel:

rc-update add nv-nvidia default

[edit] To Do

  • Check my bad English.
  • Who knows?

[edit] See also

[edit] Feedback

Concerns or Compliments? Please use the Discussion section.

Personal tools