bayasdev / envycontrol

Easy GPU switching for Nvidia Optimus laptops under Linux
MIT License
1.3k stars 61 forks source link

Xorg no longer rootless #12

Closed Vargblood closed 2 years ago

Vargblood commented 2 years ago

Hi everyone and thank you for your great work and this project. I switched recently from Optimus manager to envycontrol and everything is working fine. I noticed that my Xorg session under Gnome now runs as root. Before the change, the process ran rootless. Is this change possibly related to envycontrol or the gdm package I changed from gdm-Prime to the original gdm package? Has anyone who has also changed noticed the same behavior?

DaVikingMan commented 2 years ago

This page might help you : https://wiki.archlinux.org/index.php/Xorg#Rootless_Xorg

Vargblood commented 2 years ago

This page might help you : https://wiki.archlinux.org/index.php/Xorg#Rootless_Xorg

I know this page. Gdm run xorg rootless by default but not with my current configuration. Now I’m looking for the cause.

DaVikingMan commented 2 years ago

Which init system and linux distro are you using? Also, what's the output of cat /proc/cmdline?

Vargblood commented 2 years ago

Which init system and linux distro are you using? Also, what's the output of cat /proc/cmdline?

I use arch linux with systemd.

Output of cat /proc/cmdline:

pti=on page_alloc.shuffle=1 BOOT_IMAGE=/@/boot/vmlinuz-linux-hardened root=UUID=[UUID] rw rootflags=subvol=@ cryptdevice=/dev/nvme0n1p2:arch splash apparmor=1 security=apparmor intel_iommu=on iommu=pt

I replaced the actual UUID with [UUID].

DaVikingMan commented 2 years ago

According to the output, it seems like KMS for nvidia isn't enabled. To do that :

  1. Open /etc/default/grub with a text editor(with root)
  2. Add nvidia-drm.modeset=1 to GRUB_CMDLINE_LINUX_DEFAULT=""(There should be two of these lines. One should already be filled with an argument. Add it to the one which doesn't have anything in its quotation marks like GRUB_CMDLINE_LINUX_DEFAULT="nvidia-drm.modeset=1". You can also append this line rather than editing the existing ones)
  3. Run sudo grub-mkconfig -o /boot/grub/grub.cfg
  4. Reboot
  5. Check if nvidia kms is enabled by running cat /proc/cmdline and checking if the line nvidia-drm.modeset=1 is in the output
Vargblood commented 2 years ago

This is the solution. Now Xorg is run as a normal user. Two more questions: Did Optimus manager set this option automatically and that's why I never noticed? Do I need to pay attention to anything else in the future when this option (nvidia-drm.modeset=1) is set or is this standard with an nvidia card anyway?

Thanks for your very helpful solution description and your great help.

DaVikingMan commented 2 years ago
  1. Optimus-manager doesn't add this option to the kernel parameters so It might be related to gdm-Prime instead of optimus-manager as that package does add some patches for hybrid graphics.
  2. Although this isn't pre-enabled in nvidia cards, it should be enabled as it enables the card to do direct rendering, which helps the kernel to access direct rendering manager(https://en.wikipedia.org/wiki/Direct_Rendering_Manager for more info regarding this). This option shouldn't cause any problems so there isn't a need to pay attention to this option.
Vargblood commented 2 years ago

Awesome. Thank you. Maybe someone should add this to the wiki of this project for those who come from Optimus manager and used the gdm-prime package.