For the complete documentation index, see llms.txt. This page is also available as Markdown.

5.2 Installing FreeBSD with VirtualBox

Oracle VirtualBox is a Type-2 hypervisor that provides computing, storage, and network resources to virtual machines through device emulation and paravirtualization technologies. VirtualBox supports multiple virtual disk image formats, defaulting to VDI (Virtual Disk Image), while also being compatible with VMDK (VMware), VHD (Microsoft), and other formats. This virtualization software runs on mainstream operating systems including Windows, macOS, Linux, and Oracle Solaris. FreeBSD can install VirtualBox OSE via Ports to serve as a host machine.

FreeBSD runs stably as a virtual machine in VirtualBox. The demonstration environment in this section uses VirtualBox 7.2.8 and Windows 11 25H2.

Note

VirtualBox currently maintains two parallel branches: 7.1.x and 7.2.x. The 7.2 series was first released in August 2025, adding Windows/Arm platform support, and is the current mainline version; the 7.1.x series continues to receive maintenance updates. In FreeBSD Ports, emulators/virtualbox-ose (6.1.x) has been marked as DEPRECATED with an expiration date of 2026-12-31. It is recommended to use emulators/virtualbox-ose-72.

Downloading VirtualBox

Visit the official website https://www.virtualbox.org, click the Download button on the right side of the page, and select the installer for your platform to complete the installation.

Installation Settings

After installing VirtualBox, create and configure the virtual machine step by step.

VirtualBox Main Interface

Select "New" in the VirtualBox main interface.

Create Virtual Machine

Enter "FreeBSD" in the "Name" field, and the related options below will be auto-filled.

Virtual Machine Name Setting

Allocate memory size and CPU count, and enable the EFI support option.

Tip

It is recommended to use UEFI boot mode, as Xorg can automatically detect the graphics driver without manually writing /usr/local/etc/X11/xorg.conf.

Hardware Settings

Adjust the virtual hard disk capacity.

Hard Disk Size Setting

Enter the virtual machine settings.

Virtual Machine Settings

Set the graphics controller to VBoxSVGA.

Warning

Do not check "Enable 3D Acceleration". VirtualBox Guest Additions on FreeBSD do not support 3D acceleration; enabling it will cause display abnormalities.

Display Settings

If needed, you can switch the virtual hard disk to an NVMe controller:

NVMe Hard Disk

Click "Start" to begin installing FreeBSD.

FreeBSD Installation Interface
FreeBSD Installation Interface
FreeBSD Installation Interface

After installation is complete, you must manually shut down and remove the installation disc from the virtual machine settings (if prompted to force release, select agree), otherwise the next startup will enter the installation interface again.

Eject Disc After Installation

The completed FreeBSD virtual machine system:

FreeBSD System Interface

Resolving Inability to Shut Down Properly Under EFI

Edit the /etc/sysctl.conf file and add the following content:

Then restart the system, and shutting down should work normally again. This setting disables the EFI power-off function, allowing the system to shut down through ACPI instead.

References

Network Settings

In terms of virtual networking, VirtualBox provides various network modes including NAT, Bridged, Internal, and Host-Only, each corresponding to different network topologies and connectivity.

Bridged Mode

Tip

VirtualBox bridged mode enables bidirectional network connectivity.

Bridging is a convenient way for the host machine and virtual machine to communicate with each other. The virtual machine can obtain an IP address on the same subnet as the host machine. For example, if the host machine IP is 192.168.5.123, the virtual machine IP will be 192.168.5.x.

Bridged Network Settings

Make sure the network card selected in "Name(N)" in the figure above is the one currently in use, otherwise the virtual machine will not be able to access the network.

After configuration, run dhclient em0 to immediately obtain an IP address. For a persistent configuration, add ifconfig_em0="DHCP" to /etc/rc.conf.

If you cannot access the Internet, set the DNS to 223.5.5.5. For specific steps, refer to the DNS configuration section in this chapter.

NAT and Host-Only Modes

Unlike VMware, in VirtualBox's default NAT mode, the host machine and virtual machine cannot directly communicate with each other. The virtual machine can access the host machine's special address 10.0.2.2 and the services running on it, but the host machine cannot access the virtual machine's ports, and the networks between virtual machines are also isolated from each other.

When bridged mode does not work, you can use a dual network adapter approach instead. If you want to control the FreeBSD system in the virtual machine from the host machine (such as Windows 11), you need to configure two network adapters: one in NAT mode for Internet access, and another in Host-Only mode for communication with the host machine.

First, configure the network adapter in NAT mode for Internet access:

Dual NIC Settings

In the network adapter type dropdown, the "NAT" and "NAT Network" options have similar functionality. The main difference is that virtual machines can communicate with each other under "NAT Network" mode, while virtual machine networks are isolated from each other under "NAT" mode.

Then configure the second network adapter (Host-Only mode) for the local network:

Host-Only Mode Settings

Run ifconfig to check the network status. If the second network adapter em1 has not obtained an IP address, you can temporarily obtain one via DHCP: dhclient em1. For a persistent configuration, add ifconfig_em1="DHCP" to /etc/rc.conf.

NAT and Host-Only Mode

In this configuration, the virtual machine and the host machine's local network cannot directly communicate with each other. SSH connections should be made through the em1 IP address, typically 192.168.56.X, rather than 10.0.2.X.

References

Virtual Machine Enhancement Tools

VirtualBox Guest Additions are a set of drivers and system services running inside the virtual machine, providing the following support:

  • Shared clipboard.

  • Integrated mouse pointer.

  • Host time synchronization.

  • Window resizing.

  • Seamless mode.

Note

The following commands are executed inside the FreeBSD virtual machine.

Installing Guest Additions

  • Install using pkg:

  • Or install using Ports:

  • After installation, you can view the Guest Additions configuration instructions with the following command:

Service Management

After installing the Guest Additions, you need to enable the relevant services and set them to start at boot.

Enable the VirtualBox guest enhancement driver:

Enable the VirtualBox service:

Add the regular user ykla to the wheel group for administrative privileges:

If you are using the ntpd(8) time service, you should disable host time synchronization by adding the following to /etc/rc.conf:

Desktop Preview

In Wayland environments, desktop functionality is currently unavailable due to the lack of corresponding DRM/KMS driver support. The following demonstrates installing and launching KDE under X11 in a virtual machine:

FreeBSD System Interface

Window resizing, seamless mouse switching, and other features all work normally.

FreeBSD System Interface

Video playback is relatively smooth, but the default volume is low; you may want to increase the system volume appropriately.

Shared Folders

Shared folders are used to transfer files between the host machine and the virtual machine, and can be mounted and accessed via the mount_vboxvfs command. The following example creates a shared folder C:\Users\ykla\ in the VirtualBox graphical interface and mounts it to /mnt/bsdboxshare inside the virtual machine:

Edit Shared Folder

Note that the "Folder Name" is the filename that the operating system (FreeBSD virtual machine) will see, and it must not contain spaces.

View the folders to be mounted in the FreeBSD virtual machine:

The command to mount the shared folder in the FreeBSD virtual machine is as follows:

List the contents of the shared folder:

Troubleshooting and Outstanding Issues

Mouse Captured in Virtual Machine Window, Unable to Move Out

Press the right Ctrl key to release the mouse (by default, the keyboard has left and right Ctrl keys). If you need to restore the screen due to auto-resizing or cannot find the menu bar, press Home + right Ctrl.

Tip

On a standard 108-key keyboard, the Home key is located below the Scroll Lock key.

UEFI Firmware Settings

Press the Esc key repeatedly at boot to enter the VirtualBox virtual machine's UEFI firmware settings interface.

Last updated