FreeBSD Installation and Setup

Repost from my WordPress site. The information might be slightly outdated.

On the surface, FreeBSD is almost identical to Linux. The difference is that, like Arch Linux, the base installation doesn't have the features or configuration that something like Ubuntu provides for non-technical users.

This post goes through my process of getting FreeBSD running with a full desktop environment. It should take a couple of hours at most, starting with a basic installation disc or ISO.

Essentially what’s happening here are the following steps:

  • Install a base system from the disc image.
  • Fetch and install X Windows and desktop environment components.
  • Configure the operating system to load X Windows and the desktop environment at startup.

Installing the Base System

For this I used the i386 ‘disc 1’ ISO file in VirtualBox, but the following should apply when installing FreeBSD directly onto a machine with fairly generic hardware. The first thing we get is the boot screen.

From the menu select the ‘Boot Multi-user’ option, then at the next menu launch the FreeBSD Installer. The installation should be fairly quick, as it consists of the base system and the command line interface. When prompted, we definitely need to create a second user account.

Reboot the system and login as root. Fortunately, these days the common UNIX-like systems have package managers. The next stage will require the ‘pkg’ tool to fetch and install other components, so enter the ‘pkg command. #pkg

Adding a desktop interface to the installation will involve modifying configuration files. I use Vim for this, but I strongly recommend the Nano for the less experienced - it's very easy to screw things up with Vim, if you're not fully used to it. The package manager can be used to install this. #pkg install nano

Certain components need to be enables - dbus, hald and kdm4 in particular. The Hardware Abstraction Layer daemon (hald) is used for handling display-related hardware, and dbus is used for inter-process communication. Edit /etc/rc.conf to add the following lines: dbus_enable="YES"
hald_enable="YES"
kdm4_enable="YES"

The thing is hald relies indirectly on procfs, the /etc/fstab file should look something like the following screenshot, and contain the entry for proc: #nano /etc/fstab # Device Mountpoint FStype Options Dump Pass
/dev/ada0p2 / ufs rw 1 1
/dev/ada0p3 none swap sw 0 0
proc /proc procfs rw 0 0

Installing X Server and Desktop Environment

There are some pages on this in the official FreeBSD documentation, but I’ve skipped certain things.
The X Window System is the underlying component for rendering windows, desktops and graphical menus, and where most graphics-related issues are fixed later.

The system will require an X Server: #pkg install xorg

As the status messages indicate, this also fetches and installs the TWM environment. Also required are the X Display Manager (xdm) and Session Manager (xsm). #pkg install x11/xdm
#pkg install x11/xsm

Run ‘X -configure’ and copy the generated file with the following command: cp /root/xorg.conf.new /etc/X11/xorg.conf

In the new file (/etc/X11/xorg.conf) add the following section: Section "Extensions"
Option "Composite" "Enable"
EndSection

Sorting KDE and KDM

Now we’re ready to install a full desktop environment on this. As with Linux, we have a range of possible environments to choose from. I chose KDE, which gives users something vaguely similar to the Windows 7 desktop. #pkg install x11/kde4

Roughly 950MB of KDE and KDE-related packages are fetched (many of them we don’t really need), and installation takes up around 3GB. When this is done, we modify /etc/ttys so TTY8 uses KDM instead of XDM: ttyv8 "/opt/kde/bin/kdm" xterm on secure

I also entered the following to see whether KDM runs as a service at this point. #service kdm4 start

In the user’s home directory we require a file that starts KDE as the default GUI. Enter the following command: #nano ~/.xinitrc

And add the following line to the .xinitrc file: exec /usr/local/kde4/bin/startkde If all is well, the installation should have a desktop interface.

Changing the Display Size and Resolution

After installing FreeBSD with a desktop environment, the first thing I wanted to fix was the virtual screen size, which was much smaller than the physical screen.

Before getting to that, a fresh installation doesn’t have the ‘sudo' program to enable the execution of specific tasks with root privilieges. Switch to another terminal, e.g. Ctrl+Alt+F4, log in as root, then install sudo': Then: #pkg install sudo

Now we need to add the user to the sudoers file, using the visudo command. Add something like the following into the file: michael All=(ALL) ALL

Maxing Out the Display

As often happens when installing Linux/UNIX on VirtualBox, and sometimes when installing on physical hardware, the desktop is much smaller than the physical screen. In this case, I’m guessing the underlying problem was the operating system attempted to detect the video hardware and load the appropriate driver for it. Failing that (because it’s VirtualBox), the operating system falls back to a generic driver module. The driver module needs to be replaced with something from the VirtualBox Additions package. The FreeBSD wiki does have some information on this.

To install the VirtualBox Additions: #sudo pkg install virtualbox-ose-additions-4.3.32 Then enable the VirtualBox guest services by adding the following lines to /etc/rc.conf: vboxguest_enable=”YES”
vboxservice_enable=”YES”

In xorg.conf, the following lines in the Device section are important: Identifier "Card0"
Driver "vboxvideo"
VendorName "InnoTek Systemberatung GmbH"
BoardName "VirtualBox Graphics Adapter"
BusID "PCI:0:2:0"

Hopefully the boot messsages would show the VirtualBox additions being loaded successfully whenever the system is rebooted, and a full size desktop should appear.

Configuring Display Size for Installations without a Desktop

Environment

Before resolving the KDE problem, I managed to fix the display size for the command line by playing with the video mode. As far as I can tell, this only works when the generic display driver module’s loaded.

The following command displays a list of video modes: #vidcontrol -i mode Whichever one of those listed is used is a matter of trial and error, of trying the ones that appear right, with something like: #vidcontrol MODE_279

When you’ve hit the correct one, the mode can be made persistent by adding the following line to /etc/rc.con: allscreens_flags="MODE_279"