Using Optimus on Void or Non Systemd Distros
What is optimus technology?
According to gentoo wiki
NVIDIA Optimus is a proprietary technology that seamlessly switches between two GPUs. It is typically used on systems that have an integrated Intel GPU and a discrete NVIDIA GPU. The main benefit of using NVIDIA Optimus is to extend battery life by providing maximum GPU performance only when needed.
There is a great wiki about using bumblebee(not transformer) on void linux but bumblebee’s project last commit was in 2013 and it doesn’t support vulkan, so no luck for linux gamers. A better way is to use a utility like nvidia-prime which is available for ubuntu or optimus-manager which is available for arch-based distros(available in AUR). Sadly, these projects require systemd as a init system. There is only one project which uses shell script and partly depends on systemd but is pretty hackable - nvidia-xrun.
Problem on void
libglvnd is broken in void repos which makes it hard to have multiple drivers from different vendors to coexist on the same filesystem. This results in having either openGL libraries from mesa or nvidia.
The Hack
Install nvidia openGL libraries in /opt directory and point nvidia-xrun to use them. This is just a workaround of libglvnd.
First of all install these packages:
- nvidia-dkms - for kernel modules
- libGL libEGL - mesa drivers
- xrandr xorg - display server
- any wm/de
Create a file /etc/modprobe.d/nvidia.conf for blacklisting nvidia kernel modules so that they won’t be loaded at boot. Add the following text:
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uv
blacklist nouveau
Next create some directories
$ sudo mkdir /opt/nvidia
$ sudo mkdir -p /opt/nvidia/fakeroot/usr/lib
$ sudo mkdir -p /opt/nvidia/fakeroot/usr/lib32
$ sudo mkdir /etc/X11/nvidia
Now we have to create a fakeroot directory with nvidia openGL libraries
$ sudo ln -s /opt/nvidia/fakeroot/usr/lib /opt/nvidia/fakeroot/lib
$ sudo ln -s /opt/nvidia/fakeroot/usr/lib32 /opt/nvidia/fakeroot/lib32
$ sudo chmod 755 -R /opt/nvidia/fakeroot
$ xbps-install --rootdir /opt/nvidia/fakeroot --repository https://alpha.de.repo.voidlinux.org/current --repository https://alpha.de.repo.voidlinux.org/current/nonfree --repository https://alpha.de.repo.voidlinux.org/current/multilib --repository https://alpha.de.repo.voidlinux.org/current/multilib/nonfree --yes --sync nvidia nvidia-libs nvidia-libs-32bit
Next clone my repo and move the scripts to respective location
$ git clone https://github.com/fd0e/optimus-hack.git
$ cd optimus-hack/
$ sudo cp -r xorg.conf xorg.conf.d /etc/X11/nvidia/
$ sudo cp run.sh /opt/nvidia/
There is also off.sh which ensures that GPU is off. Run this as root at boot.
Also add these lines in your ~/.xinitrc.
# load additional configs
if [ "$2" = "nvidia" ]; then
XINIT_D="/etc/X11/nvidia/xinit/xinitrc.d"
else
XINIT_D="/etc/X11/xinit/xinitrc.d"
fi
if [ -d "$XINIT_D" ]; then
for f in "$XINIT_D/?*.sh" ; do
[ -x "$f" ] && . "$f"
done
unset f
fi
unset XINIT_D
# additional nvidia specific settings
if [ "$2" = "nvidia" ]; then
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
fi
Now close your X session and run /opt/nvidia/run.sh.
And boom! Your X session is now running on nvidia opengl libraries.
Troubleshooting
If steam complains about missing libGL. Run steam using this command
$ STEAM_RUNTIME_PREFER_HOST_LIBRARIES=0 steam
Conclusion
I don’t recommend using this method but this is the only thing that worked for me.
See this article for more details - here