FreeBSD
January 6, 2020

FreeBSD gearing-up quick guide

After spending some time setting up several devices, discovering how to get hardware and software working in BSD based systems, here are some steps I came in after a clean installation.

You can also inspect this document along with some specific installation scripts in this repository

Here's a quick index of what is covered:

  • User groups.
  • Disable beep-beep console sound.
  • System update.
  • pkg installation.
  • GPU setup.
  • Brightness control in laptops.
  • Touch-pad tweaks.
  • doas (super user grant) configuration.
  • Firewall configuration.
  • HDD format / mount.
  • Trackpad configuration.
  • Power management.
  • Async I/O.
  • Setting-up audio card.
  • Miscellaneous facts.

— Add your user to groups

Some useful groups are wheel, operator and video.

First check your user's current membership by typing:

# id yourUserName

That'll list you which groups you're part of. Then to maintain your groups (if any) and add new ones, use the following command:

# pw group mod GROUP -m yourUserName

Change GROUP with the desired group name.

— Turn off "beep" sounds

This shouldn't be such a deal, but it becomes a bit annoying when working in the tty. In order to turn off your computer's speaker (not the ones to play audio, the beep-beep one) type

# sysctl kern.vt.enable_bell=0

To make it permanent on every system boot, save it to your /etc/sysctl.conf file.

# echo "kern.vt.enable_bell=0" >> /etc/sysctl.conf

— Update the system

You can do the following two steps combined but just to keep things in order, first fetch the updates and then install them.

su freebsd-update fetch
su freebsd-update install

Chances are you're running a CURRENT version of FreeBSD where updating needs to be made by compiling the source. The Handbook explains it really in depth, but for quick purposes, here are the basic steps required to update from source:

CURRENT is located at /base/head in FreeBSD's repositories so we need to look for it and locate into our /usr/src directory:

# svnlite checkout https://svn.freebsd.org/base/head/ /usr/src

Once the source code is fetched, the following steps provide a complete system upgrade:

Note the -jN flag sets the number of jobs. This can be useful to speed up builds in multi-core processors. You can determine the number of cores with sysctl hw.ncpu.
# svnlite update /usr/src 
# cd /usr/src
# make -j4 buildworld
# make -j4 buildkernel
# make installkernel
# shutdown -r now
# cd /usr/src
# make installworld
# shutdown -r now
# mergemaster -Ui

At this point you might want to check for obsolete files or directories after the update:

# make check-old
# make delete-old
# make delete-old-libs
# shutdown -r now

After any update installation you can reboot the system and proceed to update the pkg collection:

su pkg update

If you want to use the latest pkg branch instead of the quarterly one, follow this three steps:

  1. Copy /etc/pkg/FreeBSD.conf to /usr/local/etc/pkg/repos/FreeBSD.conf
  2. Change the string quarterly to latest in the url line
  3. Run pkg update -f to update from the new repository metadata.

— If you want to use the ports way to install software, you may also update the ports collection following these steps:

  • Get the latest snapshot:
# portsnap fetch
  • For the first time updating ports, populate the /usr/ports directory:
# portsnap extract  
  • After the first use of portsnap has been completed /usr/ports can be updated as needed by running:
#portsnap fetch
#portsnap upgrade

— Install pkgs

Note that the following pkg list fit some general dependencies such as input and graphic drivers, text editors and basic programming components. You may need extra packages.

Use doas instead of sudo in FreeBSD.

# pkg install doas xorg-minimal xrdb xsetroot nnn xclip pfetch vim-console git devcpu-data mesa-libs python36 xrandr rxvt-unicode feh ffmpeg wget

To get the keyboard / touchpad / trackpoint working there are two ways: the old-fashioned way, and the new way.

  • The old-fashioned way is using synaptics.
xinput xf86-input-synaptics
  • The new way uses libinput instead.
libinput xf86-input-libinput

For video cards check if you mount intel, AMD or nVidia.

  • intel: xf86-video-intel
  • amd: xf86-video-amdgpu
  • nvidia: nvidia-driver
Note that for enhanced gpu behavior you need to set-up drm kmod. Check the step "Set-up graphic cards" down below.

In the web browsers field I find Firefox is the most decent web browser out there, but it stills need too many hard disk and RAM resources. If you have time to try different things, consider options such as vimb or qutebrowser.

  • firefox: firefox papirus-icon-theme gtk-arc-themes
  • vimb: vimb (and if you want custom icons and gtk themes: papirus-icon-theme gtk-arc-themes).
  • qutebrowser: qutebrowser

Some general productivity applications you can install:

# pkg install vlc inkscape blender audacity

— Set-up graphic cards

You need to install drm-kmod in order to get graphic drivers working. For each FreeBSD version there's a different package.

  • FreeBSD CURRENT uses drm-devel-kmod

Along the mentioned pkg depending on your graphics vendor, write the following in your /etc/rc.conf file:

  • intel graphics: kld_list="/boot/modules/i915kms.ko"
  • AMD graphics: kld_list="/boot/modules/amdgpu.ko"
  • Radeon graphics (until 2013's Sea Islands included): kld_list="/boot/modules/radeonkms.ko"

If you want to use OpenCL with AMD graphics or make AMD GPUs to work some workarounds are available:

  1. Be sure you install the correct drm-kmod for your system.
  2. In laptops check if your hardware mounts an hybrid intel processor + amd gpu card and determine to select the second one.
  3. In the /boot/loader.conf file add the following line: hw.syscons.disable=1

— Set-up brightness

Laptops don't have physical brightness control, instead a special set of keys in the keyboard control the bright amount. Depending on the screen you have, you can opt for some packages or some manual workaround to change brightness in your screen.

  • If your laptop has a normal screen:

— You can add acpi_video into /boot/loader.conf

— You can install xbacklight and get control with brightness keys in your laptop.

  • If your laptop has an OLED screen:

ACPI is not working here. You have to find via sysctl -a | grep brightness your drm setting that contains the brightness value and then setup it manually.

desired_val=50
$ doas sysctl sys.class.backlight.[specific_gpu_vendor].device.brightness=desired_val

You can make a script to manage the value via your laptop's dedicated bright keys. An example can be found here.

There are other workarounds like changing brightness via xrandr but that doesn't change the brightness but the gamma.

— Enable touchpad / trackpad

If you're using a Thinkpad and you want to enable the trackpoint without loosing the trackpad functionality, and use the middle button to scroll, this steps are required.

— If you're working with synaptics:

  • In your /boot/loader.conf add the following line:
hw.psm.synaptics_support="1"
hw.psm.trackpoint_support="1"
  • In your /etc/rc.conf add the following lines:
moused_enable="YES"
moused_flags="-3 -F 200 -V"

— If you're working with libinput:

  • Remove any moused variable at /etc/rc.conf.
  • Add the following line in /etc/sysctl.conf:
kern.evdev.rcpt_mask="12"

— Configure doas

doas allows your user to act as su. After installing the doas package you have to create a doas config file in usr/local/etc/.

# touch usr/local/etc/doas.conf

Using your text editor add the following line in order to get permissions for your user (make sure your user is in the WHEEL group):

permit persist keepenv :wheel

— If you don't want to find yourself typing your user password each time you need doas you can go in a more risky way by using nopass:

permit nopass keepenv :wheel

— Configure firewall

FreeBSD firewall is pf. Is taken from OpenBSD and it works perfect.

First we have to create a rule configuration:

$ doas vim /etc/pf.conf

Populate the file with:

block in all
pass out all keep state

Then we have to tell the system where to look for it. Open the file /etc/rc.conf with vim and add the following:

pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
pflog_enable="YES"
pflog_logfile="/var/log/pflog"
pflog_flags=""

You can add your own flags to it.

— Enable microprocessor updates

Add microcode_update_enable="YES" line to /etc/rc.conf file.

Then execute:

$ doas service microcode_update start

You can also enable thermal sensors for your chip adding the following line to the /boot/loader.conf file:

  • AMD K8, K10, K11 thermal sensors: amdtemp_load="YES"
  • intel core thermal sensors: coretemp_load="YES"

— Format / Mount additional HDD / SSD drives

First you need to find what devices you have connected to the system. There are several methods that provide different information about.

  • doas egrep 'ada[0-9]' /var/run/dmesg.boot Returns a simple list.
  • doas geom disk list Returns a more detailed list.
  • doas gpart show Returns info about partitions too.

A "brute force" way to clean the disk once you have checked which devices are available and checked what name they have, is to fill it with zeroes.

doas dd if=/dev/zero of=/dev/adaX bs=1M

Where adaX is your drive name. Be careful as it is a very destructive way to work, and typing the wrong drive target can break the system.

The label bs=1M is important since if you don't alter the speed, the process can take up to days depending on the disk size.

Now that we have our second drive cleaned, we can proceed to create a new partition scheme.

$ doas gpart create -s GPT adaX 
adaX created

You can check that the step worked with # gpart show adaX

Let's add a new partition:

$ doas gpart add -t freebsd-ufs -a 1M adaX
adaXp1 added

You can check that the step worked with # gpart show adaX as well. This time you should see a partition added.

Now we have to format /dev/adaXp1 partition:

$ doas newfs -U /dev/adaXp1

Let's create a directory to mount the partition:

$ doas mkdir /media/data
$ doas mount /dev/adaXp1 /media/data/

Now we can list the new disks with # df and update the /etc/fstab file.

$ doas vim /etc/fstab

Add the line that matches your new partition to the /etc/fstab file.

/dev/adaXp1   /media/data/      ufs   rw   2   2

—If you have some external HDD drive already formatted you may want just to mount it instead of erase all the data.

This is an example for an external NTFS drive (probably the most common formatted drive you can have if coming from Windows / MacOS or Linux).

First we need to install the fusefs-ntfs package.

$ doas pkg install fusefs-ntfs

After doing so, load it:

$ doas kldload fusefs

You can make it permanent by loading it at boot, adding the following line to /boot/loader.conf

fusefs_load="YES"

Create a directory for your external drive inside the /media directory as before. Now plug your external device and get the desired partition to mount.

$ doas mkdir /media/external_drive
$ doas gpart show

For the example let's say we have an external drive named da0 and a partition named da0s1.

To mount it, type the following:

$ doas ntfs-3g /dev/da0s1 /media/external_drive

You're ready to use your external drive. To un-mount it you just need to umount the directory where the disk is mounted in.

$ doas umount /media/external_drive

— Control fan speed / sound

On laptops the fan speed may vary from being attached to AC or to the battery. You may want to look at the BIOS for power fan control. If you have settings there, you can make tweaks.

From inside freeBSD, you can use powerd to alter what happens when connected to AC and/or when connected to battery.

In your /etc/rc.conf add the following lines:

powerd_enable="YES"
powerd_flags="-a adaptive -b adaptive"

There are more options to set the flags. Check the powerd man pages for more info.

An alternative to modern multi-core processors is powerd++ (installed as powerdxx). It's an enhanced version of powerd. You have to choose which one to use as they cannot be running in pair.

— Async I/O

Simply add the following line to the /boot/loader.conf file:

aio_load="YES"

— Setting up audio

As with the graphics card, to get audio working you need to load its proper driver. That can be done both in the command-line or at boot time. This is a quick recap that should go straight forward to a working result. A deeper explanation can be found in the FreeBSD handbook.

  • From the command line type:
# kldload snd_hda
  • In order to load it at boot time, edit your /boot/loader.conf file to add the rule:
snd_hda_load="YES"

The second step we need to perform is to determine which output we want to enable. Type:

$ dmesg | grep pcm

to list which detected cards you have.

Lastly, printing cat /dev/sndstat displays which card is in use:

# cat /dev/sndstat

You can change it by calling sysctl, changing n with the number of the desired pcm card:

# sysctl hw.snd.default_unit=n

To make the changes permanent, add the line into your /etc/sysctl.conf file:

hw.snd.default_unit=n

If you're not sure which driver to load, or you have trouble getting a pcm list, change the snd_hda driver with snd_driver:

# kldload snd_driver

— Miscellaneous facts

  • You can change the initial greeting by modifying it at /etc/motd.
  • You can change the prompt chars by modifying the PS1 variable as follows:
$ doas PS1='custom_stuff-$ '
  • In order to check which shells you have on your system, type:
$ cat /etc/shells
  • (more to come as I discover them).