Nouveau & nvidia-drivers switching

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.)

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(i.e CONFIG_LOCALVERSION=mykernel-nvidia).
 * 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:

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

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.

Set the VIDEO_CARDS variable in /etc/make.conf to "nvidia nouveau" and update your system:

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

And finally use the init script bellow to switch graphics driver depending on what kernel you booted with:

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

Switching using a single kernel and
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.

Just be sure to built kernel modules about everything — at least nouveau, ttm, drm, and optionally(?) ac, button, video, i2c-algo-bit — to avoid useless hassles.

{{GenericCmd| --- /etc/init.d/hprofile	2011-07-26 15:26:56.000000000 +0000 +++ /etc/init.d/hprofile	2012-03-03 17:42:34.686258567 +0000 @@ -7,15 +7,19 @@ } start { +	vgap=$(/usr/sbin/hpdet vga) powerp=$(/usr/sbin/hpdet power) ebegin "Selecting hardware profile vga.$vgap and power.$powerp" +	/usr/sbin/hprofile vga /usr/sbin/hprofile power eend $? } stop { +	vgap=$(/usr/sbin/hprofile -c vga) powerp=$(/usr/sbin/hprofile -c power) ebegin "Stopping hardware profile vga.$vgap and power.$powerp" +	/usr/sbin/hprofile -s vga /usr/sbin/hprofile -s power eend $? } }}

Create the necessaries folder /etc/hprofile/profiles/vga/{scripts,files/etc/X11/xorg.conf.d} and add the following files.

And with that, you should be able to switch vga profile as you like without needing an extra kernel and setup.