Installing NVIDIA drivers on Linux is always difficult. This is the step by step guide for installing NVIDIA drivers on Kali Linux. I used these steps to install my NVIDIA GTX1050Ti drivers on Kali Linux. This process is tested on Kali Linux 2020.2 Gnome 64-Bit.
Step 1: Install Kali Linux on the hard drive and restart your computer after the installation process completes. If you are able to boot and log in to the kali linux system then skip step 2. Step 2 is applicable when you can’t log in to the system because it’s halting. I could to log in to Kali Linux 2020.2 Gnome 64-Bit without any problem, so I skipped step 2.
After logging in to Kali Linux system, you need to have root access to install the Nvidia driver. To do that type “sudo su” (without quotation mark) in the terminal and enter the password of your kali user account. Now type “passwd root” in the terminal, then enter the new password for the root user and retype that password again.
Now type sudo nano /etc/pam.d/gdm-password and you will see something like this:
#%PAM-1.0 auth requisite pam_nologin.so auth required pam_succeed_if.so user != root quiet_success @include common-auth auth optional pam_gnome_keyring.so @include common-account # SELinux needs to be the first session rule. This ensures that any # lingering context has been cleared. Without this it is possible # that a module could execute code in the wrong domain. session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close session required pam_loginuid.so # SELinux needs to intervene at login time to ensure that the process # starts in the proper default security context. Only sessions which are # intended to run in the user's context should be run after this. # pam_selinux.so changes the SELinux context of the used TTY and configures # SELinux in order to transition to the user context with the next execve() # call. session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open session optional pam_keyinit.so force revoke session required pam_limits.so session required pam_env.so readenv=1 session required pam_env.so readenv=1 envfile=/etc/default/locale @include common-session session optional pam_gnome_keyring.so auto_start @include common-password
Add # in the beginning of 3rd line, like this #auth required pam_succeed_if.so user != root quiet_success and keep rest of the things unchanged. Then press Ctrl + O to save the changes. Restart computer and log in with root user.
Setp 2: Now you will see the Kali Linux Grub Bootloader with a blue screen. From the GRUB loader select Kali Linux and press E. Now navigate the cursor to the row starting with Linux, then at the end of the row replace “quiet splash” with “nouveau.modeset=0” (without quote marks). Then press F10. These steps will fix boot loading and freezing issue in Kali Linux. Now Kali Linux will boot normally. Instructions with image is shown below.
From the GRUB loader select Kali Linux and press E.
Now navigate the cursor to the row starting with Linux, then at the end of the row replace “quiet splash” with “nouveau.modeset=0” (without quote marks).
Then press F10.
Step 3: After Kali Linux booted up run this command below.
apt-get update apt-get upgrade apt-get dist-upgrade
After that follow the steps below to install Nvidia drivers:
Step 4: Before we begin, you’ll need to make sure you have the kernel headers for your currently active kernel, in order to build the NVIDIA driver kernel modules type:
apt install linux-headers-$(uname -r)
This will automatically resolve the kernel headers package required for the kernel you are currently using.
Step 5: Disable nouveau
echo -e "blacklist nouveau\noptions nouveau modeset=0\nalias nouveau off" > /etc/modprobe.d/blacklist-nouveau.conf update-initramfs -u && reboot
Now system will reboot and nouveau should be disabled.
Step 6: Verify if nouveau is disabled:
lsmod |grep -i nouveau
If this command shows nothing, that means nouveau has successfully disabled.
Step 7: Install Nvidia driver from kali repository:
apt-get install nvidia-driver nvidia-xconfig
Step 8: Find the bus id of Nvidia card:
nvidia-xconfig --query-gpu-info | grep 'BusID : ' | cut -d ' ' -f6
>>My result: PCI:1:0:0
>>PCI:1:0:0 This is our Bus ID.
Step 9: Now we will create /etc/X11/xorg.conf file with this bus ID according to the Nvidia’s guide.
You can download the xorg.conf file from here and edit the BusID value with your Bus ID using any text editor. Then keep the xorg.conf file in /etc/X11/
Or you can make a xorg.conf file using the text below.
Section "ServerLayout" Identifier "layout" Screen 0 "nvidia" Inactive "intel" EndSection Section "Device" Identifier "nvidia" Driver "nvidia" BusID "PCI:1:0:0" EndSection Section "Screen" Identifier "nvidia" Device "nvidia" Option "AllowEmptyInitialConfiguration" EndSection Section "Device" Identifier "intel" Driver "modesetting" EndSection Section "Screen" Identifier "intel" Device "intel" EndSection
>>Replace the BusID value with your Bus ID and save it to /etc/X11/xorg.conf
Step 10: Now we have to create some scripts according to our display manager. Since I’m using default Kali Linux display manager which is GDM, thus I created two optimus.desktop files in directory mentioned below
/usr/share/gdm/greeter/autostart/optimus.desktop
/etc/xdg/autostart/optimus.desktop
with the following content:
[Desktop Entry] Type=Application Name=Optimus Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto" NoDisplay=true X-GNOME-Autostart-Phase=DisplayServer
You can also download the optimus.desktop file for GDM and copy that to both directory /usr/share/gdm/greeter/autostart/ and /etc/xdg/autostart/
Step 11: Now reboot your computer and you should be using Nvidia Driver. Verify if everything is working perfectly by using the command below:
apt-get install mesa-utils glxinfo | grep -i "direct rendering"
>>Result Should be “direct rendering: Yes”
If the Nvidia driver is installed successfully, then your graphics card name will be displayed in the Kali Linux’s about section.
Installing Nvidia CUDA Toolkit:
apt-get install ocl-icd-libopencl1 nvidia-cuda-toolkit
Hashcat-nvidia package:
apt install -y ocl-icd-libopencl1 nvidia-driver hashcat-nvidia
Verify Driver Installation:
nvidia-smi
Querying GPU Information:
nvidia-smi -i 0 -q
Installing Hashcat and verifying CUDA is working with hashcat:
sudo apt install -y hashcat hashcat -I
Hashcat GPU benchmarking:
hashcat -b | uniq
Follow these steps if you made mistakes and stuck in the boot screen, and now you want to uninstall Nvidia driver and revert all of the work you’ve done so far:
Press CTRL+ALT+F2 or CTRL+ALT+F3, login with your password.
apt-get remove --purge nvidia-* rm -rf /etc/X11/xorg.conf rm -rf /usr/share/gdm/greeter/autostart/optimus.desktop rm -rf /etc/xdg/autostart/optimus.desktop
Subscribe To Our Newsletter
Join our mailing list to receive the latest news and updates from our team.
You have Successfully Subscribed!