Skip to content

Instantly share code, notes, and snippets.

@vilkoz
Last active February 27, 2020 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vilkoz/651f4179671bf0ef8e3319449573a1fa to your computer and use it in GitHub Desktop.
Save vilkoz/651f4179671bf0ef8e3319449573a1fa to your computer and use it in GitHub Desktop.
Nvidia optimus laptop run Xorg on nvidia gpu by default
systemctl --user import-environment DISPLAY
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
exec i3
#exec startkde
# /etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
Identifier "intel"
Driver "modesetting"
Option "AccelMethod" "none"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
# /etc/X11/xorg.conf.d/20-nvidia.conf
Section "Files"
ModulePath "/usr/lib/nvidia"
ModulePath "/usr/lib32/nvidia"
ModulePath "/usr/lib32/nvidia/xorg/modules"
ModulePath "/usr/lib32/xorg/modules"
ModulePath "/usr/lib64/nvidia/xorg/modules"
ModulePath "/usr/lib64/xorg/modules"
EndSection
Section "ServerLayout"
Identifier "layout"
Screen 1 "nvidia" 0 0
Inactive "intel"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:1:0:0"
EndSection
Section "Screen"
Identifier "nvidia"
Device "nvidia"
EndSection
#!/bin/bash
# /usr/local/bin/enable_nvidia_gpu.sh
CONTROLLER_BUS_ID=0000:00:01.0
DEVICE_BUS_ID=0000:01:00.0
MODULES_LOAD=(nvidia nvidia_uvm nvidia_modeset "nvidia_drm modeset=1")
echo 'Turning the PCIe controller on to allow card rescan'
sudo tee /sys/bus/pci/devices/${CONTROLLER_BUS_ID}/power/control <<<on
echo 'Waiting 1 second'
sleep 1
if [[ ! -d /sys/bus/pci/devices/${DEVICE_BUS_ID} ]]; then
echo 'Rescanning PCI devices'
tee /sys/bus/pci/rescan <<<1
echo "Waiting 1 second for rescan"
sleep 1
fi
echo 'Turning the card on'
tee /sys/bus/pci/devices/${DEVICE_BUS_ID}/power/control <<<on
for module in "${MODULES_LOAD[@]}"
do
echo "Loading module ${module}"
modprobe ${module}
done
[Unit]
Description="Turn on Nvidia GPU and load Nvidia modules"
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/enable_nvidia_gpu.sh
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment