Setting up a desktop environment and applications on FreeBSD 12

In this article I would like to share resources I referred in order to set up a desktop environment and applications on #FreeBSD 12.

Replace a proprietary operating system with a free and open one

Since the last year I have started using FreeBSD, a UNIX-like operating system, on my desktop and laptop. The motive behind it is to remove proprietary operating systems from my life and replace them with free one on which most of proprietary applications even do not run.

To protect yourself from a proprietary software ecosystem in which you often are forced to join by your colleagues, the most effective method would be to use a free and open source operating system by yourself. You should not feel guilty about using a minor operating system, because in the free society, nobody can legitimately direct you to use a certain operating system. So if you ask someone to use a certain operating system, you suppress the person's right and freedom by not respecting the diversity of the digital environments. As you recognize others' freedom, let them recognize your freedom. That's the very principle of the modern civil society.

On a free and open source operating system, you can make your own environment and maintain it based on your own will. Nobody is going to take it away from you against it. You cannot expect this kind of freedom on proprietary operating systems where look and feel of the user interface is replaced sorely on the manufacturer's decision. For example, you simply cannot keep using Windows XP's environment forever.

As a free operating system, a GNU/Linux distribution such as Trisquel would be a top pick for most people, but if you are looking for something that you can orderly control everything from the ground, BSD operating systems are worth a try.

BSD operating systems are stable, powerful and versatile. They are mainly used for a server, still they also can be used with desktop environments like GNOME, MATE, and XFCE. There are also applications for the desktop environment available such as Firefox, Thunderbird, LibreOffice, GIMP, OBS Studio, and VLC media player, so if you have adopted #FOSS on other operating systems already, you can keep using the same applications in many cases. Even if the build is not available there, there is an emulator often referred as Linuxulator, which makes it possible to run it on FreeBSD if the build is compatible with GNU/Linux (See below about Linuxulator).

Understanding the Concept: Differences between GNU/Linux and BSD

In general BSD operating systems resemble GNU/Linux distributions in many ways, still there are also key differences between them. Understanding the differences first helps you to make a plan how you would take advantage of the BSD operating systems. The article below is one of the well-known essays that illustrates the main differences between BSD and GNU/Linux. Reading it through will let you grasp the basic concepts of the BSD operating systems.

BSD operating system is similar to the web browser on which you can enhance its functions with add-ons. BSD core system includes minimum packages so you can add applications on your needs. The fact that the core system and applications which enhance it are strictly separated is one of the main differences between BSD and GNU/Linux.

On BSD operating system, anything not related to the core system is not installed by default, let alone the graphical user interface. If you want to set up a desktop environment, you need to install every package required for that. This looks complicated, still the installation process gives you better understanding what you have installed for the operating system and what is in it. Principally there is not a concept of “bloatware” on the BSD operating systems. If you feel your computer does not work smoothly, it is mostly because of what you have installed and how you configured it.

Which BSD operating system do you take?

If you do not have a special preference, either FreeBSD or OpenBSD should be a natural choice. In my case I chose FreeBSD because it arguably maintains more applications for desktop environments than others, with a better IME support. If you are looking for reasons why you would prefer OpenBSD, the article below may help:

The question like “Which one is better, FreeBSD or OpenBSD?” is a nonsense. They have their own merits and advantages over others, so please learn your own needs first to pick which one should work best to satisfy them. Learn yourself to know which BSD operating system you want to use.

Resources

There is a lot of well written articles in Internet which summarize how to install a desktop environment on FreeBSD. I am not sure if I could write better than those, so I would like to just list what I have used as a reference to set up the desktop environment and applications.

Overview

At first, the articles below should help you to understand how to install FreeBSD and set it up to add a desktop environment.

I would like to stress the importance of reading the official documentation for FreeBSD. The documentation of FreeBSD is simply phenomenal. Both quality and quantity is far beyond the level of Windows / macOS. In most cases documentation is available both online and offline. You are expected to consult the official documentation before asking a question on the official forums. Otherwise your questions will simply be ignored, if you create a post with a phrase like “... does not work”.

Reading through the official documentation takes a lot of time and energy, but it will let you understand how the system works and how you can configure it on your needs. It is organized quite well, and helps you to grasp the whole picture of the operating system.

Find a laptop

When it comes to compatibilities, FreeBSD often supports less hardware than Windows, macOS, and GNU/Linux do, as a matter of fact. Rare hardware is sometimes not supported so you should carefully research which machine to use. Do not count on a virtual machine to check compatibility issues.

This page gives you the general impression which manufacture's computers tend to be supported well.

If you want to check the latest trend, I would recommend you to check the page below:

Traditionally FreeBSD has worked on IBM / Lenovo's Thinkpad. The page below helped me to have an rough idea how well Thinkpad series are supported and what kind of stuff tends to be not working there:

Comparing models on the wiki and the database, I chose Thinkpad X250 for my laptop. Mine has been cleaned and recompiled by IBM, got 8GB RAM and most importantly, a microphone and a webcam. Bluetooth should be also available but I cannot figure out how to enable it on FreeBSD.

Install FreeBSD core system on an encrypted partition

On FreeBSD it is possible to set up a full-disk encryption of the startup partition, following the procedure described below:

You also can add encrypted partitions later following the manual:

After encrypting the partition you can mount it with a key file with or without password encryption. VeraCrypt is available on FreeBSD too, but generally the natively supported protocol should work better.

Install applications

FreeBSD provides two ways to install applications. The first one is to use pkg to manage precompiled binaries (packages), and the second one is to use Ports Collection to compile binaries from the source code. On FreeBSD a toolchain for that is installed by default, and you can run make to compile an application on a port.

The Ports Collection is a set of Makefiles, patches, and description files. Each set of these files is used to compile and install an individual application on FreeBSD, and is called a port.

You can select which one based on your preference. For most cases, pkg should work as expected, but if you want to follow the latest status of the codebase, you should use Ports Collection. It consists of bug fixes since the latest branch-release, which sometimes are critical to run the system. In my case, the bug related to X Window System has prevented me from starting the graphical user interface.

Also please note that you should not use them in conjunction. According to the official page,

Before installing and using the Ports Collection, please be aware that it is generally ill-advised to use the Ports Collection in conjunction with the binary packages provided via pkg to install software. pkg, by default, tracks quarterly branch-releases of the ports tree and not HEAD. Dependencies could be different for a port in HEAD compared to its counterpart in a quarterly branch release and this could result in conflicts between dependencies installed by pkg and those from the Ports Collection. If the Ports Collection and pkg must be used in conjunction, then be sure that your Ports Collection and pkg are on the same branch release of the ports tree.

To install and upgrade an application on your system, you can use portmaster as well.

After installing it $ man portmaster lets you know how to use postmaster properly, and you should read it through to take advantage of the powerful tool.

This manual contains a lot of valuable information about portmaster, and you should read the entire manual to give you a better idea about how it works and what choices are available to you. However in the interests of getting you started quickly please see the EXAMPLES section at the end of the manual.

Search applications

As discussed in the article cited above at first, unlike GNU/Linux, FreeBSD has the monolithic codebase which has a strict hierarchy, so basically you cannot download an official source code from another repository to build and install an application because there is not another repository from the start.

Any applications must be imported into the codebase to be supported officially, which is why the set of files for building an application is called a port. Each official application is maintained by ports submitters, maintainers, and committers, most of whose work is voluntary. It is a manual labor and applications do not magically appear in the Ports Collection.

You can search these websites for applications in the Ports Collection.

Install MATE

As a desktop environment I picked MATE, and referred the page below to install it. The article was written for FreeBSD 11, but it worked for FreeBSD 12 as well.

Installation might take some time despite being a straightforward process. After installing it you'll have to configure the system manually to log in to the desktop environment. The article above picks slim as a display manager, but it is fine to chose another one such as lightdm. To compare display managers, I found this site useful:

Firewall

FreeBSD has well maintained firewall applications like pf and ipfw. I chose pf for my computer. Please note it does not have a default setting, so you'll have to configure it by yourself on your own needs.

Since my knowledge about the concept of the firewall is also quite poor, I followed the guide below to create the configuration file.

Please note that if you are the only user on the computer, there is almost no point of filtering packets going outside as you should understand already which applications are running. At first I did not understand that and had a hard time of figuring out how to allow ports used by an application randomly. Limiting ports usually makes sense only if the computer is used as a server which a lot of people interact with.

Wireless network

To set up a connection with a wireless network also needs a manual configuration. Everything you need to know what to configure to establish the connection should be available on the manual.

$ sudo ifconfig wlan0 list scan up

After finding your network, copy the SSID, and edit /etc/wpa_supplicant.conf

network={
        ssid="..."
        scan_ssid=0
        psk="..."
        priority=5
}

Input the SSID to ssid and its password to psk

On my laptop I also needed to specify external nameservers. If $ ping example.com does not return the result, open /etc/resolve.conf to specify other nameservers but localhost (I picked AdGuard DNS).

After setting the nameservers, run $ sudo service netif restart. To check if DNS is working properly, run $ ping example.com again.

My desktop works without this configuration so this must be related to my incorrect setting somewhere.

Sound

You need to configure a sound card to enable sound on FreeBSD, if the operating system does not detect it automatically.

After loading the driver on /boot/loader.conf, edit /etc/sysctl.conf to choose the default unit of sound with hw.snd.default_unit setting.

Webcam

On FreeBSD it is possible to join an online video conference with a WebRTC-based FOSS such as Jitsi.

As always, you need to install an additional application and configure the operating system so it loads the webcam's driver properly. I referred the website below to set up the webcam on my laptop.

Tip: if you are asked to join a video conference on a proprietary software, you should tell them very clearly that it is not possible to do so because the application is unavailable on FreeBSD. Do not let those who do not respect the principle of the modern civil society, mutual recognition of freedom, take an initiative to decide how the video conference should take place.

GNU/Linux emulator

FreeBSD supports running GNU/Linux applications on the emulator, but not so many applications run successfully on the current stable version of FreeBSD. You can check below to find out how to set up the emulator and which applications have been confirmed to run or not.

On FreeBSD 12, neither Electron-based apps nor AppImage run yet. The latter is being worked on here while the former is not quite. If you cannot find applications which work on FreeBSD, I think it is worth looking for alternatives. There might be another version which you can use with a command line.

Run ProtonMail Bridge

It is possible to run ProtonMail Bridge inside the GNU/Linux emulator on the command line. Here are the rough steps with which I configured it.

$ sudo chroot /compat/linux /bin/bash

On the emulator download the official package for Debian from the webpage below:

Run dpkg -i to install the application. At first installation should fail due to the lack of required packages, so run # apt --fix-broken install to install them and the application itself.

In order to run it, you also need to install pass and run gpg --gen-key create a GPG key without a password. After creating the key, run pass init to configure the password manager.

After that, run # /usr/lib/protonmail/bridge/protonmail-bridge --cli to configure the application.

The command below should start it from the outside of the GNU/Linux emulator.

$ sudo chroot /compat/ubuntu/ /bin/bash -c '/usr/lib/protonmail/bridge/protonmail-bridge --noninteractive'

I have set up cron with sudo to make it run each time the computer reboots.

Bonus: Watch DRM based movies on FreeBSD

On FreeBSD 12 it is not possible to watch movies managed with DRM technology due to a proprietary library to decode them. I took advantage of the shell script provided at the website below to install Brave Browser on GNU/Linux emulator.

Since the DRM technology is not a FOSS by design, please use it based on your will and responsibility. Respect others' right and freedom, and do not force others to use it. Never presume they are fine with using it.

Closing remark

FreeBSD stress ball

"FreeBSD Stress Ball" by FAndrey is licensed under CC BY 2.0.

BSD operating systems generally require you to understand the structure of the system more than other popular proprietary operating systems do. You are expected to read a manual and educate yourself by doing so, which often takes a lot of time.

One of the main advantages of BSD is that you can 100% decide what to install and how to use it. The concept of bloatware does not exist in its ecosystem. You can create and maintain the environment sorely on your own will. This is similar to creating your own garden; nobody forces you what to grow there.

The large ecosystem of FreeBSD has been maintained by a lot of voluntary work. It includes a lot of applications for daily use on desktop environments, and you can not only use them freely but also help the ecosystem to develop by proposing a change, submitting bug fixes, localization, joining users community or starting one, etc. This is an enjoyable and precious experience for sure which cannot be achieved with proprietary operating systems.

Copyright © 2021 Suguru Hirahara. This work is available under GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation. See https://blog.progressiv.dev/yq31akw3jj for copying conditions.