Early loading Nvidia module resolution problem

Hi guys! Just like most people with Nvidia cards I’m having a terrible time setting things up.

First of all, here’s the output of inxi -Ga

Graphics:
  Device-1: Intel TigerLake-H GT1 [UHD Graphics] vendor: Acer Incorporated ALI
    driver: i915 v: kernel arch: Gen-12.1 process: Intel 10nm built: 2020-21
    ports: active: eDP-1 empty: DP-1,DP-2 bus-ID: 0000:00:02.0
    chip-ID: 8086:9a68 class-ID: 0300
  Device-2: NVIDIA TU117M [GeForce GTX 1650 Mobile / Max-Q]
    vendor: Acer Incorporated ALI driver: nvidia v: 525.89.02
    alternate: nouveau,nvidia_drm non-free: 525.xx+
    status: current (as of 2023-02) arch: Turing code: TUxxx
    process: TSMC 12nm FF built: 2018-22 bus-ID: 0000:01:00.0
    chip-ID: 10de:1f9d class-ID: 0300
  Device-3: Quanta HD User Facing type: USB driver: uvcvideo bus-ID: 3-9:3
    chip-ID: 0408:a061 class-ID: 0e02
  Display: x11 server: X.Org v: 21.1.7 compositor: Picom v: git-b700a
    driver: X: loaded: intel,nvidia unloaded: modesetting
    alternate: fbdev,nouveau,nv,vesa dri: i965 gpu: i915 display-ID: :0
    screens: 1
  Screen-1: 0 s-res: 2560x2160 s-dpi: 96 s-size: 676x570mm (26.61x22.44")
    s-diag: 884mm (34.81")
  Monitor-1: HDMI-1-0 pos: top-left res: 2560x1080 hz: 60 dpi: 97
    size: 673x284mm (26.5x11.18") diag: 730mm (28.76") modes: N/A
  Monitor-2: eDP1 pos: primary,bottom-r res: 1920x1080 hz: 144 dpi: 143
    size: 340x190mm (13.39x7.48") diag: 389mm (15.33") modes: N/A
  API: OpenGL v: 4.6 Mesa 22.3.5 renderer: Mesa Intel UHD Graphics (TGL GT1)
    direct-render: Yes

As you can see, I have that optimus setup with integrated Intel graphics and a dedicated nvidia GTX1650.

I had to set the nvidia driver to be loaded early setting the nvidia-drm.modeset=1 in the /etc/kernel/cmdline. Doing so made the driver load correctly, my external monitor was detected and worked perfectly, but my main screen resolution changed. The lightdm resolution was wrong too. After the login I could set the right resolution using arandr (curiously the right resolution was the only option). I saved the display setup to the monitor.sh script and it worked, but one thing I couldn’t fix: the lightdm resolution after boot.
If I logout, the lightdm screen will be in the right resolution (1920x1080), but if I reboot, it will be in 640x480. If I remove the kernel parameter to load the nvidia driver earlier, the lightdm screen will be ok but my monitor will not work and the driver will be “N/A” in the inxi -Ga output.

Any help will be appreciated.

tl;dr: I have to load the nvidia driver early to make it work but it breaks the lightdm resolution after boot.

Try removing (not including any nvidia related modules in the dracut created kernel image.
Use omit_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm " in dracut config file.
https://discovery.endeavouros.com/installation/dracut/2022/12/
https://man.archlinux.org/man/dracut.conf.5

This is what I did for my LightDM/i3-wm install on an Optimus laptop, so sharing in the hope it helps you resolve your issue too.

  • Add nvidia_drm.modeset=1 to the /etc/kernel/cmdline
    Added for completeness, but it looks like you already did this

  • Omit drivers as petsam pointed out above

  • Run

sudo dracut-rebuild
sudo reinstall-kernels
  • Create a file on /etc/X11/xorg.conf.d/optimus.conf with:
Section "Module"
    Load "modesetting"
EndSection
Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
    Option "AllowEmptyInitialConfiguration"
EndSection

The BusID should be PCI:1:0:0, but you can find yours using

lspci | grep -E 'VGA|3D'

There is also an alternate 20-nvidia.conf on the Nvidia troubleshooting WIKI.
NOTE: Only use one, not both

  • For Lightdm:

Create a file on ‘/usr/local/bin/optimus.sh’ with:

#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Make it executable with:

sudo chmod a+rx /usr/local/bin/optimus.sh
  • Edit /etc/lightdm/lightdm.conf and set this at the [Seat:*] section:
display-setup-script=/usr/local/bin/optimus.sh 

Just uncomment, and add the location of the script

  • Remove xf86-video-intel
    I was having issues with only one strange resolution available, which was not the default resolution of laptop panel

  • Reboot

Optional

  • Remove xf86-video-amdgpu and xf86-video-ati

References where i found above info:

Discovery Nvidia