FreeBSD as a Desktop with Nvidia

Hello everyone. Welcome to my setup for using FreeBSD as a desktop operating system with Nvidia graphics.

Let me begin by saying that unless you are looking to get into software development or systems administration, there isn’t any real benefit to using FreeBSD as a desktop over something like Linux or MacOS. There are a few “out of the box” features that I think make FreeBSD more ideal than a Linux operating system. I will discuss these during the installation and setup process as they arrive.

Installation

The installation process is very straightforward. When installing FreeBSD on bare metal, I prefer the .img download. When installing on a virtual machine, I will use the dvd.iso – Slight disclaimer for those that are looking to play with it in a VM, you’ll probably have an easier time with the .iso variants.

Upon booting the installation medium, you’re greeted by the coolest mascot/logo in OS history:

image

Let the time run out, which will select 1. Boot Multi user [Enter] by default, or press Enter. If you want to read the other options or explore a bit, press spacebar (or any other key).

At this point the bsdinstall command runs.
image

Selecting Install is your best option.

Note, I have experienced some issue with Corsair keyboards being recognized. The K30 works fine on my system but the K70 does not. Your experience may vary.

The default keymap has always been correct during my installations. But, feel free to select yours if this isn’t the case.

image

Note, Test default keymap is useful if you want to verify the option you have selected is in fact identical to your keyboard.

Next, you’ll give a hostname to your computer. Pretty standard stuff, try and use something original to your network and avoid using weird characters and underscores.

image

You can also borrow from my creative genius when it comes to naming convention. Press Enter to continue.

Choosing optional system components is strictly based on user preference. If you plan on doing some development or contributing to the FreeBSD project, I recommend selecting all of the options. Use the arrow keys to move and spacebar to select entries. I would leave the defaults checked.

image

Pressing Enter at any time will move the installation forward.

Once you arrive at partitioning, you are now upon the precipice of what makes FreeBSD great: Native ZFS.

image

ZFS is a high performing file system initially developed at Sun Microsystems. The FreeBSD handbook describes three major benefits to using ZFS:

Taken here. What does this mean for you?

  1. Even with a failing hard drive, your data will remain intact.
  2. Ease of creating and tagging storage partitions.
  3. Very high performing read/write/mirror/striping.

The caveat to this is MEMORY. ZFS has a very high overhead, meaning it consumes a lot of resources, RAM in this case.

I am going to select ZFS for this installation, a pool type of stripe (since I only have 1 disk, definitely choose based on your use case. Stripe: data is spread across all disks in the array/pool. Mirror: data is the same across all disks in the array/pool. Plus variations, depending on the quantity of disks will have some for mirror and some for striping), and a 4GB swap size. I change the default swap from 2 to 4 at the recommendation of Michael Warren Lucas, infamous FreeBSD sysadmin, developer, and writer. 4GB is enough to hold a kernel dump.

image

Press Enter over Select, confirm your pool type, and press spacebar to select your disk. Use the arrow and spacebar to select multiple disks.

Confirm writing to disk(s).

image

Note, for experienced Linux users, look at the difference in naming scheme. My disk is da0.

After the disks are partitioned, the system will begin installing.

image

image

Once the system is installed, you will be tasked with setting a password for the root user.

image

Note, the password will not show up as *'s or any other symbol. Your keyboard is working just fine, if you’ve made it this far.

Select your network interface. Depending on what you’re using this computer for, you may not want a DHCP lease. If you are assigning a static IP, be sure to use the arrow keys to move down to subnet and gateway and not Tab or Enter.

I am using DHCP for IPv4 and IPv6. If you have a modern router, you should enable IPv6.

After the IP, subnet, and gateway information is configured, it’s time to setup your DNS information. Mine has auto-populated, but if yours does not, do not leave the Search blank! You can name it no.search if you want but do not keep it blank, you may experience network issues.

image

Selecting the network time comes next. You may receive a warning about keeping the time at UTC or if you are not sure the message will tell you to select “No”. Select your country and timezone.

Note, you can press the number coinciding with your state multiple times if it is a higher ten. United States is 49, so I press 4 several times to arrive there.

After that, confirm the calendar date and time. Stop! For some reason the default highlight is set to skip. Be sure to left arrow over to actually set the date and time.

image

Next are the services starting at boot. I select local_unbound, sshd, ntpdate, ntpd, and dumpdev. This is more of a preference. I’ve heard powerd is useful if you’re running FreeBSD on a laptop.

image

Next is hardening the system. This, in my opinion, is where FreeBSD holds a benefit over Linux. No system is secure out of the box, but FreeBSD attempts to proactively protect the system during the installation compared to most Linux systems having you do this post-installation. I select every option.

image

Obviously change this based on your use case. My recommendation is enable them all by default and then learn the system by disabling the options that conflict what a service you may need later. Learn by breaking!

After hardening, you have the option to create additional users. I always create a user that is part of the wheel and operator groups (more on that, later).

image

I change the shell to tcsh. It’s grown on me, and sh is kind of boring.

After adding users, you’ll have the option to make last minute changes. Or, you can just exit the installer and reboot.

image
image
image

Post-Install Setup

Now that you have rebooted your fresh installation, let’s go ahead and login with the additional user you made.

image

Depending on how you’ve logged in, you may or may not receive a “message of the day” or “motd”. Your standard user will have limited privileges, so let’s su into root.

Note, I always recommend using an escalation command rather than running everything as a root user. This comes recommended as a best practice by several professionals in the industry. However, on a fresh system, it may be necessary or useful to work as the root user until the system is configured.

Once at the root user, install some packages to get your system working. The FreeBSD package manager is pkg. If you’re familiar with Linux, the pkg command comes with several commands as a Linux package manager:

pkg install
pkg remove
pkg search
man pkg

All of the above work when using or learning about pkg. I want to install sudo, so I don’t have to run everything as root, vim, for a better editor, and git, because I plan on doing some software development and prefer using git for version control.

image

You’ll notice on first executing the pkg command, FreeBSD cannot find it, but it will offer to install it for you. After the installation of pkg, the rest of the packages you specified will be installed as well.

image

A note on doas, arguments, and ports

Some people prefer doas instead of sudo. I’ve read arguments for both, but don’t understand the controversy or fanboy attitude about either. Both do a great job, in my opinion. Use what you’re comfortable with. You can learn more about doas here.

If you have experience with Linux, you may run various arguments with your package manager or other applications. FreeBSD follows the Unix conventions. So, for example, if you want to automatically say “yes” to the “are you sure you want to install these packages” question, the -y will go before the list of packages, not after.

Linux method:

sudo apt install openjdk vim git -y

FreeBSD method:

sudo pkg install -y openjdk vim git

The order matters, in FreeBSD. sudo pkg install openjdk vim git -y will not work.

FreeBSD has a Ports Collection with the package portsnap. This is a way of having the source code for tools and utilities locally. Since I am not experienced enough to contribute back, I am not very familiar with this nor do I use this method. I much prefer using the package manager. However, if this is something you are interested, or if you prefer reviewing the source and compiling your own packages, you can learn more about this here. The Ports Collection is outside the scope of this write up.

Back to Post-Install

Remember when I added my user to the wheel group and I said we’ll review this later? Well, the time is now!

With sudo installed, enter visudo.

You are now in the sudoers file. Here we can add users and groups to have full or limited super user access.

If you’re not familiar with vim, I’ll give you a quick cheat sheet:

l (lowercase L) - move one space right
h - move one space left
j - move one line down
k - move one line up
/ - search (Searching for “wheel” you would type /, type “wheel” (no quotes or spaces), and press Enter)
:w! - write to the file (include the colon(:slight_smile: and exclamation point(!))
:q! - quit (include the colon(:slight_smile: and exclamation point(!))
:wq - write to the file and quit (no exclamation point needed)
i - insert mode (from here, you can use the keyboard as you would in a word processor)
Esc - command mode (the mode when you first entered the file)
gg - go to the top of the file
G - go to the end of the file
A - append to the end of the current line

Note, “write to the file” is just a fancy phrase for “save”.

Let’s search for “wheel” in the sudoers file by entering a / and typing the word wheel. Press Enter. You can press the n key to move down to the next result of the search. Look for the lines:

## Uncomment to allow members of group wheel to execute any command
# %wheel ALL=(ALL) ALL

You want to remove the comment (# symbol) from the second line. As an exercise, try to find out how to do this without using the backspace or delete keys while in insert mode. My answer will be below. Don’t worry if you mess something up, just quit the file with :q! and enter visudo again.

Answer:

The x key in command mode will remove the currently highlighted character.

After the edit, the lines should look like this

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

Save the file with :wq (don’t forget to press escape if you’re in insert mode)

Congrats! Now the next time a user part of the wheel group logs in, they will have sudo permissions.

We’re almost to the good part, hang tight!

We need to edit our /etc/fstab file to have some fancy kernel magic happen at boot. proc is what’s known as a pseudo-filesystem and it’s used to interface with data structures in the kernel. This means that some of your commands with the system will not work without proc mounted.

You can use vim to edit the file.

vim /etc/fstab

This is what my file looks like after my changes:

image

The additions I made were as follows:

proc /proc procfs rw 0 0

You can use Tab to space over to the appropriate areas.

Save the file with :wq

Now, it’s time to get the graphics setup.

Graphics

Xorg and your favorite desktop environment (DE) are necessary. Plus, we’ll need a login manager. I am going to use KDE for the DE and SDDM for the login manager. They’re both simple, fully functional on FreeBSD, and easy to use for most people.

pkg install -y xorg

This may take awhile depending on your network connection speeds.

Once Xorg is installed, go ahead and install the login manager and DE.

Note, during this write up, I experienced a mismatch size in a package, and the package would not install. I had not experienced this in the past, but if this happens to you, run pkg update -f and attempt installing the packages again. This should clear it up. If not, let me know, and I may have another suggestion.

pkg install -y sddm x11/kde5

This is another “may take a while depending on network speeds” disclaimer. We’re almost there!

Now it’s time to install Nvidia. First, we need to load Linux binary compatibility, which is required to install and run Nvidia drivers.

kldload linux
pkg install x11/nvidia-driver x11/nvidia-settings x11/nvidia-xconfig

The above command and three packages will get everything installed for you. Now it’s time to configure these to start at boot.

Post-Install Configuration

We need to edit the /etc/rc.conf file. The rc.conf file is the FreeBSD systems configuration file. Everything that starts after the bootloader and kernel is setup in this file.

vim /etc/rc.conf

We need to add our libraries for Linux and Nvidia, D-Bus, and our login manager.

This is what I’ve added to the end of my /etc/rc.conf file

dbus_enable="YES"
sddm_enable="YES"
kld_list="linux64 linux nvidia nvidia-modeset"

The linux64 likely isn’t required, but if you plan on experimenting with other packages or gaming, I would keep it on.

Save the file with :wq

Now, we want to have Xorg ready.

Xorg -configure

You may get a long, bizarre output, but that’s normal. Change into your root directory and you should see the xorg.conf.new file:

cd
ls

Move that into /usr/local/etc/X11/xorg.conf.d/xorg.conf

mv xorg.conf.new /usr/local/etc/X11/xorg.conf.d/xorg.conf

Now, reboot, and you should be greeted by a fancy GUI!

shutdown -r now

Potential Issues

I only have one monitor displaying.

Try rerunning Xorg -configure while in the GUI and move the new file to /usr/local/etc/X11/xorg.conf.d/xorg.conf

I have screen tearing

Run nvidia-settings as sudo and change your Advanced Settings under X Server Display Configuration to Force Full Pipeline Composition. When you save the file, save it as /usr/local/etc/X11/xorg.conf.d/nvidia.conf This DOES NOT replace xorg.conf, they work together!.

Congrats!

Congratulations. You have installed one of the better, cleaner Unix operating systems. You are ready to tackle the most challenging system, network, and software engineering challenges. Something to consider is that FreeBSD has regular updates. You can check for this by running freebsd-update fetch as sudo. If you have updates, run freebsd-update install as sudo and your system will be patched.

Let me know if you run into any issues, have questions, or would like more content like this. Thanks for reading!

5 Likes

Great write-up. Braver than me by installing FreeBSD from scratch. Didn’t look that hard at the end of the day and still a better experience than arch.
I have been running FreeNAS for years and do plenty of stuffing about inside jails and whatnot. Nothing you can’t do in FreeBSD itself.
I think I am running:

  • nextcloud
  • gogs
  • plex media server
  • invoiceninja (depreciated, gonna remove it and use gnucash I think)
  • unifi
  • rslsync
  • various download clients, media indexers

Got two VMs running (in bhyve):

  • netdebian running a docker installation of home assistant
  • rancheros running portainer and a bunch of other docker contains. Migrating various jails to docker containers because I like having watchtower automatically update them.

The jails have been invaluable for me not trashing the FreeNAS installation. If I screw something up, I can either revert back if I took a ZFS snapshot on the jail, or just create a new one. The jails operate pretty fast as well.

I know some long time linux users are fluent with vim, and agree it is somehow improved, but I find it frustrating that I have to go look up the commands every time. I guess I know enough to insert some text and maybe delete some, but it isn’t fun for me.
FreeNAS comes with ee, aliased to edit. Much nicer in that I can see what the basic commands are, and it starts in edit mode. :slight_smile:

Want some software or find out if something is available? Head to https://www.freshports.org/ and have a look around. This will give you the package and source tree details, so you can do either type of installation.
Lastly, I never had good experiences trying to compile software using portsnap etc. Usually hit some kind of error or dependency issue I couldn’t resolve myself due to lack of knowledge and time. Now I just use the pkg tool, until it no longer works due to a FreeBSD major release. Then I will just upgrade the jail to the more recent release of FreeBSD and continue from there.

So I am curious. How do optimus laptops behave?