VirtualBox (host mode) was quite recently ported to FreeBSD, some bits are still missing particular network support. So I spent the last couple of days hacking on it and how have a working implementation that supports bridged adapters.

Update 10 Sep: The patches have been committed upstreams.
Update 9 Sep: working vboxnetadp and patchset sent upstreams.
Update: Re-written to use netgraph, now works on FreeBSD 7 and 8

Patches can be found at

http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-netif-20090908.patch
http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetadp-20090908.patch
http://www.shapeshifter.se/pub/patches/virtualbox/vbox-freebsd-vboxnetflt-20090908.patch
http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-20090908.patch
http://www.shapeshifter.se/pub/patches/virtualbox/src-VBox-HostDrivers-Makefile.kmk-20090908.patch

Additional patches to test with the 3.0.51.r22226 version in FreeBSD ports.

http://www.shapeshifter.se/pub/patches/virtualbox/Config.kmk-r22226-20090908.patch
http://www.shapeshifter.se/pub/patches/virtualbox/virtualbox-port-20090907.patch
http://www.shapeshifter.se/pub/patches/virtualbox/ConsoleImpl2.cpp.patch

Re-install VirtualBox through ports using the following commands

Apply/compile with
cd /usr/ports/emulators/virtualbox
make clean patch
mkdir work/virtualbox-3.0.51r22226/src/VBox/HostDrivers/VBoxNetFlt/freebsd
mkdir work/virtualbox-3.0.51r22226/src/VBox/HostDrivers/VBoxNetAdp/freebsd
patch < virtualbox-port-20090907.patch
patch -d work/virtualbox-3.0.51r22226/Config.kmk-r22226-20090908.patch
patch -d work/virtualbox-3.0.51r22226/ConsoleImpl2.cpp.patch
patch -d work/virtualbox-3.0.51r22226/src-VBox-HostDrivers-Makefile.kmk-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-netif-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-vboxnetadp-20090908.patch
patch -d work/virtualbox-3.0.51r22226/vbox-freebsd-vboxnetflt-20090908.patch
make install

In VirtualBox network settings, under "Bridged Adapter" you should now see your available network interfaces. Select the one connected to your network and boot your virtual machine. It should now be connected to your local network as any other machine.

Host only adapter mode can be used to create a virtual network with multiple guests, it creates a special vboxnetX adapter on the host. You'll have to do normal routing between this interface to get outside connectivity.

In addition to vboxdrv.ko you'll have to load vboxnetflt.ko and vboxnetadp.ko too.

kldload /boot/modules/vboxnetflt.ko
kldload /boot/modules/vboxnetadp.ko
3 Responses to “VirtualBox hacking”
  1. jnw says:

    Hello!
    Thanks for very useful feature!
    Does it possible to load vboxnetflt.ko automatically when FreeBSD start?

  2. fli says:

    Try reloading the vboxnetflt.ko driver if you’re getting the VERR_SUPDRV_COMPONENT_NOT_FOUND error.

  3. Harry says:

    Many many thanks for your great work, this is really great news.
    I upgraded to 3.0.51r22902 on 8-BETA4 (kernel from today) and have the problem that bridged-re0 doesn’t work.
    Here’s what I get when starting via qt gui:
    Failed to open/create the internal network ‘HostInterfaceNetworking-re0′ (VERR_SUPDRV_COMPONENT_NOT_FOUND).
    Failed to attach the network LUN (VERR_SUPDRV_COMPONENT_NOT_FOUND).
    Unknown error creating VM (VERR_SUPDRV_COMPONENT_NOT_FOUND).

    Fehlercode:
    NS_ERROR_FAILURE (0×80004005)
    Komponente:
    Console
    Interface:
    IConsole {0a51994b-cbc6-4686-94eb-d4e4023280e2}

    Any help appreciated.

    Thanks,

    -Harry

  4.