libvirt and bhyve

Testing libvirt and bhyve

  1. Make sure that in
    /etc/rc.conf
    that the following is set:
    local_unbound="NO"
    
  2. Make sure that in
    /etc/rc.conf
    that there are no entries which create tap or bridge devices, such as
    autobridge_interfaces
    ,
    autobridge_bridge[n]
    .
  3. Do:
    service local_unbound onestop
    
  4. Do: pkg install dns/dnsmasq to install the dnsmasq port.
  5. Install the
    devel/libvirt
    port, version 1.2.6 or higher. Before building the port, do make config and make sure that BHYVE and QEMU options are enabled.
  6. Edit
    /usr/local/etc/libvirt/libvirtd.conf
    and add a line:
    log_level = 2
  7. Create a file
    /tmp/bhyve.xml
    with the following:
    
    <domain type='bhyve'>
      <name>bhyve</name>
      <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
        <memory>2147483</memory>
        <currentMemory>2147483</currentMemory>
        <vcpu>1</vcpu>
        <os>
           <type>hvm</type>
        </os>
        <features>
          <apic/>
          <acpi/>
        </features>
        <clock offset='utc'/>
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>restart</on_reboot>
        <on_crash>destroy</on_crash>
        <devices>
          <disk type='file'>
            <driver name='file' type='raw'/>
            <source file='/tmp/some_disk.img'/>
            <target dev='hda' bus='sata'/>
          </disk>
          <interface type='bridge'>
            <model type='virtio'/>
            <source bridge="virbr0"/>
          </interface>
          <serial type="nmdm>
            <source master="/dev/nmdm0A" slave="/dev/nmdm0B"/>
          </serial>
        </devices>
    </domain>
    
    

    Make sure that source_file points to a valid disk image that can boot in bhyve.

  8. Start libvirtd from the command-line:
    /usr/local/sbin/libvirtd
  9. After starting libvirtd, verify that the virbr0 device was created with ifconfig:
    # ifconfig -a
    
    virbr0: flags=8843 metric 0 mtu 1500
            ether 02:29:45:c7:8f:00
            inet 192.168.122.1 netmask 0xffffff00 broadcast 192.168.122.255 
            nd6 options=1
            id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 4
            maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
            root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
    
  10. Run these commands from the command-line using using virsh:
    virsh -c 'bhyve:///system' "define /tmp/bhyve.xml"
    virsh -c 'bhyve:///system' "start --console bhyve"
    
    If all the configuration steps were successful, then a bhyve VM should successfully start.

Further references