Last active
November 21, 2021 18:11
-
-
Save Natetronn/28090913834e4c1d74e8e7682a0db6c6 to your computer and use it in GitHub Desktop.
Grub GPU Switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copy the main menuentry from /boot/grub/grub.cfg and add it twice to /boot/grub/custom.cfg | |
# for Nvidia add the following to the end of the linux line: modprobe.blacklist=nouveau systemd.setenv=GPUMOD=nvidia rd.driver.blacklist=nouveau nouveau.modeset=0 nvidia.modeset=1 | |
# for Nouveau add the following to the end of the linux line: modprobe.blacklist=nvidia systemd.setenv=GPUMOD=nouveau rd.driver.blacklist=nvidia nouveau.modeset=1 nvidia.modeset=0 | |
# for example (again, adjust for your system based on your main menu entry) | |
menuentry 'Manjaro Linux - Nvidia' --class manjaro --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-xxxxxxxx-xxxxxxx-xxxxxxx-xxxxx' { | |
savedefault | |
load_video | |
set gfxpayload=keep | |
insmod gzio | |
insmod part_gpt | |
insmod ext2 | |
search --no-floppy --fs-uuid --set=root xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx | |
linux /boot/vmlinuz-5.15-x86_64 root=UUID=xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx ro nowatchdog zswap.enabled=0 mitigations=off audit=0 quiet apparmor=1 security=apparmor resume=UUID=xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx udev.log_priority=3 modprobe.blacklist=nouveau systemd.setenv=GPUMOD=nvidia rd.driver.blacklist=nouveau nouveau.modeset=0 nvidia.modeset=1 | |
initrd /boot/intel-ucode.img /boot/initramfs-5.15-x86_64.img | |
} | |
menuentry 'Manjaro Linux - Nouveau' --class manjaro --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx' { | |
savedefault | |
load_video | |
set gfxpayload=keep | |
insmod gzio | |
insmod part_gpt | |
insmod ext2 | |
search --no-floppy --fs-uuid --set=root xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx | |
linux /boot/vmlinuz-5.15-x86_64 root=UUID=xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx ro nowatchdog zswap.enabled=0 mitigations=off audit=0 quiet apparmor=1 security=apparmor resume=UUID=xxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx udev.log_priority=3 modprobe.blacklist=nvidia systemd.setenv=GPUMOD=nouveau rd.driver.blacklist=nvidia nouveau.modeset=1 nvidia.modeset=0 | |
initrd /boot/intel-ucode.img /boot/initramfs-5.15-x86_64.img | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
if [[ "$GPUMOD" == "" ]] ; then | |
# uncomment nouveau blacklists | |
sed -i '/blacklist nouveau/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist ttm/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm_kms_helper/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
cat /dev/null > /etc/X11/xorg.conf.d/01-nv.conf | |
elif [[ "$GPUMOD" == "nvidia" ]] ; then | |
# uncomment nouveau blacklists | |
sed -i '/blacklist nouveau/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist ttm/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm_kms_helper/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm/s/^#//g' "/etc/modprobe.d/mhwd-gpu.conf" | |
# for the following, you can find your specific gpu's Section Device using nvidia-settings gui | |
# https://wiki.archlinux.org/title/NVIDIA#nvidia-settings | |
cat > /etc/X11/xorg.conf.d/01-nv.conf << EOF | |
Section "Device" | |
Identifier "Device0" | |
Driver "nvidia" | |
Option "NoLogo" "True" | |
EndSection | |
EOF | |
elif [[ "$GPUMOD" == "nouveau" ]] ; then | |
# if you get "Failed to start virtualization daemon" error on boot, due to libvirtd service failing, | |
# uncomment the following systemctl to mask libvirtd: | |
# systemctl mask libvirtd | |
# | |
# comment nouveau blacklists | |
sed -i '/blacklist nouveau/s/^/#/g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist ttm/s/^/#/g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm_kms_helper/s/^/#/g' "/etc/modprobe.d/mhwd-gpu.conf" | |
sed -i '/blacklist drm/s/^/#/g' "/etc/modprobe.d/mhwd-gpu.conf" | |
cat > /etc/X11/xorg.conf.d/01-nv.conf << EOF | |
Section "Device" | |
Identifier "Device0" | |
Driver "nouveau" | |
EndSection | |
EOF | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Follow this article https://arashmilani.com/post?id=86 | |
And rename My Script and /my-script to GPU Switcher and gpu-switcher, or something similar. | |
Then create /usr/bin/gpu-switcher and add the gpu-switcher code to it. | |
This has been adapted from the from the nvidia.start script found here: | |
https://wiki.gentoo.org/wiki/Nouveau_%26_nvidia-drivers_switching#Switching_using_a_single_kernel_and_hprofile | |
You may have to adjust each Section "Device" entry of that script for your drivers and system. | |
I don't know what they should be exactly. | |
It's possible you can find more info under some file in: /etc/X11/xorg.conf.d/ - or in the forums/google. | |
Once complete, you can select the custom grub menu entry for a driver of your choice on boot. | |
Note: to see grub menu, you may need to change the following values in /etc/default/grub for the menu to show up, | |
if not already visable. | |
GRUB_DEFAULT=saved | |
GRUB_TIMEOUT=10 | |
GRUB_TIMEOUT_STYLE=menu | |
GRUB_SAVEDEFAULT=true | |
Don't forget to sudo update-grub after changing this file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment