├── .gitignore ├── README.md ├── Setup.sh ├── Systemd-Nvidia-Entry.sh ├── config-optimus.sh ├── extra.py ├── solus-prime-indicator ├── Makefile ├── README.md ├── gpu-switch-nosudo.sh ├── gpu-switch.policy ├── intel.svg ├── nvidia.svg ├── solus-prime-indicator.desktop └── trayicon.py └── systemd-nvidia-entry.service /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | OptimusScript\.zip 3 | 4 | Solus/SolusOptimusScript\.zip 5 | **/*~ 6 | *~ 7 | .vscode/ 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Systemd-Nvidia-Entry 2 | * It's started as a fork from [Grub-Nvidia-Entry](https://github.com/Superdanby/Grub-Nvidia-Entry) 3 | * I'm trying this using Solus, but I believe that others systems can work with some tweaks. 4 | * There are two versions, one with Nouveau and this one with bbswitch, if you prefer with nouveau go to Releases. 5 | 6 | ## Prerequisites 7 | * Nvidia driver 8 | * UEFI 9 | * bbswitch-current 10 | 11 | ## Supported Operating Systems 12 | * Solus (tested on current kernel) 13 | * Arch Linux 14 | `sudo pacman -S lsb-release` 15 | 16 | ## Arch 17 | * After installing Nvidia driver and lsb-release 18 | * Run Systemd-Nvidia-Entry.sh 19 | * On Arch there is no need to run it again after updates. 20 | 21 | ## Solus Instructions 22 | 23 | * Install bbswitch-current: 24 | 25 | `sudo eopkg install bbswitch-current` 26 | 27 | * Install nvidia proprietary drivers: 28 | 29 | `sudo eopkg install nvidia-glx-driver-current nvidia-glx-driver-common nvidia-glx-driver-32bit` 30 | 31 | * Reboot your computer 32 | 33 | * Clone scripts: 34 | 35 | `git clone git@github.com:MarechalLima/Systemd-Nvidia-Entry.git` 36 | 37 | * Execute the following command to make Intel as default: 38 | 39 | `sh Setup.sh` 40 | * To get rid of everything and make Nvidia default again: 41 | 42 | `sh Setup.sh rm` 43 | 44 | ### Solus-prime-indicator (it only shows which driver is up) 45 | * To install solus-prime-indicator use the command: 46 | 47 | `python3 extra.py install` 48 | 49 | * You can remove solus-prime-indicator with the following command: 50 | 51 | `python3 extra.py remove` 52 | 53 | ## ATTENTION 54 | * After a **kernel update**, you need to execute again: 55 | 56 | `Systemd-Nvidia-Entry` 57 | 58 | ## Caution 59 | When booting, config-optimus.sh will verify whether you are using intel or nvidia, and while on intel 00-ldm.conf will be on /opt/Systemd-Nvidia-Entry/ 60 | ## Donation 61 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=nicholaslima%2erw%40gmail%2ecom&lc=US&item_name=Nicholas%20Lima%20de%20Souza%20Silva&item_number=MarechalLima¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) 62 | 63 | # Disclaimer 64 | * **USE AT YOUR OWN RISK** 65 | -------------------------------------------------------------------------------- /Setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | install(){ 4 | sudo mkdir /opt/Systemd-Nvidia-Entry/ -p 5 | echo "Making directory /opt/Systemd-Nvidia-Entry" 6 | sudo cp config-optimus.sh /opt/Systemd-Nvidia-Entry/ 7 | sudo chmod 775 /opt/Systemd-Nvidia-Entry/config-optimus.sh 8 | sudo cp systemd-nvidia-entry.service /etc/systemd/system/ 9 | sudo systemctl enable systemd-nvidia-entry.service 10 | sudo cp Systemd-Nvidia-Entry.sh /usr/bin/Systemd-Nvidia-Entry 11 | sudo chmod +x /usr/bin/Systemd-Nvidia-Entry 12 | chmod +x Systemd-Nvidia-Entry.sh 13 | sh Systemd-Nvidia-Entry.sh 14 | printf "Clr-boot-manager options with Nvidia modules disabled!\n" 15 | sudo mkdir -p /etc/kernel/cmdline.d/ 16 | printf " modprobe.blacklist=nvidia,nvidia_drm,nvidia_modeset,nvidia_uvm" | sudo tee -a /etc/kernel/cmdline.d/40_switch_nvidia.conf 17 | } 18 | 19 | uninstall(){ 20 | mountPoint="/mnt/Systemd-Nvidia-Entry" 21 | partitionEFI=$(lsblk -o NAME,FSTYPE -l | grep vfat) 22 | partitionEFI=${partitionEFI::-5} 23 | if ! [[ `cat /proc/mounts | grep /boot` == "" ]]; then 24 | mountPoint="/boot" 25 | else 26 | if ! [[ `cat /proc/mounts | grep /mnt/Systemd-Nvidia-Entry` == "" ]]; then 27 | printf "\n/mnt/Systemd-Nvidia-Entry is busy! Please unmount /mnt/Systemd-Nvidia-Entry!" 28 | printf "\nExiting...\n" 29 | exit 30 | fi 31 | sudo mkdir /mnt/Systemd-Nvidia-Entry -p 32 | printf "\n----------------------\n\n" 33 | printf "Mounting EFI Partition ($partitionEFI)\n" 34 | sudo mount /dev/$partitionEFI $mountPoint 35 | fi 36 | 37 | sudo rm -f $mountPoint/loader/entries/nvidia.conf 38 | configFile=$(uname -r) 39 | if [[ `echo $configFile | grep current` ]]; then 40 | configFile=${configFile::-8} 41 | else 42 | configFile=${configFile::-4} 43 | fi 44 | configFile=$(ls $mountPoint/loader/entries/ | grep $configFile) 45 | sudo sed -i 's/ \//g' $mountPoint/loader/entries/$configFile 46 | 47 | if [[ $mountPoint == "/mnt/Systemd-Nvidia-Entry" ]]; then 48 | sudo umount $mountPoint 49 | fi 50 | 51 | if ! [[ -e /etc/X11/xorg.conf.d/00-ldm.conf ]]; then 52 | sudo mv /opt/Systemd-Nvidia-Entry/00-ldm.conf /etc/X11/xorg.conf.d/00-ldm.conf -f 53 | fi 54 | echo "Removing directory /opt/Systemd-Nvidia-Entry" 55 | sudo rm -f /usr/bin/Systemd-Nvidia-Entry 56 | sudo rm -rf /opt/Systemd-Nvidia-Entry/ 57 | sudo sed -i 's/ \//g' /etc/kernel/cmdline.d/40_switch_nvidia.conf 58 | sudo systemctl disable systemd-nvidia-entry.service 59 | sudo rm /etc/systemd/system/systemd-nvidia-entry.service 60 | } 61 | 62 | if [[ $1 == "rm" ]]; then 63 | uninstall 64 | else 65 | install 66 | fi 67 | -------------------------------------------------------------------------------- /Systemd-Nvidia-Entry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | systemRelease=$(lsb_release -is) 3 | printf "######### WARNING ########\n" 4 | printf "You need to be on the latest kernel!\n" 5 | printf "Do you wish to proceed? Clr-boot-manager will RUN (on Solus)!\n" 6 | select yn in "Yes" "No"; do 7 | case $yn in 8 | "Yes") if [ $systemRelease == "Solus" ]; then 9 | sudo clr-boot-manager update 10 | fi 11 | break;; 12 | "No") exit;; 13 | esac 14 | done 15 | 16 | mountPoint="/mnt/Systemd-Nvidia-Entry" 17 | partitionEFI=$(lsblk -o NAME,FSTYPE -l | grep vfat) 18 | partitionEFI=${partitionEFI::-5} 19 | if ! [[ `cat /proc/mounts | grep /boot` == "" ]]; then 20 | mountPoint="/boot" 21 | else 22 | if ! [[ `cat /proc/mounts | grep /mnt/Systemd-Nvidia-Entry` == "" ]]; then 23 | printf "\n/mnt/Systemd-Nvidia-Entry is busy! Please unmount /mnt/Systemd-Nvidia-Entry!" 24 | printf "\nExiting...\n" 25 | exit 26 | fi 27 | sudo mkdir /mnt/Systemd-Nvidia-Entry -p 28 | printf "\n----------------------\n\n" 29 | printf "Mounting EFI Partition ($partitionEFI)\n" 30 | sudo mount /dev/$partitionEFI $mountPoint 31 | fi 32 | 33 | printf "\n----------------------\n\n" 34 | printf "Configuring...\n" 35 | printf "Original boot options with Nvidia modules disabled!\n" 36 | configFile=`ls -t $mountPoint/loader/entries/ | grep -iv fallback | grep -i $systemRelease | head -1` 37 | 38 | if [[ `sudo cat $mountPoint/loader/entries/$configFile | grep modprobe.blacklist=nvidia,nvidia_drm,nvidia_modeset,nvidia_uvm` == '' ]]; then 39 | sudo sed -i '/options/s/$/ modprobe.blacklist=nvidia,nvidia_drm,nvidia_modeset,nvidia_uvm/' $mountPoint/loader/entries/$configFile 40 | fi 41 | sudo cp -f $mountPoint/loader/entries/$configFile $mountPoint/loader/entries/nvidia.conf 42 | sudo sed -i '/title/s/$/ Nvidia/' $mountPoint/loader/entries/nvidia.conf 43 | 44 | sudo sed -i 's/ \//g' $mountPoint/loader/entries/nvidia.conf 45 | 46 | if [[ `sudo cat $mountPoint/loader/entries/nvidia.conf | grep nvidia-drm.modeset=1` == '' ]]; then 47 | sudo sed -i '/options/s/$/ nvidia-drm.modeset=1/' $mountPoint/loader/entries/nvidia.conf 48 | fi 49 | 50 | printf "\nNew boot menu entry with Nvidia modules enabled\n" 51 | 52 | if [[ $mountPoint == "/mnt/Systemd-Nvidia-Entry" ]]; then 53 | sudo umount $mountPoint 54 | fi -------------------------------------------------------------------------------- /config-optimus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if ! [ -d /opt/Systemd-Nvidia-Entry/ ]; then ## checks if the directory exist 3 | mkdir /opt/Systemd-Nvidia-Entry/ -p ## if it doesn't exist, here it's created 4 | fi 5 | 6 | modprobe bbswitch ## starting bbswitch 7 | 8 | if ! [[ `lsmod | grep nvidia` == "" ]]; then ## Nvidia 9 | tee /proc/acpi/bbswitch <<= 2: 9 | if sys.argv[1] == "install": 10 | print("Installing requirements for solus-prime-indicator") 11 | eopkg_pyqt5_install_return = subprocess.run(['sudo', 'eopkg', 'install', 'python3-qt5', 'make'], stdout=subprocess.PIPE, stdin=subprocess.PIPE) 12 | print(eopkg_pyqt5_install_return.stdout.decode('utf-8')) 13 | make_command_return = subprocess.run("cd solus-prime-indicator && make install", shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 14 | print(make_command_return.stdout.decode('utf-8')) 15 | 16 | elif sys.argv[1] == "remove": 17 | make_command_return = subprocess.run("cd solus-prime-indicator && make uninstall", shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 18 | print(make_command_return.stdout.decode('utf-8')) 19 | 20 | elif sys.argv[1] == "help": 21 | print("- install\n\tAllows you to install solus-prime-indicator") 22 | print("- remove\n\tRemove solus-prime-indicator") 23 | -------------------------------------------------------------------------------- /solus-prime-indicator/Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash # Use bash syntax 2 | 3 | install: 4 | @if [[ `whoami` == "root" ]]; then \ 5 | echo "No root!";\ 6 | exit 1;\ 7 | fi; \ 8 | 9 | @if ! [[ -d ~/.config/autostart/ ]]; then \ 10 | mkdir ~/.config/autostart/ ;\ 11 | fi; \ 12 | 13 | sudo cp trayicon.py /usr/bin/solus-prime-indicator 14 | cp solus-prime-indicator.desktop ~/.config/autostart/solus-prime-indicator.desktop 15 | sudo chmod +x /usr/bin/solus-prime-indicator 16 | 17 | uninstall: 18 | @if [[ `whoami` == "root" ]]; then \ 19 | echo "No root!";\ 20 | exit 1;\ 21 | fi; \ 22 | 23 | sudo rm -f /usr/bin/solus-prime-indicator 24 | rm -f ~/.config/autostart/solus-prime-indicator.desktop 25 | -------------------------------------------------------------------------------- /solus-prime-indicator/README.md: -------------------------------------------------------------------------------- 1 | # Solus-Prime-Indicator 2 | * It's started as a fork from [Grub-Nvidia-Entry](https://github.com/Superdanby/Grub-Nvidia-Entry) 3 | * **[Download here for Solus](https://github.com/MarechalLima/Systemd-Nvidia-Entry/releases/tag/v1-1)** 4 | 5 | ## Prerequisites 6 | * Nvidia driver 7 | * make 8 | * python3-qt5 9 | 10 | ## Supported Operating Systems 11 | * Solus 12 | 13 | ## Instructions 14 | * After installing Nvidia drivers, and rebooting... 15 | * Install with "make install". 16 | 17 | ## Caution 18 | ### DO NOT UPGRADE NVIDIA PACKAGE USING NOUVEAU 19 | * If you did: Ctrl + Alt + F2; After logging, type: sudo mv -f /etc/X11/xorg.conf.d/00-ldm.conf ~/.cache/MarechalLima/00-ldm.conf 20 | #### If you are updating your script, you should run 'make uninstall' before installing 21 | * /etc/X11/xorg.conf.d/00-ldm.conf is moved to ~/.cache/MarechalLima while using nouveau. MAKE A COPY FOR BACKUP! (the Makefile will create a copy at ~/.cache/00-ldm.conf.bkp) 22 | * /usr/lib/modprobe.d/nvidia.conf has 'blacklist' commented while using nouveau. 23 | 24 | ## Donation 25 | [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=nicholaslima%2erw%40gmail%2ecom&lc=US&item_name=Nicholas%20Lima%20de%20Souza%20Silva&item_number=MarechalLima¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) 26 | 27 | # Disclaimer 28 | * **USE AT YOUR OWN RISK** 29 | -------------------------------------------------------------------------------- /solus-prime-indicator/gpu-switch-nosudo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if ! [ -d /home/$1/.cache/MarechalLima/ ]; then ## checks if the directory exist 3 | mkdir /home/$1/.cache/MarechalLima/ ## if it doesn't exist, here it's created 4 | fi 5 | if ! [ -e /usr/lib/modprobe.d/optimus.conf ]; then ## checks if the file exist 6 | echo -e 'blacklist nvidia\nblacklist nvidia_drm\nblacklist nvidia_modeset\nblacklist nvidia_uvm' | tee /usr/lib/modprobe.d/optimus.conf ## if it doesn't exist, here it's created 7 | fi 8 | if [[ `lsmod | grep nouveau` == '' ]]; then 9 | if [[ `cat /usr/lib/modprobe.d/nvidia.conf | grep \#` == '' ]]; then 10 | mv -f /etc/X11/xorg.conf.d/00-ldm.conf /home/$1/.cache/MarechalLima/00-ldm.conf 11 | sed -i "s/blacklist/#blacklist/g" /usr/lib/modprobe.d/nvidia.conf 12 | sed -i "s/#blacklist/blacklist/g" /usr/lib/modprobe.d/optimus.conf 13 | echo "nouveau" 14 | else 15 | echo "nouveau!" 16 | fi 17 | else 18 | if ! [[ `cat /usr/lib/modprobe.d/nvidia.conf | grep \#` == '' ]]; then 19 | mv -f /home/$1/.cache/MarechalLima/00-ldm.conf /etc/X11/xorg.conf.d/00-ldm.conf 20 | sed -i "s/#blacklist/blacklist/g" /usr/lib/modprobe.d/nvidia.conf 21 | sed -i "s/blacklist/#blacklist/g" /usr/lib/modprobe.d/optimus.conf 22 | echo "nvidia" 23 | else 24 | echo "nvidia!" 25 | fi 26 | fi 27 | -------------------------------------------------------------------------------- /solus-prime-indicator/gpu-switch.policy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Run Gpu-Switch As Admin 6 | Authentication is required to run Gpu-Switch As Admin 7 | 8 | no 9 | no 10 | auth_admin_keep 11 | 12 | /usr/bin/gpu-switch 13 | TRUE 14 | 15 | 16 | -------------------------------------------------------------------------------- /solus-prime-indicator/intel.svg: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 31 | 33 | 57 | 62 | 67 | 75 | ® 80 | 81 | 82 | -------------------------------------------------------------------------------- /solus-prime-indicator/nvidia.svg: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 31 | 33 | 58 | 63 | 64 | -------------------------------------------------------------------------------- /solus-prime-indicator/solus-prime-indicator.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=solus-prime-indicator 3 | Exec=/usr/bin/solus-prime-indicator 4 | Terminal=false 5 | Type=Application 6 | Icon=dialog-information 7 | -------------------------------------------------------------------------------- /solus-prime-indicator/trayicon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | import os 5 | from PyQt5.QtWidgets import (QApplication, QSystemTrayIcon, QMenu) 6 | from PyQt5.QtGui import QIcon 7 | from subprocess import check_output, check_call 8 | 9 | class App: 10 | def __init__(self): 11 | # Create a Qt application 12 | self.app = QApplication(sys.argv) 13 | icon = None 14 | try: 15 | if 'nvidia' in str(check_output("lsmod")): 16 | icon = QIcon.fromTheme("prime-nvidia") 17 | else: 18 | icon = QIcon.fromTheme("prime-intel") 19 | except Exception as e: 20 | print(e) 21 | menu = QMenu() 22 | #Gpu-switch 23 | #switchAction = menu.addAction("Gpu-Switch") 24 | #switchAction.triggered.connect(self.switch) 25 | #Exit 26 | exitAction = menu.addAction("Exit") 27 | exitAction.triggered.connect(sys.exit) 28 | 29 | self.tray = QSystemTrayIcon() 30 | self.tray.setIcon(icon) 31 | self.tray.setContextMenu(menu) 32 | self.tray.show() 33 | 34 | def run(self): 35 | # Enter Qt application main loop 36 | self.app.exec_() 37 | sys.exit() 38 | 39 | # def switch(self): 40 | # try: 41 | # getUser = os.getenv('USER') 42 | # status = str(check_output(["pkexec", "/usr/bin/gpu-switch", getUser])) 43 | # status = status.replace("'", "") 44 | # status = status[:-2] 45 | # status = status[1:] 46 | 47 | # if status == "nouveau": 48 | # check_call(['notify-send', '-i', 'dialog-information', 'Nouveau, please reboot!']) 49 | # elif status == "nouveau!": 50 | # check_call(['notify-send', '-i', 'dialog-information', 'Already Nouveau, please reboot!']) 51 | # elif status == "nvidia": 52 | # check_call(['notify-send', '-i', 'nvidia', 'Nvidia, please reboot!']) 53 | # elif status == "nvidia!": 54 | # check_call(['notify-send', '-i', 'nvidia', 'Already Nvidia, please reboot!']) 55 | # check_call(["gnome-session-quit", "--reboot"]) 56 | # except Exception as e: 57 | # print(e) 58 | 59 | if __name__ == "__main__": 60 | app = App() 61 | app.run() 62 | -------------------------------------------------------------------------------- /systemd-nvidia-entry.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Systemd Nvidia Entry 3 | Before=graphical-session.target 4 | 5 | [Service] 6 | Type=idle 7 | ExecStart=/opt/Systemd-Nvidia-Entry/config-optimus.sh 8 | 9 | [Install] 10 | WantedBy=multi-user.target 11 | --------------------------------------------------------------------------------