Table of content
Bhyve is the FreeBSD native virtualization system, it allows to run a full-operating system in an isolated process.
- Reference: vm-bhyve
- Requirement: dnsmasq
- Alternative: VirtualBox
- Resources: Windows
virtio-win
Build information
Ensure the following options:
Configuration
vm-bhyve
Fist we need to create a directory where vm-bhyve
will store it’s
configuration as well as the various VMs created:
1 2 |
|
Enabling vm-bhyve
and specifying it’s directory is done in the
system configuration file rc.conf
:
Allows vm-bhyve
to initialize it’s infrastructure:
1 |
|
Various templates are available in /usr/local/share/examples/vm-bhyve/
,
they should be copied (and adapted) in the .templates
directory inside the defined in vm_dir
(in case of a zfs filesystem,
the mountpoint is used).
1 |
|
Networking
The bridge interface on which bhyve
will attach is manually configured,
instead of letting vm-bhyve
manage it, so it’s easier to integrate
on other part of the system.
Element | Description |
---|---|
wan0 |
Interface to the outside world |
bridge1 |
Cloned bridge interface |
vmnet0 |
Renamed bridge1 interface |
bhyve-bridge |
Name given to the ‘switch’ is vm-bhyve |
192.168.100.0/24 |
Subnet dedicated to VMs |
192.168.100.1 |
IP address of the host on the VM subnet |
192.168.1.1 |
IP address of the host |
Create the vmnet0
interface and assign it an IP address,
the interface is also given a group name jail
to ease management
in complex firewall rules:
If we want to give the VM access to the outside world we need to have the host act as a gateway, and also as here the VMs have been defined on a private network NAT must be enabled:
It is possible to use, for a more complex configuration, a full
featured DHCP, TFTP and DNS server to provide the necessary network
services for booting and network access, but we have chosen here to
use dnsmasq
which conveniently provide all these services with a
simple configuration:
We now let vm-bhyve
know that we have created an interface
where it will be able to connect the VMs:
named
doesn’t support tapX
interface created
by vm-bhyve
and get stuck on it so we are forced to
specified listen address (directive: listen-on
and
listen-on-v6
) of all the desired intefaces so to skip
tapX
(no more keyword: any
).
For example:
VM
Templates
As we are using zfs, the various templates will be adapted to
use a sparse zvol
as disk, and it will be named root
Console
There is a virtio console, which provide a socket where to connect
(with socat
for example), but:
- there’s no way to use console port feature (➞ no
/dev/hvc?
in linux) - emergency write is advertised, but is a no-op
For a true console, we need to use vm console
which connect (defined
when configuring the VM) to an emulated serial line:
- from null-modem using
cu
andnmdm
device - from
stdio
/stdout
usingtmnux
Shared directory
- Only available in FreeBSD 13.
- This option is not directly handled by
vm
command, the configuration filevm.conf
need to be edited. - A free PCI slot (option
-s
) need to be selected, checkvm-bhyve.log
to see what was assigned.
Sound
- Only available in FreeBSD 13.
- This option is not directly handled by
vm
command, the configuration filevm.conf
need to be edited. - A free PCI slot (option
-s
) need to be selected, checkvm-bhyve.log
to see what was assigned.
Entropy driver
To supply high-quality randomness from the hypervisor to the guest:
The guest will also need a specific driver:
- FreeBSD:
virtio_random
- Windows: see
virtio-win
Guests
Windows
Executing command at startup:
1 2 3 |
|
Linux
Console
The virtio console is available through named devices
in /dev/virtio-ports/
directory (which hold
seem links to numbered device /dev/vport?p?
).
1 2 |
|
Shared directory
1 2 |
|
Commands
1 2 |
|
1 2 |
|
1 |
|
1 |
|
1 |
|
1 2 |
|
Troubleshouting
All ports busy (vm console)
# vm console debian
all ports busy
There is a cu
process already connected to the console, find it and kill it