Xorg and video drivers on FreeBSD

In this tutorial, we will install and set up Xorg and the appropriate graphics drivers.


Xorg

We add our user to the "video" group to allow access to the DRI:

root: pw groupmod video -m $USERNAME

Then we install the packages xorg and xscreensaver:

root: pkg install xorg xscreensaver

FreeBSD as a guest on the Virtualbox

If we want to use FreeBSD under VirtualBox, we need the package virtualbox-ose-additions so that we can adjust the resolution automatically.

root: pkg install virtualbox-ose-additions

Then we enter the following in /etc/rc.conf.

root: nano /etc/rc.conf =>

vboxguest_enable="YES"
vboxservice_enable="YES"
vboxservice_flags="- disable-timesync"

Video DRM Drivers (Intel, AMD, ATI)

For FreeBSD 12.0, we can use the package drm-fbsd12.0-kmod or for FreeBSD 13 drm-fbsd13-kmod can be used:

#FreeBSD 12
root: pkg install drm-fbsd12.0-kmod

#FreeBSD 13
root: pkg install drm-fbsd13-kmod 

For amdgpu: sysrc kld_list+="amdgpu"
For Intel: sysrc kld_list+="i915kms"
For radeonkms: sysrc kld_list+="radeonkms"

Old drivers

If the new DRM drivers cause problems, we can also use the old drivers.

Intel

root: pkg install xf86-video-intel
root: sysrc kld_list+="i915kms"

Radeon Graphic

root: sysrc kld_list+="radeonkms"

Video acceleration for Intel graphics cards

For Intel graphics cards, there is a VA-API driver (Video Acceleration API) for video acceleration. We installed the package libva-intel-driver with this command:

root: pkg install libva-intel-driver

Then we test that it works: and most importantly, we also test the suspend/resume.

For Intel Sandybridge card (or better) users, enabling SNA mode may be beneficial (we check this by measuring the difference with gtkperf, for example).

To activate this mode, an example configuration:

root: nano /usr/local/etc/X11/xorg.conf.d/20-video.conf =>

Section "Device"
    Identifier "Intel Graphics"
    Driver "modesetting"
    Option "AccelMethod" "sna"
    Option "TearFree" "true"
EndSection

X11 video driver for Nvidia

For Nvidia drivers there are several drivers depending on the generation of the graphics card (nvidia-driver-304, nvidia-driver-340, nvidia-driver-390, nvidia-driver).

So that we know which GPU is supported by which version, we simply look at the nvidia website.

For a current GPU, we install the nvidia-driver package as follows:

root: pkg install nvidia-driver

root: echo 'nvidia_load="YES"' >> /boot/loader.conf

root: mkdir -p /usr/local/etc/X11/xorg.conf.d/

root: nano /usr/local/etc/X11/xorg.conf.d/20-video.conf =>

Section "Device"
    Identifier "NVIDIA Card"
    VendorName "NVIDIA Corporation"
    Driver "nvidia"
EndSection

If there is more than one graphics card in our notebook, the BusID entry can be used to select the desired card. We can get a list of the BusIDs of the graphics cards with pciconf -lv | grep -B3 display.

root: nano /usr/local/etc/X11/xorg.conf.d/20-video.conf =>

Section "Device"
    Identifier "NVIDIA Card"
    VendorName "NVIDIA Corporation"
    Driver "nvidia"
    BusID "PCI:1:0:0"
EndSection

System Console Frame Buffer (SCFB)

If an accelerated graphics driver is not available for our FreeBSD system, we can use the scfb driver as an alternative. First we install the package xf86-video-scfb:

root: pkg install xf86-video-scfb

Then we create the file /usr/local/etc/X11/xorg.conf.d/driver-scfb.conf with the following content:

root: nano /usr/local/etc/X11/xorg.conf.d/driver-scfb.conf =>

Section "Device"
    Identifier    "Card0"
    Driver        "scfb"
EndSection

dbus (for Gnome / KDE)

We configure the automatic start of dbus:

root: sysrc dbus_enable=YES

And we start these services:

root: service dbus start

By default, FreeBSD does not load procfs or fdesc. But for some applications, these are required. We edit the file /etc/fstab and add these two lines:

root: nano /etc/fstab =>

proc    /proc        procfs     rw,late        0    0
fdesc   /dev/fd      fdescfs    rw,late        0    0

root: mount /proc
root: mount /dev/fd/

Polkit

Regarding software that Polkit uses (e.g. xfce), we can specify as follows that the user can shut down the computer and put the user in the "operator" group into hibernation.

```bash
root: nano /usr/local/etc/polkit-1/rules.d/51.shutdown.rules =>

polkit.addRule(function (action, subject) {
    if ((action.id == "org.freedesktop.consolekit.system.restart" || action.id == "org.freedesktop.consolekit.system.stop") && subject.isInGroup("operator")) {
        return polkit.Result.YES;         
    }
});
 
  
  
root: nano /usr/local/etc/polkit-1/rules.d/52.resume.rules =>
  
polkit.addRule(function (action, subject) {
    if (action.id == "org.freedesktop.consolekit.system.suspend" && subject.isInGroup("operator")) {
        return polkit.Result.YES;
    }
});

root: chown -R polkitd /usr/local/etc/polkit-1/

Then we will correct a missing permission problem regarding the actions. We should notice the following errors in the /var/log/messages:

Jul 18 00:21:28 x220 dbus [20382]: [system] Rejected send message, 2 matched rules; type = "method_call", sender = ": 1.19" (uid = 1001 pid = 63293 comm = "") interface = "org.freedesktop.ConsoleKit.Manager" member = "CanSuspend" error name = "(unset)" requested_reply = "0" destination = ": 1.1" (uid = 0 pid = 44489 comm = "")

Jul 18 00:21:28 x220 dbus [20382]: [system] Rejected send message, 2 matched rules; type = "method_call", sender = ": 1.19" (uid = 1001 pid = 63293 comm = "") interface = "org.freedesktop.ConsoleKit.Manager" member = "CanHibernate" error name = "(unset)" requested_reply = "0" destination = ": 1.1" (uid = 0 pid = 44489 comm = "")

To solve this problem (and unlock the “Standby” and “Hibernate” actions) from, e.g. B, to fix XFCE we have to edit the file /usr/local/etc/dbus-1/system.d/ConsoleKit.conf, and add these 6 lines after the last deny line:

root: nano /usr/local/etc/dbus-1/system.d/ConsoleKit.conf =>

<deny send_destination = "org.freedesktop.ConsoleKit"
     send_interface = "org.freedesktop.DBus.Properties" />
<allow send_destination = "org.freedesktop.ConsoleKit"
      send_interface = "org.freedesktop.ConsoleKit.Manager"
      send_member = "CanSuspend" />
<allow send_destination = "org.freedesktop.ConsoleKit"
      send_interface = "org.freedesktop.ConsoleKit.Manager"
      send_member = "CanHibernate" />
<allow send_destination = "org.freedesktop.ConsoleKit"
      send_interface = "org.freedesktop.ConsoleKit.Manager"
      send_member = "Restart" />

fonts

We install the following pretty fonts:

root: pkg install dejavu urwfonts bitstream-vera webfonts terminus-font hack-font

We then check what is taken into account in Xorg by this command:

root: fc-list

UDEV

As of FreeBSD 12.1, udev has been used to automatically configure input devices.

First, we install the following packages: libinput and xf86-input-libinput:

root: pkg install libinput xf86-input-libinput

We will now create the following configuration file:

root: nano /usr/local/etc/X11/xorg.conf.d/99-myinput.conf =>

Section "InputClass"
    Identifier "libinput keyboard catchall"
    MatchIsKeyboard "on"
    MatchDevicePath "/dev/input/event*"
    Driver "libinput"
    Option "XkbRules" "evdev"
EndSection

Section "InputClass"
    Identifier "libinput touchpad catchall"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/event*"
    Driver "libinput"
    Option "MiddleEmulation" "on"
    Option "Tapping" "on"
    Option "DisableWhileTyping" "on"
    Option "AccelSpeed" "0.42"
    Option "ClickMethod" "clickfinger"
    Option "HorizontalScrolling" "on"
    Option "ScrollMethod" "twofinger"
    Option "TappingDrag" "on"
    Option "TappingDragLock" "off"
EndSection

In the /etc/sysctl.conf we enter the following:

root: nano /etc/sysctl.conf =>

kern.evdev.rcpt_mask=12

Further setting options can be found here and here.

DEVD

If XOrg was created with devd, we have to use the following settings.

root: echo 'hw.psm.synaptics_support="1"' >> /boot/loader.conf

root: sysrc moused_enable=YES

root: service moused start

For a Trackpoint or an Elantec, we have to replace the word “synaptics” with your pointer type.

Under Xorg, the xset mouse 5 1 command improves acceleration. We just add this line to our ~/.xinitrc.

user: nano ~/.xinit =>

xset mouse 5 1

We would like to use a “MacBook”-like scrolling with two fingers. For this we enter the following in /etc/sysctl.conf:

root: nano /etc/sysctl.conf =>

hw.psm.synaptics.min_pressure=45
hw.psm.synaptics.max_pressure=220
hw.psm.synaptics.max_width=10

hw.psm.synaptics.vscroll_hor_area=1300
hw.psm.synaptics.vscroll_ver_area=-600
hw.psm.synaptics.vscroll_min_delta=50
hw.psm.synaptics.vscroll_div_min=100
hw.psm.synaptics.vscroll_div_max=150

hw.psm.synaptics.weight_current=3
hw.psm.synaptics.weight_previous=6
hw.psm.synaptics.weight_previous_na=20
hw.psm.synaptics.weight_len_squared=2000

hw.psm.synaptics.div_min=9
hw.psm.synaptics.div_max=17
hw.psm.synaptics.div_max_na=30
hw.psm.synaptics.div_len=100

hw.psm.synaptics.margin_top=200
hw.psm.synaptics.margin_right=200
hw.psm.synaptics.margin_bottom=200
hw.psm.synaptics.margin_left=200

hw.psm.synaptics.window_min=4
hw.psm.synaptics.window_max=10
hw.psm.synaptics.multiplicator=10000

hw.psm.tap_timeout=0
hw.psm.synaptics.tap_max_delta:80
hw.psm.synaptics.tap_min_queue:2
hw.psm.synaptics.taphold_timeout:125000

To define the keyboard type, we create the configuration file /usr/local/etc/X11/xorg.conf.d/10-keyboard.conf, which is filled with the following content:

root: nano /usr/local/etc/X11/xorg.conf.d/10-keyboard.conf =>

Section "InputClass"
    Identifier "Keyboard Defauls"
    Driver "keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "de"
EndSection