└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Installing-Nvidia-drivers-on-Kali-Linux 2 | 3 | 4 | After spending few days on how-tos and debugging the black screen issue on boot after insalling the nvidia drivers, I was finally able to find a solution to all my problems. 5 | The main reason I'm writing this post is to let you know that the tutorial found on [Kali's official website](https://docs.kali.org/general-use/install-nvidia-drivers-on-kali-linux) is broken as of date 11 April 2018. 6 | According to he mentioned in their website you might be able to successfully install the packages - ocl-icd-libopencl1, nvidia-driver, nvidia-cuda-toolkit 7 | but you might encounter issues during the reboot. You might get a black screen and won't be able to login via the GUI. 8 | 9 | ## So lets get started- 10 | First of all let me tell you the specifications of my system- 11 | 12 | CPU - Intel® Core™ i5-8250U CPU @ 1.60GHz × 8 13 | 14 | GPU #1- Intel® UHD Graphics 620 15 | 16 | GPU #2- Nvidia GeForce MX150 17 | 18 | ```shell 19 | root@europa:~# uname -a 20 | Linux europa 4.14.0-kali3-amd64 #1 SMP Debian 4.14.17-1kali1 (2018-02-16) x86_64 GNU/Linux 21 | ``` 22 | 23 | ```shell 24 | root@europa:~# cat /etc/*release* 25 | DISTRIB_ID=Kali 26 | DISTRIB_RELEASE=kali-rolling 27 | DISTRIB_CODENAME=kali-rolling 28 | DISTRIB_DESCRIPTION="Kali GNU/Linux Rolling" 29 | PRETTY_NAME="Kali GNU/Linux Rolling" 30 | NAME="Kali GNU/Linux" 31 | ID=kali 32 | VERSION="2018.1" 33 | VERSION_ID="2018.1" 34 | ID_LIKE=debian 35 | ANSI_COLOR="1;31" 36 | HOME_URL="http://www.kali.org/" 37 | SUPPORT_URL="http://forums.kali.org/" 38 | BUG_REPORT_URL="http://bugs.kali.org/" 39 | ``` 40 | 41 | Before we begin, a couple of notes: 42 | 43 | ***USE AT YOUR OWN RISK*** 44 | 45 | **This tutorial is for official NVIDIA Driver** 46 | 47 | **Tutorial found on official Kali website is BROKEN! It never works for optimus/hybrid Graphics enabled laptop** 48 | 49 | **Step 1:** Verify you have hybrid graphics 50 | 51 | ```shell 52 | root@europa:~# lspci | grep -E "VGA|3D" 53 | 00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07) 54 | 01:00.0 3D controller: NVIDIA Corporation GP108M [GeForce MX150] (rev a1) 55 | ``` 56 | 57 | **Step 2:** Disable nouveau 58 | 59 | ```shell 60 | echo -e "blacklist nouveau\noptions nouveau modeset=0\nalias nouveau off" > /etc/modprobe.d/blacklist-nouveau.conf 61 | update-initramfs -u && reboot 62 | ``` 63 | 64 | **Step 3:** System will reboot and nouveau should be disabled. Verify if nouveau is disabled: 65 | ```shell 66 | lsmod |grep -i nouveau 67 | ``` 68 | If shows nothing,means nouveau successfully disabled. 69 | 70 | **Step 4:** Install nvidia driver from kali repo: 71 | ```shell 72 | apt-get install nvidia-driver nvidia-xconfig 73 | ``` 74 | You can also download latest .run file from [Nvidia's website](http://www.nvidia.com/Download/index.aspx). Execute and procceed with installation. Whether its from Kali's repo or Nvidia's website, procedure is same. 75 | Code to install the .run file: 76 | ```shell 77 | sudo sh ./Nvidia-driver-filename.run 78 | ``` 79 | **Step 5:** Now we have to find bus id of our nvidia card: 80 | 81 | ```shell 82 | nvidia-xconfig --query-gpu-info | grep 'BusID : ' | cut -d ' ' -f6 83 | ``` 84 | it should show something like this: 85 | ```shell 86 | PCI:1:0:0 87 | ``` 88 | This is our Bus ID. 89 | 90 | **Step 6:** Now we generate /etc/X11/xorg.conf file with this bus ID according to [Nvidia's guide](http://us.download.nvidia.com/XFree86/Linux-x86/375.39/README/randr14.html): 91 | 92 | ``` 93 | Section "ServerLayout" 94 | Identifier "layout" 95 | Screen 0 "nvidia" 96 | Inactive "intel" 97 | EndSection 98 | 99 | Section "Device" 100 | Identifier "nvidia" 101 | Driver "nvidia" 102 | BusID "**PCI:1:0:0**" 103 | EndSection 104 | 105 | Section "Screen" 106 | Identifier "nvidia" 107 | Device "nvidia" 108 | Option "AllowEmptyInitialConfiguration" 109 | EndSection 110 | 111 | Section "Device" 112 | Identifier "intel" 113 | Driver "modesetting" 114 | EndSection 115 | 116 | Section "Screen" 117 | Identifier "intel" 118 | Device "intel" 119 | EndSection 120 | ``` 121 | Replace the string inside ** ** with your Bus ID and save it to /etc/X11/xorg.conf 122 | 123 | **Step 7:** Now we have to create some scripts according to our [display manager](https://wiki.archlinux.org/index.php/NVIDIA_Optimus#Display_Managers).Since im using default Kali linux which is GDM,i created two files: 124 | /usr/share/gdm/greeter/autostart/optimus.desktop 125 | /etc/xdg/autostart/optimus.desktop 126 | with the following content: 127 | 128 | ``` 129 | [Desktop Entry] 130 | Type=Application 131 | Name=Optimus 132 | Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto" 133 | NoDisplay=true 134 | X-GNOME-Autostart-Phase=DisplayServer 135 | ``` 136 | **Step 8:** Now reboot and you should be using Nvidia Driver. Verify if everything is ok: 137 | install mesa-utils if not previously installed. 138 | ```bash 139 | apt-get install mesa-utils 140 | ``` 141 | ```bash 142 | root@europa:~# glxinfo | grep -i "direct rendering" 143 | direct rendering: Yes 144 | ``` 145 | **Step 9:** Now you can install the cuda toolkits and drivers. The package nvidia-cuda-toolkit has been deprecated. You can install hashcat-nvidia package as an alternative. 146 | ```bash 147 | apt install -y ocl-icd-libopencl1 nvidia-driver hashcat-nvidia 148 | ``` 149 | **Step 10:** Now that our system should be ready to go, we need to verify the drivers have been loaded correctly. We can quickly verify this by running the [nvidia-smi](https://developer.nvidia.com/nvidia-system-management-interface) tool. 150 | ``` 151 | root@europa:~# nvidia-smi 152 | Wed Apr 11 11:08:55 2018 153 | +-----------------------------------------------------------------------------+ 154 | | NVIDIA-SMI 390.42 Driver Version: 390.42 | 155 | |-------------------------------+----------------------+----------------------+ 156 | | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | 157 | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | 158 | |===============================+======================+======================| 159 | | 0 GeForce MX150 Off | 00000000:01:00.0 Off | N/A | 160 | | N/A 60C P0 N/A / N/A | 368MiB / 2002MiB | 0% Default | 161 | +-------------------------------+----------------------+----------------------+ 162 | 163 | +-----------------------------------------------------------------------------+ 164 | | Processes: GPU Memory | 165 | | GPU PID Type Process name Usage | 166 | |=============================================================================| 167 | | 0 763 G /usr/lib/xorg/Xorg 20MiB | 168 | | 0 793 G /usr/bin/gnome-shell 19MiB | 169 | | 0 1108 G /usr/lib/xorg/Xorg 82MiB | 170 | | 0 1191 G /usr/bin/gnome-shell 242MiB | 171 | | 0 2132 G gnome-control-center 1MiB | 172 | +-----------------------------------------------------------------------------+ 173 | ``` 174 | 175 | ***FIXING SCREEN TEARING ISSUE:*** 176 | After you successfully boot up with Nvidia Driver, you most probably would be experiencing screen tearing issue eg: glitches while playing videos in VLC, Youtube videos on Chrome/Firefox etc. Luckily, we can fix this by enabling PRIME Sync. 177 | 178 | **1.** Verify if PRIME is disabled 179 | ```bash 180 | xrandr --verbose|grep PRIME 181 | ``` 182 | it should output something like this: 183 | ```bash 184 | PRIME Synchronization: 0 185 | PRIME Synchronization: 1 186 | ``` 187 | First one is our connected display.So PRIME sync is disabled. 188 | 189 | **2.** Edit **/etc/default/grub** and append **nvidia-drm.modeset=1** in **GRUB_CMDLINE_LINUX_DEFAULT** after quiet.Like the following: 190 | 191 | ```bash 192 | ... 193 | GRUB_CMDLINE_LINUX_DEFAULT="quiet nvidia-drm.modeset=1" 194 | ... 195 | ``` 196 | 197 | **3.** Save the changes and update grub using the command: 198 | ```bash 199 | update-grub 200 | ``` 201 | 202 | **4.** Reboot your system. 203 | 204 | **5.** Verify if PRIME is enabled: 205 | ```bash 206 | xrandr --verbose|grep PRIME 207 | ``` 208 | Now it should output: 209 | ```bash 210 | PRIME Synchronization: 1 211 | PRIME Synchronization: 1 212 | ``` 213 | 214 | If it still shows 0 for you,then there is probably something wrong with your system config/kernel. Since this is still an experimental feature from Nvidia,you are out of luck. 215 | 216 | ***IF YOU STUCK IN BOOT SCREEN*** 217 | 218 | Revert what we have done so far: 219 | 220 | Press CTRL+ALT+F2 or CTRL+ALT+F3, login with your password. 221 | ```bash 222 | apt-get remove --purge nvidia-* 223 | rm -rf /etc/X11/xorg.conf 224 | ``` 225 | Remove those display manager files we created earlier (for GDM): 226 | ```bash 227 | rm -rf /usr/share/gdm/greeter/autostart/optimus.desktop 228 | rm -rf /etc/xdg/autostart/optimus.desktop 229 | ``` 230 | Now reboot. You should be able get back to your old system. 231 | 232 | 233 | 234 | 235 | If any issues exist please post it in [Kali's forum](https://forums.kali.org/showthread.php?35748-TUTORIAL-Installing-official-NVIDIA-driver-in-Optimus-laptop). 236 | 237 | **My sincere thanks to [TiGER511](https://forums.kali.org/member.php?53670-TiGER511)** who did all the hard-work. 238 | 239 | **I'll soon update this repo on how to switch between your Intel Graphics and Nvidia Graphic card.** 240 | --------------------------------------------------------------------------------