FreeBSD on XPS 13: Part 1

Posted on | 984 words | ~5 mins

I like to think of myself as being fairly Operating System agnostic. At home, my main desktop runs macOS and my laptop runs OpenSUSE. At work, I develop software for a Debian-based network operating system and administer CentOS VMs on VMware hypervisors.

There are two gaps here though. I don’t particularly use Windows any more (other than still rocking a Windows Phone for work), and I’ve never really seriously used a BSD. With that in mind, I decided to kill off the OpenSUSE install that’s been running my laptop for just over 3 years and replace it with a FreeBSD one.

In this part, I installed FreeBSD, configured wireless networking, and created my first boot environment.

The Laptop

My laptop is a fairly standard Dell XPS 13 9343 with QHD+ display, however I swapped out the Dell Wireless 1560 (Broadcom BCM4352) with an Intel Wireless-AC 7265 a couple of years after buying it. This was because I got fed up with losing wireless connectivity when OpenSUSE Tumbleweed released kernel updates before the corresponding Broadcom driver update. Given that Intel wireless cards have fairly good support in both Linux and FreeBSD, I suspect this made things a bit easier.

The XPS 13 9343 comes with a Broadwell CPU, which means it’s one generation too new to be supported by the i915 driver in FreeBSD. While I’m not too bothered about 3D graphics acceleration, I read some things that suggested I may have other problems with that driver (in later parts, you’ll find out that I definitely did), so being able to use the drm-next-kmod port was a must.

The drm-next-kmod requires some infrastructure in the kernel to work, so you need to be running FreeBSD 11.2 or later. At the time of writing, 11.2 is still in beta, so I downloaded the 11.2-BETA2 memstick installer and wrote it to a USB stick.

Installing FreeBSD

I’m not going to go into detail about how to install FreeBSD (the excellent FreeBSD Handbook does that much better than I could manage), but there are a few useful pieces of information I’d like to call out:

  • UEFI seems to work fine, so I’d suggest using it.
  • Building the drm-next-kmod port requires the source tree, so make sure you install the src component.
  • ZFS is great, definitely use it.
  • Boot environments (we’ll cover them later) don’t yet support encrypted boot pools, so you probably don’t want to encrypt your root ZFS pool. You can use encrypted swap though.
  • You probably won’t be able to configure any network interfaces during install, as the module for the wireless card isn’t loaded and there’s no on-board ethernet.
  • It’s worth creating a user when given the chance, and you should invite them to the wheel group so that you can use su.

Once I got through the installer, I rebooted, logged in as root and was ready to start configuring the system.

Getting Connected

Before I could install any software, I needed to get my laptop connected to the network. Unlike on modern Linux distributions, there’s no iproute2 on FreeBSD, so I had to dust off my ifconfig skills. Running ifconfig, I was a bit alarmed to find that I didn’t seem to have any interfaces other than lo0!

In FreeBSD, wireless drivers are generally not built into the GENERIC kernel and are instead available as loadable kernel modules. Luckily, loading them is really easy! I added the following to /boot/loader.conf:

if_iwm_load="YES"
iwm7265Dfw_load="YES"

That ensures that the required modules were loaded on the next boot, but to avoid needing to reboot, you can also load them immediately:

# kldload if_iwm
# kldload iwm7265Dfw

My wireless network is secured using WPA2, so I needed to create a wpa_supplicant configuration to be able to connect to it. I created an /etc/wpa_supplicant.conf file containing something like this (you should use your own SSID and PSK:

network={
    ssid="jammynetwork"
    psk="SuperSecurePassword"
}

Finally, I could configure my wireless interface. On FreeBSD, quite a lot is configured through the /etc/rc.conf file. In order to configure the wireless interface (for both IPv4 and IPv6, obviously), I added the following:

wlans_iwm0="wlan0"
ifconfig_wlan0="WPA DHCP"
ifconfig_wlan0_ipv6="inet6 accept_rtadv"

Like with the kernel modules, adding the wireless interface configuration to rc.conf only has an effect on the next boot. It’s possible to bring the interface up without rebooting:

# service netif restart

Installing Software

Much like Linux distributions, FreeBSD has a collection of additional software available through the ports tree (and pkg). I had installed the ports component during install, but I started by ensuring it was up to date:

# portsnap fetch
# portsnap extract

Before doing too much to the system, I wanted to create a new boot environment so I could roll back my changes if anything went wrong. To do that, I needed to install the sysutils/beadm port:

# cd /usr/ports/sysutils/beadm
# make config-recursive
# make install

Sometimes, you may need to run make config-recursive a few times before it stops prompting you to select options, but in this case I only needed to run it once. make install builds the software and installs it, and it’s then ready to use.

Creating a Boot Environment

Boot environments are a feature borrowed from Solaris, which leverage ZFS and its copy-on-write semantics to maintain multiple bootable copies of the operating system while using minimal space. The easiest way to use them is with the beadm tool, and I encourage you to read the man page to fully understand what it can do.

For now, I just needed to make a new boot environment and boot into it so that if I messed anything up when I started configuring the system, I could always roll back without needing to completely reinstall:

# beadm create 20180529-current
# beadm activate 20180529-current
# reboot

With that, the laptop was booted into a new boot environment and I was ready to start configuring it. I’ll cover that in Part 2.