FreeBSD with NVidia drivers

There have been various issues with FreeBSD-11.2 and later with the NVidia drivers. There is, at time of writing, no mention of this in /usr/ports/UPDATING. This was first written around the time of 11.2 so there may be some dated references, but the instructions still work with 12.x and 13.x.

This is taken from various posts on FreeBSD forums and my own experience.

Firstly, if upgrading from 11.1, remove the NVida drivers and any reference to them in /boot/loader.conf or rc.conf. We will reinstall them once the newer installation is in place. is in place.

Sometimes, the kernel gets updated and the package doesn't, in which case you may have to build from ports. When this was first written, around December, 2018, that was the case. At present, almost May, 2020 the package should work.

The Nvidia driver port requires having the kernel source code in place, so you must first install FreeBSD source code. This can be done with, assuming you have gitup installed and properly configured
gitup release

This will put the source code into /usr/src.

For instructions on using gitup, I have a small page covering simple use of git and gitup.

You must next figure out if your NVidia card uses the legacy nvidia-driver-340 or the regular nvidia-driver. You can find a (not necessarily THE) model of your card with pciconf -lv. This will give some sort of indication of what card you have, though it might not agree with NVidia's. Here is their listing of legacy cards. See if the model you get from pciconf matches or seems similar to one there. If so, you probably want to install the x11/nvidia-driver-340 driver. Regardless, install the driver from the port, using your favorite ports management tool. With portmaster (assuming you are installing the latest driver)
portmaster x11/nvidia-driver

If using pkg, then
pkg install -y nvidia-driver

If you have a really old NVidia card, you may even need the nvidia-driver-304.

Once the port is installed, you can view the pkg-msg with
pkg info -D nvidia-driver

This will tell you to add, if it's the newer nvidia driver nvidia-modeset_load="YES"

to /boot/loader.conf. If it's the legacy driver, then add nvidia_load="YES" to loader.conf. You can, if you prefer, add

or, for the legacy, kld_list="nvidia" to /etc/rc.conf

The pkg info says that linux_enable="YES" in rc.conf is needed, but I've found, if not using any Linux applications, that that's not necessary. Depending upon your use case, you may be using some other Linux applications though, and it doesn't seem to add much overhead.

Lately I've been doing it with sysrc. The commands are
sysrc -f /boot/loader.conf nvidia-modset_load="YES"

for /boot/loader.conf, or
sysrc kld_list+=nvidia-modeset

if you prefer to put it in for /etc/rc.conf.

It is usually necessary to create a /usr/local/etc/X11/xorg.conf.d file. In there make a file. Its name must end with .conf but otherwise, any name you choose is fine. Putting 00 at the start of the name means that it will be read before any other files, such as synaptic settings, that you might add to the directory later. So, create, for example, 00nvidia.conf which should read
Section "Device"
        Identifier "NVIDIA Card"
        VendorName "NVIDIA Corporation"
        Driver "nvidia"

After this, especially if added to /boot/loader.conf, you may need to reboot to load the module. (This can probably be skipped, but as I've only used the Nvidia on workstations, not servers, I've never bothered checking. You can first try with kldload nvidia-modeset)

. At this point if it still fails, saying no screens found, I've usually been able to fix it by installing the nvidia-xconfig package (this can be installed with pkg install) and then running nvidia-xconfig. This will create a /etc/X11/xorg.conf file that should work with your NVidia card. You can probably remove large portions of it, but I've not experimented.

The only other issue I ever ran into was on only one of about 4 machines. X still wouldn't start and in that case, it turned out that the nvidia-xconfig hadn't created a BusID entry in the xorg.conf file, and this particular machine (though not some others) required it for X to start.

I was able to get the BusID entry from starting X, and then, even though it failed, looking at the /var/log/Xorg.0.log. You can also get it from pciconf -lv. It will show something like

above the listing. In this case, you want an entry of
BusID    "PCI:1:0:0"

In other words, leave off the first 0 and last colon.

At present, May, 2021, these are the steps necessary to get an NVidia card running on FreeBSD-X.X-RELEASE, from 11.x-13.0

One may also want to do something with console resolution. For example, my default console font is rather large. I was able to change this by first adding

to /boot/loader.conf. I was then able to use the vidcontrol command to change the mode. First run the command with -i, as in information mode.
vidcontrol -i mode

This will give you a variet of modes that your system can use. For example my system shows several modes including
276 (0x114) 0x0000001f G 800x600x16 D    8x16  0xa0000 64k 64k 0xf1000000 937k
277 (0x115) 0x0000001f G 800x600x32 D    8x16  0xa0000 64k 64k 0xf1000000 1875k
279 (0x117) 0x0000001f G 1024x768x16 D   8x16  0xa0000 64k 64k 0xf1000000 1536k
280 (0x118) 0x0000001f G 1024x768x32 D   8x16  0xa0000 64k 64k 0xf1000000 3072k
282 (0x11a) 0x0000001f G 1280x1024x16 D  8x16  0xa0000 64k 64k 0xf1000000 2560k
283 (0x11b) 0x0000001f G 1280x1024x32 D  8x16  0xa0000 64k 64k 0xf1000000 5120k

Suppose I want to use the 1280x1204x16 mode, I use the number that is in the first column, with the vidcontrol command.
vidcontrol MODE_283

If I decide that I like that resolution, I can make it permanent and have it apply to all consoles by adding this line to /etc/rc.conf

This gives me better resolution when working in console.