Installing Nvidia driver from source on Kali Linux 2.0


Following the official documentation for installing Nvidia driver on Kali 2.0 didn’t work for me. I installed nvidia-kernel-dkms, disabled nouveau driver, and rebooted. Then I had an error saying Something went wrong.. and presented with only a logout button. I was unable to login to the graphical interface. So I dug every bit of information in the internet and finally installed NVIDIA driver (361.28) on Kali (kernel 4.0.0).

Preparation

First, download the driver for your GPU. To know which driver to download, run lspci | grep -E "VGA|3D" command. It will show the GPU you currently have. Mine is GeForce GT 740M. Then look for the appropriate driver for your GPU at Nvidia website. Here are the archives for 64 bit and 32 bit system. After downloading the driver, place it somewhere in your home folder – we will be needing it later. Make it executable chmod +x ~/Downloads/NVIDIAxxxx.run.

Next, install the linux headers:

  • apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
  • aptitude -r install linux-headers-$(uname -r) Where -r means install all recommended packages as well.

 

If you have installed nvidia-kernel-dkms earlier, remove it and all nvidia packages by apt-get remove nvidia* --purge.

Disable nouveau driver

Create a file /etc/modprobe.d/nvidia-installer-disable-nouveau.conf and paste the following lines:

blacklist nouveau
options nouveau modeset=0
options nouveau.modeset=0

 Stop X server

We need to stop the X server so we can run the Nvidia installer. Kali2.0 uses gdm by default. You can stop the X server by stopping gdm systemctl stop gdm. Another way is to hit Ctrl+Alt+Backspace. You can also try the methods suggestedhere in case previous methods don’t work.

If nothing works then just restart. As you have already disabled nouveau, your kernel won;t be able to load X server or the nouveau driver.

Backup your xorg.conf file (optional)

cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup

Chances are, there won’t be any file to backup.

Install Nvidia Driver

Now, cd into the directory where the installer is located. Then run the installer ./NVIDIAxxxx.run -a. Just accept whatever the installer asks. For 64 bit systems, you might encounter a question about 32bit libs, just ignore it.

After the installation completes, we need to disable the nouveau driver and configure the X server.

Configure X server

(From the Arch wiki )

Then, configure xorg.conf. You will need to know the PCI address of the NVIDIA card, which you can find by issuing lspci | grep -E "VGA|3D". The PCI address is the first 7 characters of the line that mentions NVIDIA. It will look something like01:00.0. In the xorg.conf, you will need to format it as #:#:#; e.g. 01:00.0 would be formatted as 1:0:0.

In my case, the bus id for my GPU was 04:00.0.

Now, you can take the backup of the conf file created while installing Nvidia driver but it is 100% useless and will not work.

Edit/create the file /etc/X11/xorg.conf and add the following lines after removing any other text that is there in that file.

Section "Module"
    Load "modesetting"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "4:0:0"
    Option "AllowEmptyInitialConfiguration"
EndSection

Then create a file /usr/share/gdm/greeter/autostart/display_setup.desktop and paste the following lines:

[Desktop Entry]
Type=Application
Name=Display setup
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-AutoRestart=true

Reboot and you should be good to go.

Sources