My FreeBSD Development Environment
I’m writing this primarily for myself, but also for others to reference and improve upon.
I run FreeBSD CURRENT in a VM. I use a VM for the inevitable situation where it crashes. I prefer to use Qemu on KVM, almost exclusively because of the ease of using the graphical
virt-manager over ssh, and the ease of rebooting.
FreeBSD cannot do crash dumps to VT disks (vtdb0) so I make sure the Disk type is SATA. Also, the disk should be at least 40GBs, or else you won’t be able to dump the kernel core in the event of a crash.
After installation, I install the same packages I use as follows:
pkg install sudo bash git gdb bat vim tmux rsync
Next I set the following options in
sysrc dumpdev=/dev/ada0p2 # Or whichever device your swap partition is sysrc dumpdir=/var/crash sysrc savecore_enable=YES
/usr/src to be owned and thus editable by my user account:
chmod farhan:farhan /usr/src/
Then I clone the FreeBSD repository:
git clone https://github.com/freebsd/freebsd-src /usr/src
I enable debugging symbols and disable cleaning in
/etc/make.conf by adding the following values:
NO_CLEAN=1 CFLAGS+=-g -O0 -fno-inline-functions NO_CLEANDIR=1 WITH_DEBUG=YES WITHOUT_CLEAN=1
Then I will build and install everything:
cd /usr/src/ make buildworld -j 8 make buildkernel -j 8 make installworld -j 8 make installkernel -j 8
This step takes a few hours, so I typically run it overnight and give the VM as many CPUs as possible. Note, LLDB takes the majority of time…Then reboot and hope it comes back :)
After reboot, I ensure that kernel debugging is enabled by triggering a panic and trying to dump the core by doing:
When you drop to a
ddb prompt, I run
reboot. This should dump the kernel into the swap partition then reboot, respectively.
At reboot I run
kgdb -n last to verify I can access the kernel dump.
Finally, I always work on updates off of a git branch from the latest
main branch and periodically
git fetch the latest changes and
git rebase main to ensure things are drifting…which they never do anyways.
Two areas of improvement:
- I would love to use VS Code connected to a FreeBSD development environment via the SSH extension. This does not work at the moment, I suspect because of a local daemon that does not currently run on FreeBSD. Ideally some sort of kdb-over-IP would be great too.
- Boot Environments: I have not needed this just yet, but I’ll update this when this becomes a problem.
And that’s it!