brloh.is/content/tech/freebsd.md

113 lines
4.7 KiB
Markdown

+++
title = "FreeBSD Tips and Tricks"
date = 2025-06-12
slug = "freebsd"
+++
# GPU Drivers
On June 10, 2025, the new FreeBSD 14.3 was released and I decided to try it out. After installing the OS from a USB stick on my bare-metal box (very smooth installation process by the way) I was greeted with the TTY login prompt. Using the built-in `pkg` package manager, I installed my favorite window manager, sway, which unfortunately failed to launch with a cryptic error message "No displays found". After looking in the very helpful [FreeBSD Handbook](https://docs.freebsd.org/en/books/handbook/x11/), it turned out that the GPU drivers weren't preinstalled in the OS, so I had to install them manually and add the respective kernel module to automatically load during boot.
```
pkg install drm-kmods
sysrc kld_list+=i915kms # replace by amdgpu if using an AMD GPU
```
Unfortunately this was not enough, the system still wasn't able to start the graphics. After looking at the logs for some time, I found out that the version of the kernel modules responsible for the GPU drivers wasn't updated for the latest kernel revision yet. Fortunately, FreeBSD developers have a separate repository called `FreeBSD-kmods` with updated drivers so that I didn't need to compile the ports (BSD lingo for source-based packages) manually. However, this repository wasn't enabled by default, so I had to force the package manager to update from it.
```
pkg upgrade -r FreeBSD-kmods
```
This was enough to make sway launch (by using `seatd-launch sway`, as the post-install message from the `seatd` package mentioned) and fully use it to the best of its abilities.
# (Wired) 802.1x authentication
My university uses an `802.1x` authenticated network (both wired and wireless) on campus, in order to connect to it, I had to use `wpa_supplicant` with the following configuration (`/etc/wpa_supplicant.conf`)
```
network={
key_mgmt=WPA-EAP
eap=PEAP
phase1="peaplabel=0"
phase2="auth=MSCHAPV2"
identity="user@school.edu"
password="password"
}
```
After that it was enough to make sure that the wired interface (in my case `em0`) used the supplicant (`/etc/rc.conf`) and restart the network configuration service `netif`:
```
sysrc ifconfig_em0="WPA SYNCDHCP" # replace em0 by your interface name
service netif restart
```
TODO: In the current state of things, certificates aren't checked during the connection process. It is a good idea to check them, especially if connecting to eduroam at a location you don't fully trust.
# `i3status` not using colors
This was merely a quality-of-life issue that for some reason `i3status` fails to detect that it should format its output for `swaybar` to parse it, therefore I had to force it in the config (`~/.config/i3status/config`)
```
general {
colors = true
interval = 5
output_format = "i3bar"
}
```
# Wireguard
Since FreeBSD 14, FreeBSD has excellent support for Wireguard VPNs. I just had to install the `wireguard-tools` package (`pkg install wireguard-tools`), copy my config to `/usr/local/etc/wireguard/` and add the following two lines to `/etc/rc.conf` to automatically configure the connection at boot:
```
wireguard_enable="YES"
wireguard_interfaces="wg0"
```
# Locales
In order to use the correct locale info for your area (e.g. if you want your computer to speak a different language than English), it is necessary to change the system locale in `/etc/login.conf` (or, alternatively, it can be set on per-user basis in `~/.login_conf`, the syntax is the same). In the `default` section (`me` in case of user settings, make sure it is uncommented first), change the `lang` variable to your preferred locale, for example `en_US.UTF-8` for American English or `de_DE.UTF-8` for German. You can see all available locales by running `locale -a`.
```
default:\
...
:lang=en_US.UTF-8:
```
After that don't forget to activate the changes by running the following command:
```
cap_mkdb /etc/login.conf # for system-wide setup
cap_mkdb ~/.login_conf # for per-user setup
```
# `pkg` package manager
During my adventures I stumbled upon some useful commands for the builtin `pkg` package manager that I feel like could be useful to others.
Reinstall all packages from the repository (in case you want to sync your system state to the repositories, including downgrading packages if needed, similar to Arch's `pacman -Suu`):
```
pkg upgrade -f
```
Show packages that depend on the given package (reverse dependencies):
```
pkg info -r PACKAGE
```
Show dependencies of a given package:
```
pkg info -d PACKAGE
```
Install a package from a given repository:
```
pkg install -r REPOSITORY PACKAGE
```
Update the system from a given repository:
```
pkg upgrade -r REPOSTIORY
```