Switching between nouveau and nvidia driver at boot time

Hi,

How can I switch between the nouveau and the (proprietary) nvidia driver at boot time?

Thanks,

Robert

A lot more information is needed.

Why?

Permanently, or switch back & forth?

What OS and version (I am guessing openSUSE, if so what version)?

It is necessary to understand what you are using and what you are trying to achieve – and why – before anyone is able to help you.

Right, that will teach me to post late in the evening when my brain doesn’t function very well … see below.

I’m using openSUSE 13.2, currently with nouveau on a Lenovo W520 laptop. I would like to switch back and forth between nouveau and nvidia, and I guess a reboot is the way to go. I don’t think it will ever be feasible to do this when X is running…

Nouveau is IMO better integrated to the system - KMS, ability to change display brightness without locking up and generally gives me a better feeling when using more open-source components rather than fewer. On the other hand, nvidia is much better at supporting games, especially when running them using wine.

Therefore, my goal is to use nouveau most of the time, but also be able to reboot and select the nvidia driver for gaming sessions.

Ah, I see.

Well, to do it that way, simply:

When you reach the Grub menu, type “e”

Go down to the line that starts with “Linux”, hit the END key to make sure you get to the end of that line (it wraps).

Add a space, then add nomodeset

This will disable the NVIDIA driver and fall back to nouveau, I believe. Late at night (or, I should say, well into early morning) for me here, so brain is now basically mush. So, if I am wrong, I am certain Wolfi will correct me. He is knowledgeable about NVIDIA.

The nomodeset will disable the NVIDIA driver, though, I know for sure.

This will only hold until the next reboot, as it is temporary when added to the boot that way. The next time you boot, NVIDIA will be back in control.

OK, I’ll try that tonight - basically install both nvidia and nouveau and add ‘nomodeset’ when trying to boot with nouveau. One thing I’m not sure about though - I recall the nvidia driver will blacklist nouveau when installed. Is there a way to workaround that?

Remove the blacklist file? But you’d probably have to recreate the initrd too, as the blacklist is in there as well, and the nouveau driver will be missing from the initrd if blacklisted.
You’ll probably get away without changing the initrd, if you disable plymouth or at least remove it from the initrd, as this is what loads the graphics driver kernel modules already.
(At least on 13.1 the nouveau driver will not work at all if the nouveau module is missing/blacklisted in the initrd, if plymouth is in there. I don’t know yet about 13.2)

You’ll have other problems as well anyway though:

  • Xorg will prefer the nvidia driver if it’s available. So you either have to make sure it cannot start, or use an xorg.conf.
  • the nvidia driver replaces system libraries, namely Xorg’s libglx and Mesa’s libGL1. This breaks all Mesa drivers (regarding OpenGL at least).
    In 13.2 the libglx is switched via “update-alternatives”, and the nvidia driver uses a file in /etc/ld.so.conf.d/ to make the system prefer its own libGL1.

So, it’s not that straight-forward and easy to switch the drivers on boot.
Doable I suppose, but not just by adding/removing nomodeset to/from the boot options.

Yeah, that was probably the dumbest answer I have given on these forums, I think! :shame:

After I shut off my PC and went to bed, as soon as my head hit the pillow, my brain decided to start working again! However, I was not willing to get back up, come back downstairs, and fire the PC back up to correct myself. I was confident you would straighten it up, wolfi.:wink:

One possible way would be to install twice, dual boot.

One install is set up with nouveau, the other with NVIDIA, perhaps they could share the same /home? Your thoughts on that, wolfi?

Of course. That would be possible.

Or somebody posted a script here in the forums some time ago, that would switch between nouveau and nvidia. I don’t remember the details, I didn’t really look at it as I wasn’t interested in doing that anyway. (personally I don’t even use an nvidia card)

I hope I can find that again…
It probably would have to be adapted to the new way libglx is installed in 13.2 (via update-alternatives), but it would be a good starting point probably.

Was it perhaps my script for switching between Intel and Nvidia on Optimus systems with this type of MUX? Switching to Intel as an alternativ for Nouveau is for most user scenarios better, performance isn’t much lower and battery time is far better. And switching into Nvidia mode gives much more graphic power than running bumblebee in Optimus mode. Only drawback is you’ll have to enter BIOS setup to switch. The script to put into /etc/init.d/boot.local for 13.2 is here, 64-bit only:



rm /etc/alternatives/libglx.so
mode=$(/sbin/lspci | egrep 'VGA|3D');

#Make shure we are in command of /usr/X11R6/lib
if  -e /etc/ld.so.conf.d/nvidia-gfxGO*.conf ]; then
    /bin/rm /etc/ld.so.conf.d/nvidia-gfxGO*.conf
fi  

#Check graphics mode fix symlinks
if  `echo $mode | grep -c "Intel" ` -gt 0 ]; then
ln -s /usr/lib64/xorg/modules/extensions/xorg/xorg-libglx.so /etc/alternatives/libglx.so
fi 

if  -e /usr/X11R6/lib64/libGL.so.1 ]; then
    /bin/rm /usr/X11R6/lib64/libGL.so.1
fi    

if  `echo $mode | grep -c "NVIDIA" ` -gt 0 ]; then
    ln -s /usr/lib64/xorg/modules/extensions/nvidia/nvidia-libglx.so /etc/alternatives/libglx.so
    /sbin/ldconfig /usr/X11R6/lib64
fi

Note, this only works with Nvidia installed from the repo in yast.

Yes, that was indeed what I meant!

Should be adaptable for switching between nouveau and nvidia as well I suppose, i.e. just turn on/off the nvidia driver (that’s what it actually does in the end anyway).

Btw, for switching libglx, you should just as well be able to use “update-alternatives” I think.

Yes I made an attempt vith update-alternatives but had a silly error and decided to use brute force. But it can be done just a little shorter with it.


mode=$(/sbin/lspci | egrep 'VGA|3D');

#Make shure we are in command of /usr/X11R6/lib
if  -e /etc/ld.so.conf.d/nvidia-gfxGO*.conf ]; then
    /bin/rm /etc/ld.so.conf.d/nvidia-gfxGO*.conf
fi  

#Check graphics mode fix symlinks
if  `echo $mode | grep -c "Intel" ` -gt 0 ]; then
     update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/xorg/xorg-libglx.so
fi 

if  -e /usr/X11R6/lib64/libGL.so.1 ]; then
    /bin/rm /usr/X11R6/lib64/libGL.so.1
fi    

if  `echo $mode | grep -c "NVIDIA" ` -gt 0 ]; then
    update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/nvidia/nvidia-libglx.so
    /sbin/ldconfig /usr/X11R6/lib64
fi

I suppose one could add an extra boot line into grub and pass some silly names on each commandline for nvidia and nouveau.

It would be fascinating to see if you can get this working for the OP’s purpose, and it would probably be valuable to a few users.:wink:

Probably something like:


#Make shure we are in command of /usr/X11R6/lib
if  -e /etc/ld.so.conf.d/nvidia-gfxGO*.conf ]; then
    /bin/rm /etc/ld.so.conf.d/nvidia-gfxGO*.conf
fi  

#Check graphics mode fix symlinks
if  `grep -c "nouveau" /proc/cmdline` -gt 0 ]; then
     update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/xorg/xorg-libglx.so
fi 

if  -e /usr/X11R6/lib64/libGL.so.1 ]; then
    /bin/rm /usr/X11R6/lib64/libGL.so.1
fi    

if  `grep -c "nouveau" /proc/cmdline` -eq 0 ]; then
    update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/nvidia/nvidia-libglx.so
    /sbin/ldconfig /usr/X11R6/lib64
fi

Should make it possible to switch to nouveau, by adding “nouveau” to the boot options.
Please note that I haven’t tried it (no nvidia system here), and have no idea whether it would work as-is.

The blacklist nouveau file shouldn’t really matter, but one would have to still add an xorg.conf (or better a snippet in /etc/X11/xorg.conf) to switch the nouveau X driver, when “nouveau” is set. (the nvidia driver is preferred by X)
I guess adding something like:

/bin/cat > /etc/X11/xorg.conf.d/20-nouveau.conf << END 
Section Device
Driver "nouveau"
End Section
END

to the nouveau branch, and:

/bin/rm /etc/X11/xorg.conf.d/20-nouveau.conf

to the nvidia branch might work.
Of course if necessary you vould do something similar with the blacklist file as well.

And as said, you probably should remove plymouth from the initrd or disable it.

Oops, I just noticed that I made a typo. It’s “EndSection”, not “End Section”…:shame:

Here’s now how the whole file could look like:

#Make sure we are in command of /usr/X11R6/lib
if  -e /etc/ld.so.conf.d/nvidia-gfxGO*.conf ]; then
    /bin/rm /etc/ld.so.conf.d/nvidia-gfxGO*.conf
fi  

#Check graphics mode fix symlinks
if  `grep -c "nouveau" /proc/cmdline` -gt 0 ]; then
     update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/xorg/xorg-libglx.so

     /bin/cat > /etc/X11/xorg.conf.d/20-nouveau.conf << END 
Section "Device"
Driver "nouveau"
EndSection
END
fi 

if  -e /usr/X11R6/lib64/libGL.so.1 ]; then
    /bin/rm /usr/X11R6/lib64/libGL.so.1
fi    

if  `grep -c "nouveau" /proc/cmdline` -eq 0 ]; then
    update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/nvidia/nvidia-libglx.so
    /sbin/ldconfig /usr/X11R6/lib64
    /bin/rm /etc/X11/xorg.conf.d/20-nouveau.conf
fi

But again, this is untested, and I probably forgot something anyway… :wink:
I just noticed, that the script doesn’t enable nvidia’s libGL.so.1 at all at the moment… It just removes it.
So this would have to be added still.

This might work:

#Make sure we are in command of /usr/X11R6/lib
if  -e /etc/ld.so.conf.d/nvidia-gfxGO*.conf ]; then
    /bin/rm /etc/ld.so.conf.d/nvidia-gfxGO*.conf
fi  

#Check graphics mode fix symlinks
if  `grep -c "nouveau" /proc/cmdline` -gt 0 ]; then
    update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/xorg/xorg-libglx.so
    /bin/cat > /etc/X11/xorg.conf.d/20-nouveau.conf << END 
Section "Device"
Driver "nouveau"
EndSection
END
    # use Mesa's libGL
    ln -sf  /usr/lib64/libGL.so.1.2.0 /usr/lib64/libGL.so.1
fi 

if  `grep -c "nouveau" /proc/cmdline` -eq 0 ]; then
    update-alternatives --set libglx.so /usr/lib64/xorg/modules/extensions/nvidia/nvidia-libglx.so
    /sbin/ldconfig /usr/X11R6/lib64
    /bin/rm /etc/X11/xorg.conf.d/20-nouveau.conf
    # use nvidia's libGL
    ln -sf  /usr/X11R6/lib64/libGL.so.1 /usr/lib64/libGL.so.1
fi

But that’s it from me for now… :wink:

Interesting, intriguing, Wolfi. :slight_smile: I will see if sometime in the next few days I can break some free time loose, take one of the machines with nVidia card aside, and run some tests with this, see what might be next.

Wow, lots of nice stuff going on since I last checked … I’m traveling next week but after that I’ll give it a shot!

I’m confused about the nouveau driver in the code: I’d like to install the nvidia driver from the nvidia repo and use this code as boot.local to have toggle on or off the external nvidia gpu and the nvidia driver. So how should there be a place for nouveau?

nouveau is just a driver for the NVIDIA family of GPU. the NVIDIA driver is the proprietary driver for the NVIDIA family of GPU.

You use one or the other never ever both. As far as I know you can’t toggle “off” the NVIDIA GPU in a normal computer.

Perhaps you need to explain more about what hardware you have and what you want to accompluish.

Is this by any chance an Intel+NVIDIA notebook with Optimus tech? If so you need to run the Bumblebee packages.