The following features are available:
vmm-firmware package.
Processor compatibility can be checked with the following command:
$ dmesg | egrep '(VMX/EPT|SVM/RVI)'Before going further, enable and start the vmd(8) service.
# rcctl enable vmd # rcctl start vmd
install78.iso image file.
# vmctl create -s 50G disk.qcow2
vmctl: qcow2 imagefile created
# vmctl start -m 1G -L -i 1 -r install78.iso -d disk.qcow2 example
vmctl: started vm 1 successfully, tty /dev/ttyp8
# vmctl show
ID PID VCPUS MAXMEM CURMEM TTY OWNER NAME
1 72118 1 1.0G 88.1M ttyp8 root example
To view the console of the newly created VM, attach to its serial console:
# vmctl console example Connected to /dev/ttyp8 (speed 115200)The escape sequence
~. is needed to leave the serial console.
See the cu(1) man page for more info.
When using a vmctl serial console over SSH, the ~ (tilde)
character must be escaped to prevent
ssh(1) from dropping the connection.
To exit a serial console over SSH, use ~~. instead.
The VM can be stopped using vmctl(8).
# vmctl stop example stopping vm: requested to shutdown vm 1Virtual machines can be started with or without a vm.conf(5) file in place. The following
/etc/vm.conf example would replicate the above
configuration:
vm "example" {
memory 1G
enable
disk /home/user/disk.qcow2
local interface
}
Some configuration properties in
vm.conf(5)
can be reloaded by vmd(8) on the fly.
Other changes, like adjusting the amount of RAM or disk space, require the VM
to be restarted.
In the examples below, various IPv4 address ranges will be mentioned for different use cases:
10.0.0.0/8,
172.16.0.0/12, and 192.168.0.0/16 are not
globally routable.
100.64.0.0/10.
Using vmctl(8)'s -L
flag creates a local interface in the guest which will receive an address
from vmd via DHCP.
This essentially creates two interfaces: one for the host and the other
for the VM.
The following line in /etc/pf.conf will enable
Network Address Translation and redirect DNS requests
to the specified server:
match out on egress from 100.64.0.0/10 to any nat-to (egress)
pass in proto { udp tcp } from 100.64.0.0/10 to any port domain \
rdr-to $dns_server port domain
Reload the pf ruleset and the VM(s) can now connect to the internet.
Create a vport0 interface that will have a private IPv4 address
as defined above.
In this example, we'll use the 10.0.0.0/8 subnet.
# cat <<END > /etc/hostname.vport0 inet 10.0.0.1 255.255.255.0 up END # sh /etc/netstart vport0Create the
veb0 interface with the vport0
interface as a child interface:
# cat <<END > /etc/hostname.veb0 add vport0 up END # sh /etc/netstart veb0Ensure that NAT is set up properly if the guests on the virtual network need access beyond the physical machine. An adjusted NAT line in
/etc/pf.conf might look like this:
match out on egress from vport0:network to any nat-to (egress)The following lines in vm.conf(5) can be used to ensure that a virtual switch is defined:
switch "my_switch" {
interface veb0
}
vm "my_vm" {
...
interface { switch "my_switch" }
}
Inside the my_vm guest, it's now possible to assign
vio0
an address on the 10.0.0.0/24 network and set the default route to
10.0.0.1.
For convenience, you may wish to set up a
DHCP server on vport0.
The Ethernet network will be switched between the real network, the
host, and the VM using veb(4).
Because veb(4) disconnects interfaces added as ports from the IP
stack, any IP configuration on the real interface has to be moved
to a vport(4) interface
for the host to be able to participate in the network.
In this example em0 is the interface connected to the
real network.
Move the IP configuration from em0 to vport0:
# mv /etc/hostname.em0 /etc/hostname.vport0 # echo up >> /etc/hostname.vport0 # echo up >> /etc/hostname.em0 # sh /etc/netstart em0 vport0
Create the veb0 interface and add the em0
and vport0 interfaces:
# cat <<END > /etc/hostname.veb0 add em0 add vport0 up END # sh /etc/netstart veb0As done in the previous example, create or modify the vm.conf(5) file to ensure that a virtual switch is defined:
switch "my_switch" {
interface veb0
}
vm "my_vm" {
...
interface { switch "my_switch" }
}
The my_vm guest can now participate on the real network as if it
were physically connected.
Note: If the host interface (em0 in the above
example) uses automatic address configuration (eg, DHCP), it may
rely on the MAC address of the interface to get a particular IP
address assigned. In this situation the MAC address from em0
can be assigned to vport0 so it can use it on the real
network.
Virtual machines can be connected to a real network but isolated from the host by omitting the vport interface in the configuration above.