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:

$: doas pw groupmod video -m $USERNAME

Then we install the packages Xorg and xscreensaver:

$: doas 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.

$: doas pkg install virtualbox-ose-additions

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

$: doas nano /etc/rc.conf =>

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

Video DRM Drivers (Intel, AMD, ATI)

We will install the meta port package drm-kmod:


$: doas pkg install drm-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

$: doas pkg install xf86-video-intel
$: dos sysrc kld_list+="i915kms"

Radeon Graphic

$: doas 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:

$: doas 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:

$: doas 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:

$: doas pkg install nvidia-driver

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

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

$: doas 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.

$: doas 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:

$: doas pkg install xf86-video-scfb

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

$: doas 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:

$: doas sysrc dbus_enable=YES

And we start these services:

$: doas 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:

$: doas nano /etc/fstab =>

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

$:doas mount /proc
$:doas 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.

$: doas 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;         
	}
});
 
   
$: doas 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;
	}
});

$: doas 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., 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:

$: doas 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:

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

We then check what is considered in Xorg by this command:

$: doas fc-list

UDEV

As of FreeBSD 12.1, udev is being used to automatically configure input devices.

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

$: doas pkg install libinput xf86-input-libinput

We will now create the following configuration file:

$: doas 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:

$: doas 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.

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

$: doas sysrc moused_enable=YES

$: doas 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.

$: doas 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:

$: doas 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:

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

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

Discuss...