Installing the NVIDIA drivers in Kali Linux

James White
May 28, 2018 · 6 min read

Getting the NVIDIA drivers working on notebooks with an Optimus GPU setup

Those pesky NVIDIA Linux drivers. I forgot how annoyingly difficult they can be to work with in Linux sometimes. Unfortunately, notebooks with the Optimus GPU setup are even more painful. Fortunately, there is a way to get the NVIDIA driver working in Kali Linux.

Note: This guide installs the NVIDIA driver and isn’t for dynamically switching between the two GPUs. It provides the NVIDIA drivers in order to use the functionality of the GPU for other things i.e. CUDA. If you want the dynamic switching functionality, you should look at the Bumblebee project.

As of this time of writing the only accurate guide on getting the NVIDIA drivers working on Optimus GPU notebooks is this guide on the Kali Linux forums:

This guide is based on the instructions above. Credit to TiGER511 on the Kali Linux forums.

You may have also seen the following documentation from the official Kali docs too:

DON’T FOLLOW THIS GUIDE. It isn’t for notebooks, it works, but only if you have a dedicated GPU (not Optimus). You’ll lose your desktop environment if you follow this, as you need additional configuration. Hopefully the Kali team will add a note on this document to prevent notebook users from falling into the trap!

Installing the NVIDIA drivers

This guide assumes you have an Optimus GPU laptop. Don’t follow it if you’re unsure.

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.

apt install linux-headers-$(uname -r)

This will automatically resolve the kernel headers package required for the kernel you are currently using.

Installing the NVIDIA drivers themselves is quite easy as the packages are available within Kali. You can get the absolute latest drivers from NVIDIA’s website using the .run file, but I’d rather have package management control it.

apt install nvidia-driver nvidia-xconfig

This will take some time and build the kernel modules required. During the install, you will likely get a note about the nouveau driver being active and installed. Dismiss this message, as we’ll be adding to the work the NVIDIA drivers do after for blacklisting.

As you’ll likely be using the nouveau driver (which is default on a vanilla Kali Linux install), we need to take some steps to first unload it, as it will conflict with the NVIDIA drivers. The NVIDIA driver install actually created a blacklist file, but you might need to add further parameters to it as shown below:


blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

You should then update the kernel with:

update-initramfs -u

If for whatever reason, nouveau still keeps loading even after blacklisting the crap out of pretty much every possible nouveau related config (trust me, I’ve been through them all), try adding nouveau.modeset=0 to your kernel boot line. This seemed to be the only way I could stop the nouveau driver loading on my notebook. (Dell XPS 9550).


Find the boot option you use i.e. “Persistence” or “Encrypted Persistence” on the “Linux” line, locate the boot= part and at the end add nouveau.modeset=0

You may find that the above file is read only. If you run update-initramfs -u , this will unlock it.

I don’t know the exact reason why the normal blacklisting isn’t working for me, but this seems to do the job. The only problem is if I update the live partition i.e. overwrite it with a newer weekly Kali image, that change is going to get overridden, but I’ll have to live with it for now. Hopefully the usual blacklisting stuff works for most people however.

You’ll now need to logout, as were going to test if the NVIDIA driver can load properly.

Testing the NVIDIA driver before rebooting

Logout of Kali and press Ctrl +Alt + F2, this will given you a console. Run

systemctl stop gdm

If you have modified Kali to use something other than GNOME3 as the desktop manager, then you’ll have to adjust this accordingly. i.e. lightdm etc.

Your screen may flicker or jump to another window temporarily, just press Ctrl + Alt + F2 if this happens to get back to the console session. You now want to unload nouveau so we can attempt to load the NVIDIA drivers.

rmmod nouveau

Check if the nouveau driver has actually unloaded with:

lsmod | grep -i nouveau

If you get nothing returned, it means its been unloaded.

Additional configuration for the NVIDIA driver

With the NVIDIA driver installed. Let’s now manually load it:

modprobe nvidia-drm

You should see some feedback from console regarding loading the NVIDIA drm module.

You’ll need a few configuration files for display and your desktop environment to work.


For the xorg.conf file, you will need to potentially adjust the BusID value as it will vary for different notebooks. You can find this out by running:

nvidia-xconfig --query-gpu-info | grep 'BusID : ' | cut -d ' ' -f6

Whatever value is reported, needs to be set as the BusID value in the xorg.conf config.


To make it easier, here’s a script that can download all these config files for you.

Grab the X11 xorg.conf file

wget -O /etc/X11/xorg.conf

Remember to change the BusID after installing.

Grab the GDM/XDG Autostart file:

wget -O /usr/share/gdm/greeter/autostart/optimus.desktop
cp /usr/share/gdm/greeter/autostart/optimus.desktop /etc/xdg/autostart/optimus.desktop

Now you can attempt to start your desktop manager

systemctl start gdm

Again, replace with the desktop manager you use if its not GNOME 3. If all is well, you should see the login screen again, with display now running under the NVIDIA driver.

You can now reboot, to make all of this permanent.

Optional: Installing the CUDA toolkit

For accelerated performance in certain workloads i.e. cracking, you can use your NVIDIA GPU if it supports CUDA. If you want to install CUDA, its pretty simple:

apt-get install ocl-icd-libopencl1 nvidia-cuda-toolkit

Tell NVIDIA how you feel about this process

Unfortunately, its not quite as simple as installing drivers and rebooting with NVIDIA. I always watch this video to make me happy when I’ve had to mess with NVIDIA drivers. Thanks, Linux Torvalds!

Yeah, NVIDIA…..

Troubleshooting: Help, I have no desktop any more!

If something is not working, there are a few likely suspects. Don’t worry, you should still be able to get a console session even if the desktop environment won’t load with Ctrl + Alt + F2.

  1. Have the NVIDIA kernel modules been loaded? I noticed on USB Persistence installs that despite updating to the latest kernel with apt , the live boot stays the same, hence you may be booting into an older kernel and the modules may not have been built for it. You can either, force an update of the older kernel image:
update-initramfs -u -k $(uname -r)

Or, update the live partition with the latest kernel from the Kali weekly image.

2. Make sure you’ve got the correct BusID for your GPU in the xorg.conf

3. Make sure that nouveau is indeed being unloaded, as it was a pain in the arse to stop it loading on my notebook. If you run lsmod | grep -i nouveau and get anything returned it means its still loaded and will be blocking the NVIDIA driver from taking control of the GPU and causing problems.

4. Reverting. If you still can’t get the NVIDIA drivers to work, following this process should get you back up and running under nouveau again:

apt-get remove --purge nvidia*
rm /etc/X11/xorg.conf
rm /usr/share/gdm/greeter/autostart/optimus.desktop
rm /etc/xdg/autostart/optimus.desktop

If you used the blacklist config that the NVIDIA installer generates to stop nouveau from loading, this is automatically removed. If you used your own, you’ll need to remove this as well.

If you had to add the additional line to the boot parameters on the kernel for nouveau, you’ll also need to undo this.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade