How can I set "prime-run" as the default of every application in Arch Linux?
- User
How can I set "prime-run" as the default of every application in Arch Linux?
- Assistant
How can I set "prime-run" as the default of every application in Arch Linux?
To set prime-run as the default for every application on your Arch Linux system, you'll want to ensure that the environment variables prime-run typically sets are applied globally. This approach allows all applications to utilize the discrete NVIDIA GPU by default without needing to prepend prime-run to each command.
Here’s a step-by-step guide to achieve this:
prime-run DoesThe prime-run script generally sets several environment variables to enable NVIDIA's PRIME Render Offload. Specifically, it sets:
__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia
__VK_LAYER_NV_optimus=nvidia
These variables instruct the system to use the discrete NVIDIA GPU for rendering.
To apply these settings system-wide, you can create a script in /etc/profile.d/ that exports these variables for all users and applications.
Open a terminal and create a new script file:
sudo nano /etc/profile.d/prime-offload.sh
Insert the following lines into the file:
#!/bin/sh
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=nvidia
Save the file and exit the editor (in nano, press Ctrl+O, then Enter, and Ctrl+X). Then, make the script executable:
sudo chmod +x /etc/profile.d/prime-offload.sh
While setting environment variables helps, configuring Xorg ensures that the NVIDIA GPU is prioritized for rendering.
Create a new file for NVIDIA’s DRM (Direct Rendering Manager) settings:
sudo nano /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf
Section "OutputClass"
Identifier "nvidia"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "PrimaryGPU" "yes"
EndSection
This configuration tells Xorg to use the NVIDIA GPU as the primary GPU.
To ensure the NVIDIA GPU is properly initialized, enable the DRM modeset by adding a kernel parameter.
Open the GRUB configuration file:
sudo nano /etc/default/grub
nvidia-drm.modeset=1 to GRUB_CMDLINE_LINUXFind the line starting with GRUB_CMDLINE_LINUX and append nvidia-drm.modeset=1. For example:
GRUB_CMDLINE_LINUX="... nvidia-drm.modeset=1"
After saving the file, update GRUB to apply the changes:
sudo grub-mkconfig -o /boot/grub/grub.cfg
For all changes to take effect, reboot your computer:
sudo reboot
After rebooting, verify that the NVIDIA GPU is being used by default.
Open a terminal and run:
echo $__NV_PRIME_RENDER_OFFLOAD
echo $__GLX_VENDOR_LIBRARY_NAME
echo $__VK_LAYER_NV_optimus
All should return the values you set (1, nvidia, and nvidia respectively).
Use nvidia-smi to verify that applications are utilizing the NVIDIA GPU:
nvidia-smi
You should see processes listed that are using the GPU.
Power Consumption: Using the discrete NVIDIA GPU by default can lead to increased power consumption and reduced battery life on laptops. Be mindful of this trade-off, especially if you're using a portable device.
Performance vs. Efficiency: While the discrete GPU offers better performance, integrated GPUs (like Intel's) are more power-efficient. If you encounter issues or need better battery life, consider switching back or using hybrid modes.
Driver Updates: Ensure your NVIDIA drivers are up-to-date to maintain compatibility and performance.
If you prefer not to set environment variables globally, you can use a systemd user service to apply them to your graphical session.
mkdir -p ~/.config/environment.d
nano ~/.config/environment.d/prime.conf
Insert the following lines:
__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia
__VK_LAYER_NV_optimus=nvidia
Log out and log back in to apply the changes.
By following the steps above, you configure your Arch Linux system to use the discrete NVIDIA GPU by default for all applications. This setup leverages global environment variables and Xorg configurations to ensure that prime-run-like behavior is enabled system-wide.
If you encounter any issues or need to revert the changes, you can remove the created files and scripts or adjust the configurations accordingly.
Note: Always back up configuration files before making changes. This ensures you can restore previous settings if something doesn't work as expected.
Not yet included in a published release.