Talk:Nouveau & nvidia-drivers switching

Rondo (talk) 12:11, 13 December 2013 (UTC) The article suggests 2 kernels, why not just blacklist the nvidia/nouveau module on boot and change xorg.conf?

Switching using a single kernel and systemd (but also openrc and maybe others or maybe this is independant from the init system?)
i did successfully blacklist the nvidia-driver via the grub2 modprobe.blacklist=nvidia option and it did work with openrc. this paragraph should not mention systemd as a prerequisite to do this.

Reuben (talk)

Loading modules for the kernel command line is not the issue. You need a mechanism to control switching the opengl/opencl x11 drivers in xorg.conf. The current documentation uses a systemd environment variable. Not sure if openrc supports setting any environment variables from kernel command line. You might be able to change it according to results from querying the kernel command line via /proc/cmdline

e3k (talk)

@Reuben. Thank you for the explanation. I did not go further than changing the grub to mask the driver i do not need. All the other steps like xorg.conf and opengl settings are done manually. It is sufficient for me as the biggest (timeconsuming) problem for me would be the kernel recompilation.

FireFish5000 (talk) 00:08, 31 July 2015 (UTC) I would like to first confirm that blacklisting modules works with both or is independent of init system, second we can access boot parameter with 'get_bootparam' in init scripts. This is exemplified by which searches for the nox (No X) parameter.

I am adding an OpenRC single kernel version to the page. I would like to quickly explain the reasoning behind any/all changes made.

First, I moved OpenRC and Systemd versions to the top, as I imagine the majority of the users are not going to want to compile 2 kernels, and thus believe that this puts them in order from most likely to use to least likely.

I opted to keep modules blacklisted in, as this removes worry of both modules being loaded if bootloader doesn't get updated or gets replaced(eg. a careless user with dispatch-config, editing grub.cfg directly and then calling update-grub). The modules can then be loaded by the script, and a default can be provided in case of the exemplified error above.

I am moving the init script to for two reasons.
 * 1) nvidia.start seems to imply nvidia driver. I am hoping nv makes nvidia and nouveau equally likely, and selector shows we are selecting the driver. nvidia-nouveau or another name may be better.
 * 2) It was the only script in my local.d directory. Unless there is an explicit reason for separating it into local.d (some standard for loading drivers? Can't load faster since it depends on a boot-service.), I would prefer to have it grouped with all the other init scripts.

I am setting two NON-dot-conf files in /etc/X11/xorg.conf.d/ for the init script to link to. The reason being that with multihead setups, the work needed to be done may be more complex than just sed 's/nvidia/nouveau/'. We may want to change options like referesh rate, vsync, twinview, dpi, etc depending on driver for a better experience. I use it for naming the monitors which I configure in other files, because for some reason nvidia indexes the ports on 0 while nouveau starts at 1...

The two kernel method is being modified to explicitly recommend builtin nouveau support on one of them, since it makes no sense to have two kernels otherwise. (though it did make sense when written, we now know of a better way)

NOTE: The changes to the wiki proposed below are posted here partially for testing (moving to laptop to reproduce), but mostly to save the changes externaly in case something goes wrong with my computer. Still revising

Module Based Switching
With module based switching, a single kernel is setup to be used with both nvidia and nouveau modules, the bootloader is configured to specify which module to load, and an init script does everything necessary to get the driver and system to work together.

Configure the System
Before switching is possible, the system must be properly configured to support it.

To do this, first make sure the nouveau driver is built as a module:

Then recompile and install the kernel and kernel modules.

Next set the VIDEO_CARDS variable to support both nvidia and nouveau drivers.

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

If X11 is used on the system, then two config files need to be setup in. These files, and  (name does not matter), will specify settings necessary for nvidia and nouveau drivers respectively. Note they mustn't end in '.conf', as they are not to be loaded themselves. will link to the file in use.

If driver specific settings need to be supplied, these files would be the place to put them. Some options which may be of interest include TwinView(NVidia only), DPI, monitor-* on multihead systems.

With this, the system should be capable of switching between the two. However, there is nothing currently telling it to automatically load either. To get it loading one on boot, an init script is needed.

Init Scripts
These scripts check for the boot parameters that will be set in the bootloader and setup the system appropriately. Specifically, these scripts load the drivers modules, switch to it's opengl and opencl implementation, and tell xorg which driver to use. With this, driver switching can easily be done with OpenRC and Systemd based init systems. Just follow the instructions relative to the system's setup.

OpenRC
OpenRC is Gentoo's default init system, and thus the one most people will be using. Most of the scripts it uses are located in. These scripts are intended to be static, and as such, variables are usualy defined in in a file of the same name. This script is written keeping that in mind, so hopefully there will be no need to edit it.

Copy it to and set the executable bit:

Then add it as a boot level service.

Systemd
Add the systemd switching script

Remember to set the executable bit.

To have this script get called during the systemd init process, you can create a service file for it, but it's just as effective to integrate it into the currently existing xdm | gdm | kdm | other(?) display manager service file. You don't want to edit the service file directly, since that will get overwritten the next time that package is merged that the service file belongs to. Instead you create an override for the service file, placed in /etc/systemd/system/service-name.d

So for example if you use kdm.service you would create the directory /etc/systemd/system/kdm.service.d and place a file in it with a .conf file extension. Add a "[Service]" section that has an entry for ExecStartPre to call nvidia.start before kdm itself is started.

Bootloader
It should be possible to pass boot parameters with most bootloader, however, the means of doing it may differ. Please read other documentation for bootloaders not specified here. Note the instructions here are made to be as simple as possible. Configurations vary, please consult the existing configuration and adapt the instructions to the system.

Grub
Within the grub.cfg file you need to duplicate the desired menu item and then edit the two versions to set a boot parameter.

Efibootmgr
Before altering anything, it is a probably good idea to read and backup the current configuration. Do this by running:

Now, review the settings and alter accordingly. Below shows how one may be setup when there are no pre-existing boot entries.

Note the current efi boot settings, it will aid in the process. It may be a good idea to copy them just in case something goes wrong

Using Two Kernels
One may also setup two kernels, one with nouveau built-in and the other without it or with it built as a module. Note there is little reason to use two kernels unless nouveau is compiled-in one of them. To do this, First compile two kernels, One with Nouveau built-in

And one without or as a module

Next, Follow the same steps as above for the bootloader, changing the path/name for the nvidia and nouveau entries to point to the respective kernels.

Then refer to Init systems for seting up the script which will handle loading nvidia, changing opengl, opencl, and x11 config files.

Possibility of Live (no reboot) switching
--FireFish5000 (talk) 08:29, 10 August 2015 (UTC) It may be possible, with difficulty, to switch between nouveau and nvidia drivers without a reboot (it's GNU/Linux, the real question is how practical such a solution would be).

The instructions below should lead you to the little I currently have. It works for X11(loosing console) from nouveau to nvidia. But from nvidia to nouveau, it corrupts the display completely and goes blank/freezes with x11 (though x11 does start, ie. I can type startx, open firefox and listen to youtube videos blind).

First Ensure module unloading is supported

Then add/modify the nv-driver switcher.

With the above script, '/etc/init.d/nv-switcher nvidia' would switch to nvidia if run from shell while x11 isn't running (Checking if in use is in TODO. lsmod seems to be a good indicator, Do NOT try this script while X11 is running or if you do not understand what it is doing). Howver, shell would be blank and '/etc/init.d/nv-switcher nouveau' Would leave you in said state where nothing shows up but blind x11 will nonetheless start. This incomplete and potential harmful script was adapted from the scripts given on this page combined with the scripts here https://askubuntu.com/questions/16998/switch-between-nvidia-current-and-nouveau-without-a-reboot/17068#17068 and the suggestion here https://askubuntu.com/questions/16998/switch-between-nvidia-current-and-nouveau-without-a-reboot/381689#381689. Perhaps someone with more experience dealing with nvidia, nouveau, kernel modules, drivers, or the kernel will have a better idea on how to accomplish this.

Again, this script does NOT currently check if drivers are in use, and WILL lead to both nvidia and Nouveau drivers being loaded if you do not know what you are doing. Don't try this unless you understand the risk.

If you know a way to do this, please tell us. If you add a check for if mods are in use/successfully unloaded, feel free to edit my script to add them.