# HOWTO: Install and configure NVIDIA drivers



## tangram (Mar 26, 2009)

FreeBSD's Ports collection contains the official NVIDIA binary drivers for hardware OpenGL rendering in X, using the GLX extensions.The x11/nvidia-driver points to NVIDIA's latest stable driver set.

If you are using a legacy card check NVIDIA's site to see which driver set supports your card and browse the Ports tree for the suitable driver version and install that instead. Do notice that there aren't any 64bit NVIDIA drivers for FreeBSD.

Bellow are the steps needed to install NVIDIA drivers on i386 FreeBSD:


```
% su
# portsnap fetch update
# cd /usr/ports/x11/nvidia-drivers
# make config
# make install clean
# echo 'nvidia_load="YES"' >> /boot/loader.conf
# echo 'linux_enable="YES"' >> /etc/rc.conf
# echo 'hint.agp.0.disabled="1"' >> /boot/device.hints
```
Basically start by updating your ports tree, installing the driver and preparing FreeBSD to load the NVIDIA kernel module it at boot time. Consider selecting ACPI (enable support for ACPI Power Management) and LINUX (build with support for Linux compatibility) port options.

Now let's proceed by editing _/etc/X11/xorg.conf_ to have it use the NVIDIA driver and add some options to increase performance.

Edit _/etc/X11/xorg.conf_ and change the driver value from _"nv"_ to _"nvidia"_:


```
Driver "nvidia"
```

If your graphics card is AGP, additional performance options can be enabled, however these might affect stability. To enable Side Band Addressing and Fast Writes add the following sysctls to _/etc/sysctl.conf_:


```
# echo "hw.nvidia.registry.EnableAGPSBA=1" >> /etc/sysctl.conf
# echo "hw.nvidia.registry.EnableAGPFW=1" >> /etc/sysctl.conf
```
Finally:


```
# reboot
```

Additional ports of interest when configuring X with NVIDIA:

```
x11/nvidia-settings
x11/nvidia-xconfig
```

Possible workaround for crashes and blank screen problems:

```
# echo 'machdep.disable_mtrrs="1"' >> /boot/loader.conf
```

Further reading material can be found under:
http://www.freebsd.org/doc/en/books/handbook/x11.html
/usr/local/share/doc/NVDIA_GLX-1.0/


----------



## SirDice (Mar 26, 2009)

If you don't use any linux programs you can compile the driver without linux support. Then you also don't need to add the linuxilator.


----------



## tangram (Mar 26, 2009)

Yup. 

The port's default option is off to LINUX. However gamers running stuff like Enemy Territory, RTCW and UT will appreciate the option and should enable it.


----------



## SirDice (Mar 26, 2009)

Absolutely.. Also the linux-flashplugin needs it (which is currently the only reason why I have linux enabled).


----------



## DutchDaemon (Mar 26, 2009)

Don't forget these very helpful ports:


```
x11/nvidia-settings       Display Control Panel for X NVidia driver
x11/nvidia-xconfig        Tool to manipulate X configuration files for the NVidia driver
```


----------



## tangram (Mar 26, 2009)

DutchDaemon said:
			
		

> Don't forget these very helpful ports:
> 
> 
> ```
> ...



Added them to the post


----------



## jb_fvwm2 (Mar 27, 2009)

well, using NVIDIA I always got "agp detected, aborting setup!"
...........
Unfortunately, 
using the guide above (I think),  a blank screen, sometimes with a cursor.
one cntl-alt-del and other numerous keys-- to reboot and copy the old
xorg.conf back and comment device.hints, another cntl-alt-del to reboot
after the latter caused the blank screen to recur.  Now back the
way it was. (3 ideas of what is wrong here but I can only guess)
...........
4 permutations of ways to install nvidia-drivers and 100 permutations
of ways to tweak xorg.conf, maybe in a decade there will be a way to
set it up in 20 minutes or so.  Happy as long as I have the browser,
cursor, and window manager running...


----------



## SirDice (Mar 27, 2009)

jb_fvwm2 said:
			
		

> well, using NVIDIA I always got "agp detected, aborting setup!"


You can try removing *device agp* from your kernel config or add *hint.agp.0.disabled="1"* to /boot/device.hints.


----------



## jb_fvwm2 (Mar 27, 2009)

SirDice said:
			
		

> You can try removing *device agp* from your kernel config or add *hint.agp.0.disabled="1"* to /boot/device.hints.



The latter is one of the six or so modifications listed earlier
than my post, which when all are implemented, crash X on this
setup.  Even if it is not nvidia-driver, the xorg.conf, or
the .hints, (guessing!) it may be an unknown overclock of the video
card, or CRT rather than LCD, or...


----------



## SirDice (Mar 27, 2009)

To be honest, I can't make heads or tails of your posts.


----------



## tangram (Mar 27, 2009)

jb_fvwm2 said:
			
		

> The latter is one of the six or so modifications listed earlier
> than my post, which when all are implemented, crash X on this
> setup.  Even if it is not nvidia-driver, the xorg.conf, or
> the .hints, (guessing!) it may be an unknown overclock of the video
> card, or CRT rather than LCD, or...



The purpose of this corner of the forum is presenting HowTos and FAQs. I think you'd more easily solve your problems/issues in the appropriate forum support section, in this case Desktop -> X.Org.

You need to be more verbose on what is the problem, the steps you've taken so far and post helpful stuff like error messages, logs and configuration files.


----------



## jb_fvwm2 (Mar 27, 2009)

Sorry.  If you reread my post earlier, you can read
that I *maybe* could solve it, but am happy the way things are...
lack of time as always.


----------



## Carpetsmoker (Mar 28, 2009)

Copy of my post at DF:

I checked what your configuration tweaks do, and they don't seem to be very useful:



			
				tangram said:
			
		

> Option "RenderAccel" "True"



According to the nVidia documentation:


```
Option "RenderAccel" "boolean"

    Enable or disable hardware acceleration of the RENDER extension. Default:
    hardware acceleration of the RENDER extension is enabled.
```




			
				tangram said:
			
		

> Option "NoRenderExtension" "boolean"



As I understand it, this option is not needed, and is useful mostly for disableing the RENDER extension, not for explicitly enabling it (It is always enabled if the X server supports it), from the nVidia documentation:


```
Option "NoRenderExtension" "boolean"
    Disable the RENDER extension. Other than recompiling it, the X server does
    not seem to have another way of disabling this. Fortunately, we can
    control this from the driver so we export this option. This is useful in
    depth 8 where RENDER would normally steal most of the default colormap.
    Default: RENDER is offered when possible.
```




			
				tangram said:
			
		

> Option "NoFlip" "False"



Again, as I understand it this option is always enabled if supported, from the nVidia documentation:


```
Option "NoFlip" "boolean"

    Disable OpenGL flipping]

   o Flipping: When OpenGL flipping is enabled, OpenGL can perform buffer
     swaps by changing which buffer the DAC scans out rather than copying the
     back buffer contents to the front buffer; this is generally a much higher
     performance mechanism and allows tearless swapping during the vertical
     retrace (when __GL_SYNC_TO_VBLANK is set). The conditions under which
     OpenGL can flip are slightly complicated, but in general: on GeForce or
     newer hardware, OpenGL can flip when a single full screen unobscured
     OpenGL application is running, and __GL_SYNC_TO_VBLANK is enabled.
     Additionally, OpenGL can flip on Quadro hardware even when an OpenGL
     window is partially obscured or not full screen or __GL_SYNC_TO_VBLANK is
     not enabled.
```




			
				tangram said:
			
		

> Option "UseEdid" "True"



Enabled by default, no reason to set it, from the nVidia documentation:


```
Option "UseEDID" "boolean"

    By default, the NVIDIA X driver makes use of a display device's EDID, when
    available, during construction of its mode pool. The EDID is used as a
    source for possible modes, for valid frequency ranges, and for collecting
    data on the physical dimensions of the display device for computing the
    DPI (see Appendix I). However, if you wish to disable the driver's use of
    the EDID, you can set this option to False:
    
        Option "UseEDID" "FALSE"
    
    Note that, rather than globally disable all uses of the EDID, you can
    individually disable each particular use of the EDID]


[quote="tangram"]Option "NvAGP" "1"[/quote]

Again, this is the default, nVidia documentation:

[code]When built with support for the FreeBSD AGP driver, 'nvidia.ko' will fall back
to using NvAGP when it doesn't detect 'agp.ko' (this will be the case when
'agp.ko' does not support your AGP chipset or was explicitly disabled with
device hints).
```


----------



## lillis (Mar 29, 2009)

If anyone is having problems with a blank screen and computer hanging on startup, check this thread.
http://forums.freebsd.org/showthread.php?t=3065


----------



## tangram (Mar 30, 2009)

lillis said:
			
		

> If anyone is having problems with a blank screen and computer hanging on startup, check this thread.
> http://forums.freebsd.org/showthread.php?t=3065



Glad you've solved your problem


----------



## tangram (Mar 30, 2009)

@ Carpetsmoker, thanks for the input.

Yeah those are default settings. I just figured they were important enough to have on xorg.conf as remainder not to change them.


----------



## gr1ml0ck (Jun 30, 2009)

*I'm a bit of a noob but....*



			
				tangram said:
			
		

> Possible workaround for crashes and blank screen problems:
> 
> ```
> # echo 'machdep.disable_mtrrs="1"' >> /etc/boot/loader.conf
> ```



Should this not be:


```
# echo 'machdep.disable_mtrrs=1' >> /etc/boot/loader.conf
```

without the quotes?

Didn't work for me until I removed them.

Just in case anyone else is still getting those mtrr errors


----------



## tangram (Jun 30, 2009)

If you want your loader.conf to contain

```
machdep.disable_mtrrx="1"
```

either edit the file and add it or use `# echo 'machdep.disable_mtrrs="1"' >> /boot/loader.conf`.

If you `# echo 'machdep.disable_mtrrs=1' >> /boot/loader.conf` then your /boot/loader.conf will contain:

```
machdep.disable_mtrrs=1
```

In the how to I suggested the quotes for consistency sake.


----------



## dennylin93 (Jul 4, 2009)

tangram said:
			
		

> Possible workaround for crashes and blank screen problems:
> 
> ```
> # echo 'machdep.disable_mtrrs="1"' >> /etc/boot/loader.conf
> ```



Shouldn't it be /boot/loader.conf?


----------



## tangram (Jul 6, 2009)

Yup. Fixed it.


----------



## ale (Jul 6, 2009)

For nvidia-driver users who want to play linux-games with a linux_base > fc4, the solution is in [post=31198]this post[/post].
The solution should be temporary as nvidia is aware of the problem and it should be fixed in future releases of the driver.


----------



## meine (Sep 25, 2018)

My main box has an Nvidia card in it and this afternoon I finally got it working!

`# pkg install xf86-video-nv` --- this is a different driver than the nvidia-driver-304 and alike. With the xf86 driver in my case it doesn't need to know the exact type of the card.

make /usr/local/etc/X11/xorg.conf.d/driver-nv.conf with following content:


```
Section "Device"
      Identifier "Card0"
      Driver     "nv"
 EndSection
```

and your display should work using the more basic Nvidia driver -- see https://lwn.net/Articles/380704/ on this driver.

Maybe not suitable for gaming or heavy graphical stuff (I didn't try), but your display is nice and smooth!


----------



## Lucky (Jul 12, 2020)

A few years back, I had problems getting a kde desktop to work on my laptop with the nvidia 1050 card in it. Thought I'd put this up for anyone that may be having the same grief I once had. I'll turn it into a script eventually
https://github.com/luckyonshu/freebsdkde


----------

