VirtualBox is a well-known virtualization system in the Linux world. In this article, we will learn how to install and configure it on FreeBSD. It is worth noting that I only recommend its installation on desktop systems, as we have much more suitable solutions for servers such as IOCage or vm-bhyve . And yes, I know that VirtualBox can also be installed without graphical support and managed from the CLI, but the experience is very poor and depending on the hardware used, it can cause stability issues.
This article is based on the FreeBSD handbook guide with some additional annotations.
First, we make sure that our microprocessor has the Intel-VT/AMD-v registers. In my case, it is an Intel Core i7-6700K.
VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
There has been a case where the CPU had these registers, the option was enabled in the BIOS, but the information was incorrectly presented to the operating system:
VT-x: (disabled in BIOS) HLT,PAUSE
VT-x: (disabled in BIOS) HLT,PAUSE
In such a case, it was resolved by updating the BIOS to the latest version.
Now that we are sure that our CPU is compatible, we proceed with the installation of VirtualBox:
We load the kernel module:
We make sure that it is loaded again on the next boot:
vboxdrv_load="YES"
We enable the service and start it:
service vboxnet start
We add the user with which we will manage the virtual machines to the vboxusers group:
If we are going to use bridges in the VirtualBox network, we must give permissions to the vboxusers group:
chmod 0660 /dev/vboxnetctl
To make the permissions permanent, we must configure devfs as follows:
own vboxnetctl root:vboxusers
perm vboxnetctl 0660
If we also want the virtual machines to have access to the USB ports of the parent computer, we must add the user to the operator group:
And define the following devfs rules:
[system=10]
add path 'usb/*' mode 0660 group operator
NOTE: Note that devfs permissions have been configured in the devfs.conf file while the rules are in devfs.rules.
We tell the operating system to load our devfs rules:
service devfs restart
Some virtual machines may have trouble acquiring an IP address via DHCP. To make this work, we must enable the option:
Settings -> Network -> Adapter1 -> Promiscous mode: Allow all
Troubleshooting:
Another active virtualization system:
If we have other virtualization systems such as
CBSD
or similar, we must take into account that if the vmm module is loaded, the VirtualBox virtual machines start but remain in a black window, neither the BIOS nor the system boot appears.
The latest Windows are not able to install the latest version (6.1.32) of the “Guest Additional Tools”, for example Win8 and XP do not allow it, in which case we must download a previous version:
https://download.virtualbox.org/virtualbox/6.1.26/VBoxGuestAdditions_6.1.26.iso
Problematic QT Theme:
Sometimes the QT theme configured in the system can cause problems with VirtualBox. This error is very difficult to debug since VirtualBox simply crashes:
Segmentation fault (core dumped)
And no useful information appears in the logs:
Feb 17 21:41:55 Garrus kernel: pid 69543 (VirtualBox), jid 0, uid 1001: exited on signal 10 (core dumped)
We install the configurator and configure a more or less standard theme:
Module outdated compared to the system:
FreeBSD always avoids breaking compatibility with previous versions, but this means that there may be packages (usually kernel modules) that do not work in the latest version of the operating system and must be compiled from the ports. VirtualBox is one of them. We can read the
whole discussion in this forum thread
.
Packages are build for 13.0, kernel modules for 13.1 need to be build from ports.
That will be three months from now, then 13.0-RELEASE will be officially End-of-Life and packages will be built for 13.1-RELEASE.
I think the version mismatch issue will go away when 13.0 reaches EOL (3 months from the release of 13.1) and 13.1 becomes the lowest version. Till then, the solution may be to use the port instead of the binary package. I do not think the port could be broken as a binary package exists, but I am no expert in ports.
As we can see, until version 13.0 reaches its EOL at the end of August, the module will not be compiled for 13.1. For this reason, I recommend updating to the next version of FreeBSD only when the previous one has reached its EOL unless we urgently need some functionality of the new version.
If we try to load the module installed from binary packages:
We will see the following error in dmesg:
KLD vboxdrv.ko: depends on kernel - not available or version mismatch
linker_load_file: /boot/modules/vboxdrv.ko - unsupported file type
We remove all packages related to VirtualBox:
We compile and install the VirtualBox modules:
cd /usr/ports
make fetchindex
git -C /usr/ports branch –list -r
git -C /usr/ports rev-parse –abbrev-ref HEAD
cd /usr/ports/emulators/virtualbox-ose-kmod
make clean
make
make reinstall
We reinstall VirtualBox from binaries:
Now we can load the module without any problem:
TRUSS:
As a last resort, we can always use
TRUSS
to try to deduce the cause of the problem:
security.bsd.unprivileged_proc_debug: 0 -> 1
A regular user can now execute TRUSS: