As I do run OpenWRT on a few devices that FreeBSD doesn't run on I always had to keep a Linux based operating system around as OpenWRT doesn't really work well on FreeBSD even though "it should" and ongoing work is being done in that department. You can get the bare distribution to compile but as soon as you try to build third party applications you're in for a not so nice treat. So far I've used VirtualBox and VMware Player on my work laptop as VirtualBox on FreeBSD is clunky compared to Windows and requires quite a bit of work to make it somewhat usable. While bhyve was announced in FreeBSD 10 as stable I felt that it never really was and all machines that was capable still ran 9.X so I decided to wait until FreeBSD 10.1 was released to give it a go. While it isn't the most user-friendly solution around it works surprisingly well for being still in very active development. Documentation is still a bit light but I managed to get it all working thanks to a few tutorials and the virtualization mailling list.

Notes: You are adviced to create a separate directory to put everything in, also running this as root user is required. Following this will create a virtual machine with 40Gbyte disk space, 2 CPUs and 768Mbyte of RAM.

  • First you need to install grub2-bhyve as bhyve can't boot Linux on its own
    cd /usr/ports/sysutils/grub2-bhyve && make install clean
  • Download the distribution you want to run, in my case Debian
    fetch http://ftp.no.debian.org/pub/Linux/debian-iso/7.7.0/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso
  • Create a file which will act as your VMs hard drive (40G in my case)
    You can use truncate but it'll cause more fragmentation
    dd if=/dev/zero of=./debian-buildbox.img bs=1M count=40960
  • Load modules for networking and virtualization
    Note: If you're using GENERIC kernel this are all included by default
kldload if_tap  
kldload if_bridge
kldload vmm
kldload nmdm
  • Enable networking
sysctl net.link.tap.up_on_open=1
sysctl net.inet.ip.forwarding=1
  • Create a network interface for the VM (em1 being my network card)
ifconfig tap1 create
ifconfig bridge0 create
ifconfig bridge0 addm tap1 addm em1 up
  • Create a file called device.map containing the paths to HDD image file and ISO file
echo "(hd0) ./debian-buildbox.img" > device.map
echo "(cd0) ./debian-7.7.0-amd64-netinst.iso.iso" >> device.map
  • Run the bootloader
    Here you'll see a menu, select install and you'll be back at the prompt after a few secs
    grub-bhyve -m device.map -r cd0 -M 768M debian-buildbox
  • Launch the virtual machine
bhyve -A -c 2 -m 768M -H \
-s 0:0,hostbridge \
-s 1:0,lpc \
-s 2:0,virtio-net,tap1 \
-s 3,ahci-hd,debian-buildbox.img \
-s 4,ahci-cd,debian-7.7.0-amd64-netinst.iso \
-l com1,/dev/nmdm0A debian-buildbox
  • Run the installer and when it's going to reboot you'll be back at the prompt shortly after
  • Close the VM
    bhyvectl --vm=debian-buildbox --destroy
  • Tell bhyve to boot from the HDD
    grub-bhyve -m device.map -r hd0,msdos1 -M 768M debian-buildbox
  • Launch the virtual machine
bhyve -A -c 2 -m 768M -H \
-s 0:0,hostbridge \
-s 1:0,lpc \
-s 2:0,virtio-net,tap1 \
-s 3,ahci-hd,debian-buildbox.img \
-l com1,/dev/nmdm0A debian-buildbox

Unless something went wrong you can access your Linux OS using serial device /dev/nmdm0B
cu -l /dev/nmdm0B -s 9600

Enjoy!