Ubuntu – Nvidia Optimus on 20.04: switching to Intel GPU works on Ubuntu Mate, but not on Ubuntu Gnome

20.04hybrid-graphicsnvidia-optimusnvidia-primeubuntu-mate

I am trying to revive an old Lenovo Ideapad Z360 laptop using Ubuntu 20.04 LTS. This laptop has an integrated Intel GPU and a discrete Nvidia GPU, as follows:

$ lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 18)
    Subsystem: Lenovo Core Processor Integrated Graphics Controller
    Kernel driver in use: i915
    Kernel modules: i915
--
01:00.0 VGA compatible controller: NVIDIA Corporation GT218M [GeForce 310M] (rev a2)
    Subsystem: Lenovo GT218M [GeForce 310M]
    Kernel driver in use: nvidia
    Kernel modules: nvidiafb, nouveau, nvidia

On Ubuntu Mate 20.04, I am able to switch from the Nvidia GPU to the Intel GPU just fine. I can do this using the panel icon (mate-optimus); or using the terminal (prime-select); or using the Nvidia application (nvidia-settings). They all work, and the desktop loads just fine after I logout and login back again. The "on demand" option doesn't work — mate-optimus' github states that "NVIDIA On-Demand (known as PRIME Render Offload) will require the NVIDIA 435 drivers", so I guess this excludes my GPU (which uses NVIDIA 340 drivers) —, but I am ok with that. I am happy being able to switch between the Intel and Nvidia GPUs when needed. On Ubuntu Mate 20.04, this works just fine.

However, on Ubuntu 20.04 (Gnome), switching to the Intel GPU doesn't work!!

First thing I noticed is that the "PRIME Profiles" menu section was not available in the Nvidia application (nvidia-settings). I was able to fix that by installing the nvidia-prime package (which came pre-installed in Ubuntu Mate, but not in Ubuntu Gnome).

However, when I try to switch to the Intel GPU, I am not able to log back into the desktop after I logout (it loops back to the gdm3 greeter). If I reboot when the Intel GPU is selected, than I get a black screen. In order to fix that, I have to either switch back to the Nvidia GPU (using prime-select), or remove all nvidia packages (and use the nouveau driver instead).

So my question is: Why does it work on Ubuntu Mate, but not on Ubuntu Gnome?

Best Answer

I have an old Alienware 11Mx3 with Optimus on Nvidia 310. It is running awesome on Nvidia 345.21. I can switch smoothly back and forth... My trick is to install opting out of "third party drivers and ...". That gives me a closed-driver clean installation.

From there and after logging in, I update, upgrade and without rebooting perform the installation of the nvidia-driver-435. After rebooting, it all works.

It all works out nice and believe me I had lost all hope for Optimus. Before, my Alienware was collecting dust in its bag... now it goes with me everywhere. I am running Ubuntu Budgie 20.04 LTS and it's buttery smooth in Intel & Nvidia mode...